Creating socket.connect while in epoll loop

Discussion in 'Python' started by Miki Tebeka, Sep 12, 2012.

  1. Miki Tebeka

    Miki Tebeka Guest

    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

    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
     
    Miki Tebeka, Sep 12, 2012
    #1
    1. Advertising

  2. Miki Tebeka

    Guest

    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
     
    , Sep 12, 2012
    #2
    1. Advertising

  3. Miki Tebeka

    Miki Tebeka Guest

    > 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.
    OK.

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

    That was the idea, learning.

    > 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

    Thank you very much!
     
    Miki Tebeka, Sep 12, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,291
    Tim Slattery
    Mar 30, 2005
  2. Uday Bidkar
    Replies:
    4
    Views:
    526
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Dec 12, 2006
  3. James Mills

    epoll socket server

    James Mills, Oct 10, 2008, in forum: Python
    Replies:
    0
    Views:
    741
    James Mills
    Oct 10, 2008
  4. _wolf
    Replies:
    0
    Views:
    918
    _wolf
    Mar 24, 2010
  5. Isaac Won
    Replies:
    9
    Views:
    458
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page