def recv(self): # handlers recv pickled objects len_size = 4 read_size = 1024 buff = '' buff += self.socket.recv(len_size) #TODO real size shouldnt be more than a % extra of msg_size if not buff: return None msg_size = proto.encoded_size(buff) #print 'msg_size is', msg_size remaining_bytes = msg_size buff = buff[len_size:] while remaining_bytes > 0: if (msg_size - read_size) >= 0: _buff = self.socket.recv(read_size) buff += _buff remaining_bytes -= len(_buff) else: _buff = self.socket.recv(remaining_bytes) buff += _buff remaining_bytes -= len(_buff) if remaining_bytes == 0: break return pickle.loads(buff)
def recv(self): len_size = 4 read_size = 1024 buff = '' buff += self.socket.recv(len_size) #TODO real size shouldnt be more than a % extra of msg_size if not buff: return None msg_size = proto.encoded_size(buff) #print "received msg_size", msg_size remaining_bytes = msg_size buff = buff[len_size:] while remaining_bytes > 0: if (msg_size - read_size) >= 0: _buff = self.socket.recv(read_size) buff += _buff remaining_bytes -= len(_buff) else: _buff = self.socket.recv(remaining_bytes) buff += _buff remaining_bytes -= len(_buff) if remaining_bytes == 0: break return buff