Add task_done to asyncore-related queues
This commit is contained in:
parent
f8b4b427fc
commit
fa9ad537a5
|
@ -80,6 +80,7 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
|||
while len(self.write_buf) < bufSize:
|
||||
try:
|
||||
self.write_buf += self.writeQueue.get(False)
|
||||
self.writeQueue.task_done()
|
||||
except Queue.Empty:
|
||||
break
|
||||
if len(self.write_buf) > 0:
|
||||
|
@ -103,11 +104,13 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
|||
while True:
|
||||
try:
|
||||
self.writeQueue.get(False)
|
||||
self.writeQueue.task_done()
|
||||
except Queue.Empty:
|
||||
break
|
||||
while True:
|
||||
try:
|
||||
self.receiveQueue.get(False)
|
||||
self.receiveQueue.task_done()
|
||||
except Queue.Empty:
|
||||
break
|
||||
asyncore.dispatcher.close(self)
|
||||
|
|
|
@ -11,9 +11,12 @@ def chooseConnection(stream):
|
|||
return state.trustedPeer
|
||||
else:
|
||||
try:
|
||||
return portCheckerQueue.get(False)
|
||||
retval = portCheckerQueue.get(False)
|
||||
portCheckerQueue.task_done()
|
||||
except Queue.Empty:
|
||||
try:
|
||||
return peerDiscoveryQueue.get(False)
|
||||
retval = peerDiscoveryQueue.get(False)
|
||||
peerDiscoveryQueue.task_done()
|
||||
except Queue.Empty:
|
||||
return random.choice(knownnodes.knownNodes[stream].keys())
|
||||
return retval
|
||||
|
|
|
@ -35,7 +35,9 @@ class ReceiveQueueThread(threading.Thread, StoppableThread):
|
|||
processed += 1
|
||||
try:
|
||||
getattr(self, "command_" + str(command))(i, args)
|
||||
i.receiveQueue.task_done()
|
||||
except AttributeError:
|
||||
i.receiveQueue.task_done()
|
||||
# missing command
|
||||
raise
|
||||
if processed == 0:
|
||||
|
|
|
@ -137,7 +137,6 @@ class UDPSocket(BMProto):
|
|||
return len(self.read_buf) < AdvancedDispatcher._buf_len
|
||||
|
||||
def handle_read(self):
|
||||
print "read!"
|
||||
try:
|
||||
(addr, recdata) = self.socket.recvfrom(AdvancedDispatcher._buf_len)
|
||||
except socket.error as e:
|
||||
|
@ -150,6 +149,7 @@ class UDPSocket(BMProto):
|
|||
self.local = True
|
||||
else:
|
||||
self.local = False
|
||||
print "read %ib" % (len(recdata))
|
||||
# overwrite the old buffer to avoid mixing data and so that self.local works correctly
|
||||
self.read_buf = data
|
||||
self.process()
|
||||
|
@ -162,9 +162,10 @@ class UDPSocket(BMProto):
|
|||
return
|
||||
try:
|
||||
retval = self.socket.sendto(data, ('<broadcast>', UDPSocket.port))
|
||||
# print "broadcasted %ib" % (retval)
|
||||
print "broadcasted %ib" % (retval)
|
||||
except socket.error as e:
|
||||
print "socket error on sendato: %s" % (e)
|
||||
self.writeQueue.task_done()
|
||||
|
||||
def close(self, reason=None):
|
||||
self.set_state("close")
|
||||
|
|
Loading…
Reference in New Issue
Block a user