I have a working code running on a RedHat installed Linux with kernel 2.6.18-194.el5 #1 SMP x86_64.
When I moved the code to a newly installed machine with CentOS 6.3 the same code failed with
Error assigning socket option: Numerical argument out of domain
The kernel version of the latter machine is 2.6.32-279.el6.x86_64 #1 SMP
Below is the code of what’s both working and failing in the machines, respectively.
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 1500000;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)) != 0)
{
LM_ERR("Error assigning socket option: %s", strerror( errno ));
return FALSE;
}
Try using
I’ve seen some implementations not accepting
tv_usecabove 10^6.Edit: The issue is interesting enough to dig a little bit. Looking for
SO_RCVTIMEOin the kernel source code I’ve found the following piece of code innet/core/sock.c:The beginning of the
sock_set_timeout()function indeed contains some range checking:Now we know enough to do some
git blame-ing 🙂 The change was introduced with the following changeset:I believe that the commit comment explains everything. As far as I can see this change was included in 2.6.22-rc3.