Detect if connection was closed on remote side

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlannY
    New Member
    • Jan 2009
    • 4

    Detect if connection was closed on remote side

    Hi there. I'm writing a tool, which must detect is connection was terminated on remote side.

    Every action on network, I'm fetching with select(). And I want in some place check if connection still active.

    There are code:

    Code:
    while (1)
      {
        tv.tv_sec = 1;
        tv.tv_usec = 0; 
    
        FD_ZERO (&readfds);
        FD_SET (priv->socket, &readfds); 
        rc = select (priv->socket+1, &readfds, NULL, NULL, &tv);
    
        if (rc<0)
          {
             /* error of using select() */
          }
        else if (rc==0)
          {
             /* timeout */
          }
        else
          {
             /* HERE I can read data */
          }
    
         /* and HERE I want to check if connection still active*/
      }
    How to do it in my code?
Working...