Asyncore updates

- performance optimisation, reduce number of loops when waiting
for protocol headers / commands
This commit is contained in:
Peter Šurda 2017-05-31 10:17:36 +02:00
parent 2555f692eb
commit 18988ae2e6
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 5 additions and 5 deletions

View File

@ -78,13 +78,13 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
if self.magic != 0xE9BEB4D9: if self.magic != 0xE9BEB4D9:
# skip 1 byte in order to sync # skip 1 byte in order to sync
self.bm_proto_reset() 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") logger.debug("Bad magic")
self.close() self.close()
return False return False
if self.payloadLength > BMProto.maxMessageSize: if self.payloadLength > BMProto.maxMessageSize:
self.invalid = True 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 return True
def state_bm_command(self): def state_bm_command(self):
@ -130,7 +130,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.close() self.close()
return False return False
if retval: 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() self.bm_proto_reset()
# else assume the command requires a different state to follow # else assume the command requires a different state to follow
return True return True

View File

@ -69,7 +69,7 @@ class TCPConnection(BMProto, TLSDispatcher):
ObjectTracker.__init__(self) ObjectTracker.__init__(self)
UISignalQueue.put(('updateNetworkStatusTab', 'no data')) UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
self.bm_proto_reset() self.bm_proto_reset()
self.set_state("bm_header") self.set_state("bm_header", expectBytes=protocol.Header.size)
def antiIntersectionDelay(self, initial = False): def antiIntersectionDelay(self, initial = False):
# estimated time for a small object to propagate across the whole network # estimated time for a small object to propagate across the whole network

View File

@ -68,7 +68,7 @@ class UDPSocket(BMProto):
ObjectTracker.__init__(self) ObjectTracker.__init__(self)
self.connecting = False self.connecting = False
self.connected = True self.connected = True
self.set_state("bm_header") self.set_state("bm_header", expectBytes=protocol.Header.size)
def state_bm_command(self): def state_bm_command(self):
BMProto.state_bm_command(self) BMProto.state_bm_command(self)