1

I wanna wait for a constant amount of time(like 3 seconds) for recvfrom() to receive some data, and I wanna exit my program if it didn't receive anything (in this 3 seconds) how do that ?

1 Answers1

2

Call setsockopt() with the SO_RCVTIMEO option to set a read timeout on the socket. If the timeout fires, recvfrom() will return -1 with errno == EAGAIN/EWOULDBLOCK.

user207421
  • 305,947
  • 44
  • 307
  • 483