0

How to respond to these errors when they happen in connect() (non-blocking)? I want to know whether I should kill this socket and create a new one, or I can wait some time and try again with existing socket and all will work (if remote host became online)?

Nokeya
  • 3
  • 5

1 Answers1

1

You can try connecting again in these cases, since creating and binding the socket again would be unnecessary extra work.

Magisch
  • 7,312
  • 9
  • 36
  • 52
  • 1
    I doubt that. To try the connection the socket will be implicitly bind and the destination address will be set and only after that the SYN will be sent to the peer, because the outgoing packet needs source and destionation IP + port so that any response can be matched back to the appropriate socket. – Steffen Ullrich Oct 15 '15 at 07:34
  • In the documentation I found it says the connect() command will time out automatically after at the longest 75 seconds of no answer. – Magisch Oct 15 '15 at 13:14
  • 1
    Timeout depends on various settings but this has nothing to do with the question if the socket can be reused or not. – Steffen Ullrich Oct 15 '15 at 13:30
  • A small test indicates that you are right at least regarding socket reuse after timeout of a connection. It looks like that the implicit binding is only temporarily associated with the socket and removed after the connection failed. – Steffen Ullrich Oct 15 '15 at 13:42
  • That makes most sense. The reason there is a time out to begin with is so the socket does not remain bound to the failed connection. – Magisch Oct 15 '15 at 13:44