LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   setsockopt: SO_RCVTIMEO (https://www.linuxquestions.org/questions/programming-9/setsockopt-so_rcvtimeo-468572/)

Ephracis 07-28-2006 10:28 AM

setsockopt: SO_RCVTIMEO
 
Hi,

I am trying to set receive timeout on my raw socket but it keeps telling me "invalid argument". Is there something I'm missing here?
Code:

int val = 0;
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &val, sizeof(val))) {
      perror("setsockopt: rcvtimeo");
      exit(1);
}


Ephracis 07-28-2006 10:35 AM

Nevermind. It seems it takes a timeval as argument. :)

niteen 03-18-2013 02:43 AM

Code:

        int val = 0; 
        struct timeval tv;
        tv.tv_sec = 30;  /* 30 Secs Timeout */
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv,sizeof(struct timeval)) {
      perror("setsockopt: rcvtimeo");
      exit(1);
}



All times are GMT -5. The time now is 02:39 PM.