<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 7, 2010, at 6:07 PM, Christopher Armstrong wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Bitstream Vera Sans Mono'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="font-family: monospace; ">But will that "lower-level than endpoints" API need to be TCP-specific?<br><br>We don't have a listenSerialPort, so why do we need listenTCP (by the&nbsp;way, we should totally have a SerialPortEndpoint)?</span></span></blockquote><div><br></div><div><div>We totally *should* have a SerialPortEndpoint, but I definitely prefer the way that calling 'reactor.listenTCP(...)' implicitly selects a back-end to the platform-detection junk at the bottom of twisted.internet.serialport. &nbsp;The wonky platform-detection has some practical implications, as shown here: &lt;<a href="http://twistedmatrix.com/trac/ticket/3802">http://twistedmatrix.com/trac/ticket/3802</a>&gt;. &nbsp;I would actually prefer a nice 'AttributeError: SelectReactor has no attribute "listenSerialPort"' to the mess that it currently produces.</div></div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Bitstream Vera Sans Mono'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="font-family: monospace; ">I understand your&nbsp;point that some reactors provide addReader while others provide&nbsp;addOverlappedIOObject (or whatever the heck it's called), but an&nbsp;Endpoints implementation can DTRT based on the interfaces that the&nbsp;supplied reactor provides, so I don't see why TCPServerEndpoint can't&nbsp;just instantiate a port and call addReader/addWriter or the&nbsp;IOCPreactor equivalent.</span></span></blockquote><div><br></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Bitstream Vera Sans Mono'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="font-family: monospace; ">And maybe we need a better way to deal with&nbsp;the differences between those reactors, but I don't see why that&nbsp;requires us to have public transport-specific methods on the reactor.<br></span></span></blockquote><div><br></div><div>Well, we need to deal with the differences *somehow*. &nbsp;Currently, we&nbsp;just have a listenTCP on the reactor. &nbsp;This makes the implementation of endpoints dead simple, and it doesn't really vary at all per-platform. &nbsp;It seems to work okay; the main drawback, as far as I can tell, is that it deepens the inheritance hierarchy of the reactors a bit, because we use inheritance to grab the many similar method implementations that many similar reactors share.</div><div><div><br></div><div>In the current model, we can add new types of socket-ish things - the ones that I can think of which may one day actually matter are Java SelectableChannel objects and maybe System.Net.Socket.Select if we ever support Jython and IronPython, respectively - by adding new reactors, and these things need new reactors anyway in order to invoke the multiplexors that understand these objects. &nbsp;So that sorta makes sense to me. &nbsp;You call listenTCP on something somewhat opaque, and the opaque thing knows how to give you back an appropriate IListeningPort, ITransport, etc. &nbsp;With the reactor plugin API, we can even add these new types of things outside of Twisted, pretty straightforwardly.</div><div><br></div><div>This dispatch point *could* be handled internally in each endpoint implementation, and that does seem hypothetically more elegant to me, since it's the endpoint that should care about the TCP-ness and the reactor that should care about the file-descriptor-ness, abstractly. &nbsp;But at some point, the rubber must meet the road, and IReactorFDSet needs to be mapped to twisted.internet.tcp.Port, and twisted.internet.tcp.Connector, or similar, and IReactorIOCPMumbleMumble (btw, this interface should exist) to twisted.internet.iocpreactor.tcp.Port, etc.</div><div><br></div><div>If I want to do that mapping under the current system, I just implement my own reactor plugin and implement listenTCP to do the right thing. &nbsp;Under a new system where the endpoint was responsible for handling that mapping, can I add a reactor plugin that has a meaningfully different idea of what a multiplexable I/O resource is? &nbsp;I have some vague ideas... something sort of shaped like an adapter registry, maybe? &nbsp;A different plugin API, for things to talk specifically to the TCP endpoint code? &nbsp;I can brainstorm up some vague ideas but none of them really sit right, and certainly none of them are as straightforward as just implementing a bunch of methods specified by interfaces.</div><div><br></div><div>Now, I'm pretty sure <i>you</i> know how I feel about this, Chris, but just so nobody else takes away the wrong conclusion from this: I'm not saying that the current internal reactor factoring is perfect, or even particularly good. &nbsp;That code needs a lot of cleanup, a lot of documentation, and in many places a general sorting-out of what really constitutes the intended public API. &nbsp;It's far too hard to implement an external reactor, because you can't sensibly inherit any of that code which all reactors practically need to inherit. &nbsp;It's mostly undocumented and it has even changed incompatibly a few times. &nbsp; For example, &lt;<a href="http://twistedmatrix.com/trac/changeset/24132">http://twistedmatrix.com/trac/changeset/24132</a>&gt; incompatibly changed the signature of 'tcp.Port.__init__'. &nbsp;However, it seems like a more straightforward job to me to figure out a reasonable signature for tcp.Port.__init__, and to do some general de-duplication of code between the IOCP modules and the UNIX-file-descriptor modules, than to come up with a whole new way to correlate endpoint implementations to their respective concrete transport implementations.</div><div><br></div><div>This quality problem in the core multiplexing code is actually one of the reasons I want to vocally defend the current architecture. &nbsp;Until we have a defined path forward, with a clear design that's better in a way that has some positive, practical ramifications, I don't want to put anyone off doing this necessary maintenance work in twisted.internet. &nbsp;There's not a huge amount of maintenance going on in that area already, but if we adopt the attitude of "Oh, let's forget about that, it's going to get deprecated anyway", I have a feeling the amount of work will drop to zero.</div><div><br></div></div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Bitstream Vera Sans Mono'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="font-family: monospace; ">However, of course I'm not advocating we jump the gun on deprecating&nbsp;listenTCP and so forth. We shouldn't deprecate them now, and when we&nbsp;do, we should make it an *extremely* long period of PendingDeprecation&nbsp;followed by Deprecation.<br></span></span></blockquote></div><br><div>Well, Python 2.7 isn't going to display DeprecationWarning by default anyway, so I think PendingDeprecation may be pointless. &nbsp;But I definitely echo the sentiment, regardless.</div><div><br></div></body></html>