From fa7d2da9732db9f85fb022826e7f8679b6a82052 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Wed, 11 Mar 2020 14:48:48 +0100 Subject: [PATCH] Update --- app/corpora/CQiWrapper/CQi.py | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) 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):