From 18988ae2e6c04e43d80f0cdade95fabebb12ad49 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 31 May 2017 10:17:36 +0200 Subject: [PATCH] Asyncore updates - performance optimisation, reduce number of loops when waiting for protocol headers / commands --- src/network/bmproto.py | 6 +++--- src/network/tcp.py | 2 +- src/network/udp.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index ffd79056..f59be314 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -78,13 +78,13 @@ class BMProto(AdvancedDispatcher, ObjectTracker): if self.magic != 0xE9BEB4D9: # skip 1 byte in order to sync self.bm_proto_reset() - self.set_state("bm_header", 1) + self.set_state("bm_header", length=1, expectBytes=protocol.Header.size) logger.debug("Bad magic") self.close() return False if self.payloadLength > BMProto.maxMessageSize: self.invalid = True - self.set_state("bm_command", protocol.Header.size, expectBytes=self.payloadLength) + self.set_state("bm_command", length=protocol.Header.size, expectBytes=self.payloadLength) return True def state_bm_command(self): @@ -130,7 +130,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): self.close() return False if retval: - self.set_state("bm_header", self.payloadLength) + self.set_state("bm_header", length=self.payloadLength, expectBytes=protocol.Header.size) self.bm_proto_reset() # else assume the command requires a different state to follow return True diff --git a/src/network/tcp.py b/src/network/tcp.py index 3ce4cc52..f6d0c7ac 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -69,7 +69,7 @@ class TCPConnection(BMProto, TLSDispatcher): ObjectTracker.__init__(self) UISignalQueue.put(('updateNetworkStatusTab', 'no data')) self.bm_proto_reset() - self.set_state("bm_header") + self.set_state("bm_header", expectBytes=protocol.Header.size) def antiIntersectionDelay(self, initial = False): # estimated time for a small object to propagate across the whole network diff --git a/src/network/udp.py b/src/network/udp.py index 48a805d8..8c710997 100644 --- a/src/network/udp.py +++ b/src/network/udp.py @@ -68,7 +68,7 @@ class UDPSocket(BMProto): ObjectTracker.__init__(self) self.connecting = False self.connected = True - self.set_state("bm_header") + self.set_state("bm_header", expectBytes=protocol.Header.size) def state_bm_command(self): BMProto.state_bm_command(self)