Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Jul 2002 07:57:06 -0700
From:      Luigi Rizzo <rizzo@icir.org>
To:        David Miller <dmiller@sparks.net>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: setsockopt() weirdness
Message-ID:  <20020714075706.A74633@iguana.icir.org>
In-Reply-To: <Pine.BSF.4.21.0207141037280.13872-100000@search.sparks.net>; from dmiller@sparks.net on Sun, Jul 14, 2002 at 10:49:56AM -0400
References:  <Pine.BSF.4.21.0207141037280.13872-100000@search.sparks.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jul 14, 2002 at 10:49:56AM -0400, David Miller wrote:
> I'm probably doing something basic wrong, but I'm getting a very
> inconsistent response when using setsockopt to set the SO_RCVTIMEO to
> seven seconds or more.

i would suspect some overflow of 16-bit fields used to store
the timeout value (scaled by HZ) .
What value of "HZ" are you using ? And what is the exact threshold
where it fails (i'd bet it is between 6.5 and 6.6 sec.) ?

	cheers
	luigi

> 
> The program included works on a 4.3R system, a 4.4R and a 4.6stable system
> SUPd June 24.  The systems are a 486, 800 MHz P-III, and 1.1 GHz t-bird
> respectively.
> 
> The program fails to work on a 1 GHz t-bird with 4.6S SUPd last night, and
> an XP1700+ SUP'd several days ago.
> 
> "Works" is defined as:
> 
> bash-2.05$ ./x
> Successfully set timeout to 6
> Successfully set timeout to 7
> 
> "Not works" is defined as:
> 
> alex:c$ ./x
> Successfully set timeout to 6
> Error 33 trying to set socket timeout to 7
> 
> 
> Clue greatly appreciated.
> 
> --- David
> 
> The program:
> 
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <sys/errno.h>
> #include <netinet/in.h>
> #include <stdio.h>
> #include <arpa/inet.h>
> #include <netdb.h>
> #include <sys/time.h>
> 
> 
> extern int errno;
> 
> main() {
> 
> int sock, timeout ;
> struct itimerval s_timeout;
> 
>     if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
>         printf("Couldn't get a socket, err %d\n",sock);
>         exit(-1);
>     }
> 
>     s_timeout.it_interval.tv_usec = 0;
>     s_timeout.it_value.tv_usec = 0;
> 
>     s_timeout.it_value.tv_sec  = 0;
>     s_timeout.it_interval.tv_sec  = 6;
> 
>     if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
>             &s_timeout, sizeof(s_timeout))) {
>         printf("Error %d trying to set socket timeout\n",errno);
>     }
>     else {
>         printf("Successfully set timeout to %d\n",
>                 s_timeout.it_interval.tv_sec);
>     }
> 
>     s_timeout.it_interval.tv_sec  = 7;
> 
>     if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
>             &s_timeout, sizeof(s_timeout))) {
>         printf("Error %d trying to set socket timeout to %d\n",
>             errno, s_timeout.it_interval.tv_sec);
>     }
>     else {
>         printf("Successfully set timeout to %d\n",
>                 s_timeout.it_interval.tv_sec);
>     }
> }
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020714075706.A74633>