Commit 9efd46d7 authored by Jim Fulton's avatar Jim Fulton

Added a should_close method that allows connection closes to be

queued.
parent aed6c3c9
...@@ -68,6 +68,8 @@ SEND_SIZE = 60000 ...@@ -68,6 +68,8 @@ SEND_SIZE = 60000
MAC_BIT = 0x80000000L MAC_BIT = 0x80000000L
_close_marker = object()
class SizedMessageAsyncConnection(asyncore.dispatcher): class SizedMessageAsyncConnection(asyncore.dispatcher):
__super_init = asyncore.dispatcher.__init__ __super_init = asyncore.dispatcher.__init__
__super_close = asyncore.dispatcher.close __super_close = asyncore.dispatcher.close
...@@ -235,6 +237,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -235,6 +237,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
else: else:
return True return True
def should_close(self):
self.__output.append(_close_marker)
def handle_write(self): def handle_write(self):
self.__output_lock.acquire() self.__output_lock.acquire()
try: try:
...@@ -250,7 +255,13 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -250,7 +255,13 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
l = 0 l = 0
for i in range(len(output)): for i in range(len(output)):
l += len(output[i]) try:
l += len(output[i])
except TypeError:
# We had an output marker, close the connection
assert output[i] is _close_marker
return self.close()
if l > SEND_SIZE: if l > SEND_SIZE:
break break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment