Setting time out for connect() function tcp socket programming in C breaks recv()

前端 未结 4 849
孤街浪徒
孤街浪徒 2021-02-06 05:20

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

4条回答
  •  野性不改
    2021-02-06 05:50

    Setting time out for connect() function tcp socket programming in C is not working

    Correction. Setting the connect timeout is working. What 'isn't working' is the subsequent recvfrom(), and that's because you left the socket in non-blocking mode and you don't know what to do with the resulting EAGAIN. So, either handle that, by using select() to tell you when the socket is ready to read, or else put the socket back into blocking mode after finishing the connect.

提交回复
热议问题