Opened 17 years ago

Closed 14 years ago

Last modified 4 years ago

#191 enhancement closed invalid (invalid)

twisted.internet refactor to better support non-select reactors

Reported by: etrepum Owned by:
Priority: low Milestone:
Component: core Keywords:
Cc: Glyph, itamarst, etrepum Branch:


Change History (8)

comment:1 Changed 17 years ago by etrepum

When writing a CoreFoundation reactor for twisted, I ran into a major 
snafu.  CFSockets are cached until they are invalidated.  The problem is, 
that the only entity that can invalidate CFSockets is the reactor, and tcp/
udp just doesn't tell the reactor when they're closing!  I had to do a nasty 
runtime method swap to make it work (without hacking, etc).  
Hopefully, this would entail a reactor.addFileDescriptor(x) / 
reactor.removeFileDescriptor(x) .. or whatever nomenclature.

Another issue is that CoreFoundation supports a notify-on-connect (or 
failure otherwise).  Of course, the current code just kinda figures it out 
from doing some magic on the doRead/doWrite methods.  This is 
horrible and ugly.  The connection phase should be separated from the 
read/write loop.  A possibility would be to add a connectors dict, that 
behaves similarly to the readers/writers dicts.  When doing the select (in 
the SelectReactor) it would append these keys to both the readers and 
writers.  In CoreFoundation, I can just tell it to give me the address or 
error when a socket connects.  Right now I can't take advantage of that.

comment:2 Changed 17 years ago by Glyph

Why are you using the classes in  You're right in your other bug 
(the namespace is horrible) but those classes are for reactors which 
behave more or less like select.  If CFRunLoop doesn't behave like select, 
then write you own transport classes, don't try to make the default ones 
infinitely flexible.

comment:3 Changed 17 years ago by etrepum

I'm using the classes in tcp and udp because the code for 
CoreFoundation TCP/UDP (when not using the CFNativeSocket method) 
is identical - except for the fact that I REALLY need to know when they 
get disconnected so I can invalidate the CFSocket.  Which I did, by 
changing their connectionLost method (at runtime, from the reactor).  
Granted it's not really any nastier than what's already in tcp/udp, but it's 
not the kind of hack I'd want to put into Twisted.  I also don't want to cut 
and paste 90% of and into something else and pollute that 
namespace even more.

comment:4 Changed 17 years ago by itamarst

I agree with bob - the changes would be pretty minimal and
the vast majority of the code would be the same in any case.
Additional stuff like "register fd" would actually make some
of the code cleaner. 

OTOH, it may cause some issues, like, existing
FileDescriptor's don't have this concept. We could probably
figure out something that gets them to DTRT (startReading
could do the register the first time), or just update our
code, but at least some people have written their own
FileDescriptors already.

comment:5 Changed 17 years ago by Glyph

Subclass then, perhaps?

comment:6 Changed 14 years ago by Glyph

Resolution: invalid
Status: newclosed

Ran across this ticket more or less by accident; it's hopelessly vague.

Also, cfreactor is basically dead now, so the original motivating use-case is not relevant.

comment:7 Changed 9 years ago by <automation>

Owner: itamarst deleted

comment:8 Changed 4 years ago by GitHub <noreply@…>

In e309d630:

Merge pull request #191 from twisted/handshake-6024-2

Author: glyph, amluto

Reviewer: lukasa, habnabit, exarkun, glyph

Fixes: #6024

The new interface IHandshakeListener that can be implemented by any Protocol provides a callback that is called when the TLS handshake has been completed, allowing Protocols to make decisions about the TLS configuration before application data is sent.

Note: See TracTickets for help on using tickets.