When the connection is completed, the FD socket will be writable. You should also check for the latest socket error through getsockopt ().
How do I know how long the connect () operation will take to wait?
You cannot, of course. You must try. The question does not make sense.
Can I change this in my program?
You can change the timeout of the selection if that is what you mean. If this is not the case, I do not understand the question. Note that you can reduce the default connection timeout by default in about a minute, but you cannot increase it.
If my select operation time out, then what?
You close the socket and fulfill all the requirements of your application for a connection timeout.
Is it okay to close the socket descriptor, create another one, and then reconnect?
Only if you have reason to think that next time you will get a different result.
Or is there a way to cancel a connection in an existing socket and retry the operation using the same socket descriptor?
Not. After the connection failed, the socket will be dead and should be closed.
source share