In my program If the server is not reachable the connect function take too much time. So i try to give time out to connect using select(). Now the problem is that when i try to
You receive EAGAIN
because there's no data to read from socket buffer and your socket was set as nonblocking
. Since you're not connected with the peer, i'm not surprised with it.
Look at this from man recvfrom
:
If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is nonblocking (see fcntl(2)), in which case the value -1 is returned and the external variable errno set to EAGAIN. The receive calls normally return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested.
Another case could be the following:
readfrom
or just read
) only when your're sure you received something.