[Twisted-Python] [patch] 3/4 basic protocols don't notice disconnecting

Andrea Arcangeli andrea at cpushare.com
Wed May 17 10:37:28 EDT 2006


This is an old patch, it wasn't applied because not all transport
backends support disconnecting but since I assume most people uses the
basic int32/16 protocols on top of tcp this isn't a pratical concern for
me, and I prefer no data callback to fire after calling loseConnection.
This isn't an high prio patch but I post it anyway (I understand if it
will not be applied to SVN again for the valid reason that disconnecting
may not exists, I admit I never investigated since I only use tcp and
udp, my argument that disconnecting could be added in a compatible
transparent way to all transports still holds).

diff -r 493b5c24e0f3 twisted/protocols/basic.py
--- a/twisted/protocols/basic.py	Tue May 16 04:57:00 2006 +0000
+++ b/twisted/protocols/basic.py	Wed May 17 15:59:28 2006 +0200
@@ -309,7 +309,7 @@ class Int32StringReceiver(protocol.Proto
         """Convert int32 prefixed strings into calls to stringReceived.
         """
         self.recvd = self.recvd + recd
-        while len(self.recvd) > 3 and not self.paused:
+        while len(self.recvd) > 3 and not self.paused and not self.transport.disconnecting:
             length ,= struct.unpack("!i",self.recvd[:4])
             if length > self.MAX_LENGTH:
                 self.transport.loseConnection()
@@ -346,7 +346,7 @@ class Int16StringReceiver(protocol.Proto
         """Convert int16 prefixed strings into calls to stringReceived.
         """
         self.recvd = self.recvd + recd
-        while len(self.recvd) > 1 and not self.paused:
+        while len(self.recvd) > 1 and not self.paused and not self.transport.disconnecting:
             length = (ord(self.recvd[0]) * 256) + ord(self.recvd[1])
             if len(self.recvd) < length+2:
                 break





More information about the Twisted-Python mailing list