Connecting Tech Pros Worldwide Forums | Help | Site Map

Detect if connection was closed on remote side

Newbie
 
Join Date: Jan 2009
Posts: 4
#1: Jan 9 '09
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:

Expand|Select|Wrap|Line Numbers
  1. while (1)
  2.   {
  3.     tv.tv_sec = 1;
  4.     tv.tv_usec = 0; 
  5.  
  6.     FD_ZERO (&readfds);
  7.     FD_SET (priv->socket, &readfds); 
  8.     rc = select (priv->socket+1, &readfds, NULL, NULL, &tv);
  9.  
  10.     if (rc<0)
  11.       {
  12.          /* error of using select() */
  13.       }
  14.     else if (rc==0)
  15.       {
  16.          /* timeout */
  17.       }
  18.     else
  19.       {
  20.          /* HERE I can read data */
  21.       }
  22.  
  23.      /* and HERE I want to check if connection still active*/
  24.   }
  25.  
How to do it in my code?

Reply

Tags
close, connection, select, socket