Please, show below example
int val = 120000;
setsockopt(connSock,SOL_SOCKET,SO_RCVTIMEO,(char*)&val,sizeof(int));
I set 120 seconds at receive timeout but it takes 240 seconds.
I think timeout is double the set value.
how is it possible?
Please, show below example
int val = 120000;
setsockopt(connSock,SOL_SOCKET,SO_RCVTIMEO,(char*)&val,sizeof(int));
I set 120 seconds at receive timeout but it takes 240 seconds.
I think timeout is double the set value.
how is it possible?
SO_RCVTIMEO
does not accept an int
as the timeout. You're looking for something like this:
struct timeval tv = {
.tv_sec = 120
};
setsockopt(connSock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
SO_RCVTIMEO and SO_SNDTIMEO do not work on all socket operations, you should use non-blocking mode and select
.
The behaviour may change on different operating system configurations.
On my system the connect
timeouts after two times the value I set in SO_RCVTIMEO. A quick hack like setting SO_RCVTIMEO to x/2
before a connect and x
after it works, but the proper solution is using select.
Discussion on this problem (read comments to answer):
How to use select to achive the desired result: