[Twisted-Python] CFReactor

Bob Ippolito bob at redivi.com
Mon Oct 25 18:02:29 EDT 2004

On Oct 25, 2004, at 17:24, James Y Knight wrote:

> Itamar just added half-closing support to Twisted, and I foolishly 
> volunteered to look at adding support to cfreactor for him. However, 
> that was before I looked at it. Now that I have, I have little idea 
> what it's actually doing, so I'm afraid that I'm unable to actually 
> implement this change.
> The "SelectableSocketWrapper" looks like a horrible kludge, and I'm 
> not sure why it's necessary. Why does it override the wrapped object's 
> "connectionLost"? Why do you have to wrap&override 
> Selectable.start/stopReading/Writing, instead of doing that stuff in 
> reactor.add/removeReader/Writer? What is simulate?? Essentially, I 
> just don't understand why it is so different from the other reactors.

The SSW kludge is necessary because it inherits a lot of functionality 
from the existing default select-based reactor and its sockets.  It is 
a workaround for the lack of extensibility in the implementation of 
those sockets and that reactor.  It could be less hacky if it were 
inverted, but then you'd have to subclass every possible port and add 
the reactor notifications, and essentially copy about 80% of 
twisted.internet.default instead of subclassing it.  If you want to 
refactor it this way, be my guest.. but I'm not bored enough to do it 

The reason for the loseConnection hack is that the existing 
implementation of loseConnection doesn't do removeReader/Writer!  
loseConnection effectively kills the socket without notifying the 
reactor at all.  If the existing implementation told the reactor when 
it was done with a socket, SSW wouldn't be so much of a kludge.

> Either hints or else a working half-close implementation for cfreactor 
> would be appreciated.

You'll probably have to implement the same style of hack that is used 
for loseConnection.  Replace the half-lose-connection method (if it 
exists) with a method that notifies the reactor of the intention, and 
then call the original implementation.


More information about the Twisted-Python mailing list