From 2422064b22edbce85cce4e27641b455a92205187 Mon Sep 17 00:00:00 2001 From: TheKysek Date: Sun, 2 Oct 2016 16:52:14 +0200 Subject: [PATCH] Change how we request objects --- src/connection.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/connection.py b/src/connection.py index d174cee..ec40ed8 100644 --- a/src/connection.py +++ b/src/connection.py @@ -74,18 +74,19 @@ class Connection(threading.Thread): data = self.s.recv(self.next_message_size - len(self.buffer_receive)) self.buffer_receive += data except ssl.SSLWantReadError: - pass + if self.status == 'fully_established': + self._request_objects() except socket.error as e: err = e.args[0] if err == errno.EAGAIN or err == errno.EWOULDBLOCK: - pass + if self.status == 'fully_established': + self._request_objects() else: raise except ConnectionResetError: logging.debug('Disconnecting from {}:{}. Reason: ConnectionResetError'.format(self.host, self.port)) data = None self._process_buffer_receive() - self._request_objects() self._process_queue() self._send_data() if time.time() - self.last_message_received > shared.timeout: @@ -260,10 +261,12 @@ class Connection(threading.Thread): def _request_objects(self): if self.vectors_to_get: - if len(self.vectors_to_get) > 50000: - pack = random.sample(self.vectors_to_get, 50000) - self.send_queue.put(message.GetData(pack)) - self.vectors_to_get.difference_update(pack) - else: - self.send_queue.put(message.GetData(self.vectors_to_get)) - self.vectors_to_get.clear() + self.vectors_to_get.difference_update(shared.objects.keys()) + if self.vectors_to_get: + if len(self.vectors_to_get) > 16: + pack = random.sample(self.vectors_to_get, 16) + self.send_queue.put(message.GetData(pack)) + self.vectors_to_get.difference_update(pack) + else: + self.send_queue.put(message.GetData(self.vectors_to_get)) + self.vectors_to_get.clear()