0

This continues to occur for an infinite amount of time until a valid event occurs on the corresponding socket. Then again, it goes back to normal behavior. Unable to trace the trigger for this issue.

What other events should I look for in the sockets other than the events I have registered for and why? I have currently registered for POLLIN & POLLHUP.

  while ( 1 )
    {
        //Calling POLL Function;
        //Sockets in List ( One Server Socket TCP )
        //Sockets of Open TCP Connections
        int rv = poll ( ufds , nfds , - 1 );

        if (rv == -1)
        {
            //Error Occured in POLL
        }
        else if ( rv == 0 )
        {
            //Time out fromData Recieved
        }
        else if ( rv > 0 )
        {
               //Look for events POLLIN or POLLHUP and act correspondingly
        }
  }

(MOST POSSIBLE)Trigger for the issue -

                    //Called by Main Thread when another thread is 
                    //polling on the respective socket_fd 
                    recv(socket_fd, buffer, 1024, MSG_PEEK | MSG_DONTWAIT);

I am doing a MSG_PEEK to see whether the peer connected to this socket is alive.

b1tchacked
  • 468
  • 4
  • 12

1 Answers1

1

The POLLHUP, POLLERR and POLLNVAL events will cause poll to return even if these events have not been specified in events (in fact, setting these in events will be ignored). Check revents to see if any of these events happened for your file descriptors.

Sander De Dycker
  • 16,053
  • 1
  • 35
  • 40
  • I will reply at the earliest after I try this tweak after I reproduce the issue. POLLNVAL Invalid request: fd not open (only returned in revents; ignored in events). So do I close the socket and remove it from ufds array when this event occurs? @sander-de-dycker – b1tchacked May 18 '15 at 10:11
  • 1
    @slim : have a look at http://stackoverflow.com/questions/24791625/linux-socket-handling-revents-pollerr-pollhup-pollnval . For `POLLNVAL` specifically - that usually indicates a coding error : a socket that is not opened should not be in `ufds`. – Sander De Dycker May 18 '15 at 10:19
  • POLLNVAL isn't the event for which poll comes out of the loop. I have made an edit which describes the trigger for the event – b1tchacked May 19 '15 at 13:49
  • @slim : so, which was the event that woke up `poll` ? – Sander De Dycker May 19 '15 at 14:37
  • As of now i don't know, I will check for all the returned events `POLLIN,POLLPRI,POLLOUT,POLLRDHUP,POLLERR,POLLHUP,POLLNVAL ` in every socket. If any other even i have to check for let me know. – b1tchacked May 20 '15 at 05:52