[Twisted-Python] Oddities in calling loseConnection from tcp.Port.approveConnection
Andrew Bennetts
andrew-twisted at puzzling.org
Tue Apr 2 02:52:31 MST 2002
Ok, so I know approveConnection is probably going to be removed anyway,
but...
If I have a tcp.Port subclass which calls self.loseConnection() in
approveConnection (e.g. so that it will only accept one connection), then I
get two errors. First is:
Traceback (most recent call last):
File "w:\andrew\cvs\Twisted\twisted\internet\main.py", line 206, in doSelect
if not handfn or handfn() == -1:
File "w:\andrew\cvs\Twisted\twisted\internet\abstract.py", line 244, in fileno
raise NotImplementedError(str(self.__class__)+' has no fileno method')
exceptions.NotImplementedError: twisted.protocols.ftp.FTPDataPort has no fileno method
I think the fix for this might be:
diff -u -r1.65 main.py
--- twisted/internet/main.py 1 Apr 2002 06:35:16 -0000 1.65
+++ twisted/internet/main.py 2 Apr 2002 09:41:07 -0000
@@ -203,7 +203,10 @@
try:
why = getattr(selectable, method)()
handfn = getattr(selectable, 'fileno', None)
- if not handfn or handfn() == -1:
+ try:
+ if not handfn or handfn() == -1:
+ why = CONNECTION_LOST
+ except NotImplementedError:
why = CONNECTION_LOST
except:
log.deferr()
The second error is:
Traceback (most recent call last):
File "w:\andrew\cvs\Twisted\twisted\internet\main.py", line 215, in doSelect
selectable.connectionLost()
File "w:\andrew\cvs\Twisted\twisted\internet\tcp.py", line 476, in connectionLost
self.socket.close()
exceptions.AttributeError: FTPDataPort instance has no attribute 'socket'
This appears to be because connectionLost is called twice; once when I
originally called loseConnection and again from the select loop. I'm not
sure what the correct fix is... I don't understand why the select loop is
calling it because removeReader is calling in loseConnection, but perhaps
connectionLost should check self.connected and gracefully deal with being
called twice?
I'll probably be doing my loseConnection from buildProtocol instead of
approveConnection soon, but I suspect that I'll hit these problems there as
well.
-Andrew.
More information about the Twisted-Python
mailing list