title: recvfrom() Timeout c programming
body: <p>I have problem with setting timeout to <code>recvfrom()</code>. I run my code under Cygwin64 environment.</p>
  
  <p>.his is a sample from my code: </p>
  
  <pre><code>if(( clientSock=socket(AF_INET, SOCK_DGRAM,0))==-1){ // creat client socket 
      perror("Socket Initialisation Error\n");
  }//if
  
  struct timeval tv;
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  if (setsockopt(clientSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&amp;tv, sizeof tv)) {
      perror("setsockopt");    
  }
  
  memset(&amp;client,0, sizeof(client)); // clear the memory of 
  client addrinfo
  
  client.sin_port=htons(clientPort);// asign client port
  client.sin_family=AF_INET; // ipv4
  client.sin_addr.s_addr=INADDR_ANY;
  bzero(&amp;client.sin_zero,8);
  
  if((bind(clientSock,(struct sockaddr*)&amp;client, sizeof(struct sockaddr_in)))==-1){ // bind socket with addrinfo
      perror("\n Bind: ");
  } 
  
  server.sin_family=AF_INET; // server ipv4 type
  server.sin_port=htons(serverPort); // assign server port
  server.sin_addr.s_addr=inet_addr(serverIp); // asign server ip
  bzero(&amp;server.sin_zero,8);
  
  while(1){
      // send to the server is ok then  wait for receive: 
  
      if((recvfrom(clientSock,&amp;rcvPkt,sizeof(struct packet),0,(struct sockaddr *)&amp;server,&amp;sockLength))&lt;0){ // wait for receiving replay from server 
          puts("\nerror in receiving CONF packet");
      }
      sleep(1);
  }
  </code></pre>
  
  <p>The program keeps waiting on <code>recvfrom()</code>: the timeout is not working. </p>