I am trying to focus on how it should be done in terms of asyncio terms, but I don't have time to actually write any code ATM.
It is better not to think of this (at first) in terms of StreamReader/StreamWriter but in terms of the protocol and transport and the event loop's create_connection() method. Wrapping StreamReader/StreamWriter around the low-level objects will be obvious once the low-level puzzle has been solved. Please read the asyncio code for ssl transports and try to adapt it to your needs; it already knows how to call wrap_socket() and do the handshake asynchronously, so the right approach must be somewhere there. And my hunch is that a very small refactoring might be enough. On Sun, Apr 6, 2014 at 6:47 AM, Imran Geriskovan <[email protected] > wrote: > On 4/6/14, Guido van Rossum <[email protected]> wrote: > > Hm, I wonder if there isn't an even simpler approach that even works with > > the current asyncio public API. You can pass an already-open socket to > > create_connection() -- maybe you can use this (also passing > ssl=<context>) > > and it would just work? > > Its possible. But that needs manual manupulation of the socket outside > the asyncio domain. It is ugly. (sync code, selects, timeouts etc..) > This undermines the reason for using asyncio. > > I thought about another possibility: > > StreamWriter.transport.get_extra_info('socket') gives access to the socket. > That socket may be manually wrapped. Can you confirm if this operation > is safe? But again here we have to handle the Handshake syncronously > which is ugly too. > > I think there is no quick solution other than proper handling of the whole > wrapping process in asyncio terms. > > Regards, > Imran > -- --Guido van Rossum (python.org/~guido)
