Creating socket.connect while in epoll loop

calderone.jeanpaul at gmail.com calderone.jeanpaul at gmail.com
Wed Sep 12 14:53:56 EDT 2012


On Wednesday, September 12, 2012 12:01:58 PM UTC-4, Miki Tebeka wrote:
> Greetings,
> 
> I'm trying to write a reverse TCP proxy using epoll (just for learning).
> 
> I've started with the code at http://scotdoyle.com/python-epoll-howto.html and got to https://gist.github.com/3707665.
>
> 
> However, I can't create a new connection. When reaching line 34 (backend.connect), I get the following error (on line 34):
> 
>     socket.error: [Errno 115] Operation now in progress
> 

You cannot synchronously set up a new TCP connection using a non-blocking socket.  Instead, you begin the connection attempt and it fails with EINPROGRESS and then you use epoll to find out when the attempt completes.

I suggest reading the implementation of a Twisted reactor to see an example of how this is done.

Here are a couple links to get you started:

http://twistedmatrix.com/trac/browser/trunk/twisted/internet/tcp.py
http://twistedmatrix.com/trac/browser/trunk/twisted/internet/epollreactor.py

Jean-Paul

> 
> 
> I tried moving the socket creation to a different thread, but same problem.
> 
> Any ideas how to so fix this? (keep in mind I'm a total newbie in this area).
> 
> 
> 
> Thanks,
> 
> --
> 
> Miki



More information about the Python-list mailing list