How can I try to read data from socket with timeout?
I know, select, pselect, poll, has a timeout field, but using of them disables "tcp fast-path" in tcp reno stack.
The only idea I have is to use recv(fd, …, MSG_DONTWAIT) in a loop
clinuxsocketstcp
How can I try to read data from socket with timeout?
I know, select, pselect, poll, has a timeout field, but using of them disables "tcp fast-path" in tcp reno stack.
The only idea I have is to use recv(fd, …, MSG_DONTWAIT) in a loop
Best Answer
You can use the setsockopt function to set a timeout on receive operations:
Reportedly on Windows this should be done before calling
bind
. I have verified by experiment that it can be done either before or afterbind
on Linux and OS X.