What are possible reason for socket error EINPROGRESS in solaris?

27,421

Solution 1

You have a non-blocking socket and you are calling connect() in it. Since connect() needs the 3-way handshake to happen (so a network roundtrip), it either blocks waiting for the SYN-ACK in blocking sockets, or gives you some indication that it hasn't succeded yet in non-blocking sockets. Normally, non-blocking sockets return EAGAIN/EWOULDBLOCK to tell you that they couldn't progress and you should try again: this is not exactly your case, connect() returns EAGAIN/EWOULDBLOCK when there are no free ephemeral ports to tell you that you should try again later; so there is another error for non-blocking connect: EINPROGRESS, which tells you that the operation is in progress and you should check its status later.

To check the status later, the socket will become ready for writability, so you can use select()/poll()/... to test for that, after which you'll have to getsockopt(...SO_ERROR...) to get the success/failure status of your connect() operation.

Solution 2

You are obviously using non-blocking sockets and you need to use select() or poll() to determine when you can write (connect is a form of write) to the socket. It's the same when you wish to actually write data to the connected socket; you don't just write and connect when you feel like it, you ask the socket to tell you when you can do things and in the meantime you do something else (the idea of asynchronous socket operations).

Check your manpage for the absolute truth about available error codes:

$ man connect

[EINPROGRESS] The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) for completion by selecting the socket for writing.

Share:
27,421
Syedsma
Author by

Syedsma

Updated on August 28, 2020

Comments

  • Syedsma
    Syedsma over 3 years

    What are possible reason for socket error EINPROGRESS in Solaris? How we can check the root cause?

    tcp api is : connect

  • Syedsma
    Syedsma over 12 years
    Right now I am chking only for EAGAIN/EWOULDBLOCK error in non block, So In non-blocking , If have to do select for EINPROGRESS error along with EAGAIN/EWOULDBLOCK error also
  • ninjalj
    ninjalj over 12 years
    @Syedsma: only connect() returns EINPROGRESS.
  • Bionix1441
    Bionix1441 almost 8 years
    Just wondering, if the select returns true (select for write for example), connect succeeded but the last errno to be set was EINPROGRESS. Should this error be ignored in that case ?
  • rogerdpack
    rogerdpack over 5 years
    I don't think you'll get EINPROGRESS for that though would you?
  • Kyle Redfearn
    Kyle Redfearn over 5 years
    I am not calling connect directly I am using a networking client: FFMPEG. It might be a bug in the implementation of the client. I can only report what I saw and how it was fixed. Hopefully is helps another person like it did me.