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
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
LINUX
WINDOWS
NOTE: You have put this setting before
bind()
function call for proper run// works also after bind operation for WINDOWS
Install a handler for
SIGALRM
, then usealarm()
orualarm()
before a regular blockingrecv()
. If the alarm goes off, therecv()
will return an error witherrno
set toEINTR
.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.Here's a Simple code to add time out to your recv function using poll in C: