Change how we request objects

This commit is contained in:
TheKysek 2016-10-02 16:52:14 +02:00
parent 87fadf65b3
commit 2422064b22

View File

@ -74,18 +74,19 @@ class Connection(threading.Thread):
data = self.s.recv(self.next_message_size - len(self.buffer_receive)) data = self.s.recv(self.next_message_size - len(self.buffer_receive))
self.buffer_receive += data self.buffer_receive += data
except ssl.SSLWantReadError: except ssl.SSLWantReadError:
pass if self.status == 'fully_established':
self._request_objects()
except socket.error as e: except socket.error as e:
err = e.args[0] err = e.args[0]
if err == errno.EAGAIN or err == errno.EWOULDBLOCK: if err == errno.EAGAIN or err == errno.EWOULDBLOCK:
pass if self.status == 'fully_established':
self._request_objects()
else: else:
raise raise
except ConnectionResetError: except ConnectionResetError:
logging.debug('Disconnecting from {}:{}. Reason: ConnectionResetError'.format(self.host, self.port)) logging.debug('Disconnecting from {}:{}. Reason: ConnectionResetError'.format(self.host, self.port))
data = None data = None
self._process_buffer_receive() self._process_buffer_receive()
self._request_objects()
self._process_queue() self._process_queue()
self._send_data() self._send_data()
if time.time() - self.last_message_received > shared.timeout: if time.time() - self.last_message_received > shared.timeout:
@ -260,10 +261,12 @@ class Connection(threading.Thread):
def _request_objects(self): def _request_objects(self):
if self.vectors_to_get: if self.vectors_to_get:
if len(self.vectors_to_get) > 50000: self.vectors_to_get.difference_update(shared.objects.keys())
pack = random.sample(self.vectors_to_get, 50000) if self.vectors_to_get:
self.send_queue.put(message.GetData(pack)) if len(self.vectors_to_get) > 16:
self.vectors_to_get.difference_update(pack) pack = random.sample(self.vectors_to_get, 16)
else: self.send_queue.put(message.GetData(pack))
self.send_queue.put(message.GetData(self.vectors_to_get)) self.vectors_to_get.difference_update(pack)
self.vectors_to_get.clear() else:
self.send_queue.put(message.GetData(self.vectors_to_get))
self.vectors_to_get.clear()