select( ) is returning positive value only once

147 views Asked by At

The select function is returning +ve value when some packets reach the UDP port as expected. But this happens only once. From second time when a packet is received on the UDP port, the function is not responding for that. But in the first time after receiving the UDP packet if I do a sendto() on the same socket, the select function is responding. What would be the reason for this behaviour?

The code:

while (true)
{
   IP_FD_ZERO (&readFD);
   IP_FD_SET  (ipSock, &readFD);

   if (select( &readFD, NULL, NULL, 2000 ) > 0)
   {
      if (IP_FD_ISSET( ipSock, &readFD ))       //activity on UDP socket
      {
         addrlen   = sizeof(SocketAddrIn_t);
         noOfbytes = recvfrom( ipSock, 
                              (char*)ipRxBuffer, 
                              sizeof(ipRxBuffer), 
                              0, 
                              (SocketAddr_t *)&from, 
                              (int*)&addrlen );
      }
   }
}
1

There are 1 answers

2
user207421 On
select( &readFD, NULL, NULL, 2000 )

Bzzt. The fourth parameter to select() is a struct timeval *, not an integer. See the man page.