-
-
Notifications
You must be signed in to change notification settings - Fork 178
Add new TCPTransport base class #286
Comments
"There is actually no way to access the underlying socket, which causes some problems. " Hum, how do you plan to set TCP_NODELAY flag if you don't have access to the socket? There are a lot of socket flags and options. I'm not sure that it's a good idea to add a method for each flag. It will be difficult to document the available of each method depending on the platform and the implementation of the event loop. We already have to take care in the documentation of subtle differences between SelectorEventLoop on UNIX and on Windows, and the special case of ProactorEventLoop. |
Thinking on the issue I would suggest another solution: don't export E.g. for utilizing nodelay and keepalive in aiohttp I should check for available options anyway: old asyncio should be supported as well as other asyncio-compatible loops like quamash etc. Explicit check for |
"Thinking on the issue I would suggest another solution: don't export 'socket' extra info by uvloop (it's impossible) (...)" Hum, does it mean that we should update the doc to mention that some info may lack depending on the event loop? https://docs.python.org/dev/library/asyncio-protocol.html#asyncio.BaseTransport.get_extra_info |
I believe yes. |
Libuv has two API methods for setting NODELAY and KEEPALIVE.
These two are important and popular enough to have explicit methods in Twisted and Tornado.
I agree. But in this specific case - those are very popular and important options. And I simply can't make my loop usable without them.
Absolutely. |
I like Andrew's suggestion. Expose the libuv stream interface (wrapped in a helper object) through get_extra_info('libuv-stream'). That avoids the need for modifying the class structure of asyncio (or any other part of its implementation or interface). So user code could look like e.g.
Depending on how popular uvloop becomes we could eventually add a standard interface to asyncio so that you wouldn't have to do it one way for regular sockets and another way for uvloop, but that's not so important in the short term. |
To my surprise (I think the function is documented in a wrong place) I found a way to extract the Still, I like the idea of explicit |
Hum. At what level in a network stack do "keepalive" and "nodelay" really On Wed, Nov 25, 2015 at 9:08 AM, Yury Selivanov [email protected]
--Guido van Rossum (python.org/~guido) |
In uvloop (more details here) I implement Transports on top of libuv streams. Here's documentation on TCP and general streams.
Streams are an opaque abstraction over sockets API. All buffering is implemented in the libuv core. There is actually no way to access the underlying socket, which causes some problems. Right now, if you want to set
TCP_NODELAY
orSO_KEEPALIVE
, the only way is to callTransport.get_extra_info('socket')
and set them manually. That's what aiohttp is doing, for instance.I propose to add a new
Transport
base class -TCPTransport
. It will have two specific to TCP methods:set_nodelay(bool enabled)
andset_keepalive(bool enabled)
.Without these methods, it's virtually impossible for me to create a transport that provides this functionality on top of libuv. This is very similar to how this is done in Twisted and in Tornado.
The text was updated successfully, but these errors were encountered: