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.


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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to