Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket SO_RCVTIMEO Timeout is double the set value in C++/VC++

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?

like image 852
Vijay Kumbhani Avatar asked Oct 20 '25 03:10

Vijay Kumbhani


1 Answers

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));
like image 148
Tom Avatar answered Oct 21 '25 17:10

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!