diff --git a/app/corpora/CQiWrapper/CQi.py b/app/corpora/CQiWrapper/CQi.py index 62eebdb7..306e6732 100644 --- a/app/corpora/CQiWrapper/CQi.py +++ b/app/corpora/CQiWrapper/CQi.py @@ -6,8 +6,10 @@ # Modified by: Patrick Jentsch # # ########################################################################### # +from app import logger import socket import struct +import time """ 1. padding """ @@ -908,20 +910,40 @@ class Client: return data def __recv_DATA_BYTE(self): - byte_data = self.connection.recv(1, socket.MSG_WAITALL) + while True: + if (len(self.connection.recv(1, socket.MSG_PEEK)) == 1): + byte_data = self.connection.recv(1) + break + logger.warning('Waiting for data transfer to complete...') + time.sleep(0.1) return struct.unpack('!B', byte_data)[0] def __recv_DATA_BOOL(self): - byte_data = self.connection.recv(1, socket.MSG_WAITALL) + while True: + if (len(self.connection.recv(1, socket.MSG_PEEK)) == 1): + byte_data = self.connection.recv(1) + break + logger.warning('Waiting for data transfer to complete...') + time.sleep(0.1) return struct.unpack('!?', byte_data)[0] def __recv_DATA_INT(self): - byte_data = self.connection.recv(4, socket.MSG_WAITALL) + while True: + if (len(self.connection.recv(4, socket.MSG_PEEK)) == 4): + byte_data = self.connection.recv(4) + break + logger.warning('Waiting for data transfer to complete...') + time.sleep(0.1) return struct.unpack('!i', byte_data)[0] def __recv_DATA_STRING(self): n = self.__recv_WORD() - byte_data = self.connection.recv(n, socket.MSG_WAITALL) + while True: + if (len(self.connection.recv(n, socket.MSG_PEEK)) == n): + byte_data = self.connection.recv(n) + break + logger.warning('Waiting for data transfer to complete...') + time.sleep(0.1) return struct.unpack('!{}s'.format(n), byte_data)[0].decode() def __recv_DATA_BYTE_LIST(self): @@ -977,7 +999,12 @@ class Client: return data def __recv_WORD(self): - byte_data = self.connection.recv(2, socket.MSG_WAITALL) + while True: + if (len(self.connection.recv(2, socket.MSG_PEEK)) == 2): + byte_data = self.connection.recv(2) + break + logger.warning('Waiting for data transfer to complete...') + time.sleep(0.1) return struct.unpack('!H', byte_data)[0] def __send_BYTE(self, byte_data):