I appreciate your response.  Unfortunatly, it's not entirely accurate.

When a client's socket closes read() or recv() returns 0.
If an error occured, -1.


Bit of code:
   nRead = recv( d->descriptor, buf + index, sizeof(buf) - 10 - index, 0);
   if ( nRead > 0 )
     {
      index += nRead;
      bytes_received+=nRead;
      mrtg->bytes_received+=nRead;
      if ( buf[index-1] == '\n' || buf[index-1] == '\r' )
        break;
     }
     else if ( nRead == 0 )
     {
      sprintf(site, "Disconnection: EOF[%i]: '%s'", d->descriptor, d->Host);
      logfile(site);
      wiznet (site, NULL, NULL, WIZ_SITES, 0, 208);
      return FALSE;
     }
      else if ( errno == EWOULDBLOCK )
         break;
     else
       {
        perror( "Read_from_descriptor" );
        return FALSE;
      }


When recv() return a positive number, it processes the data.
If it returns 0, the client has disconnected (as you've stated) This is
normal.

When it return < 0 an error occurs.  This is what is happening to me. The
error is "connection reset by peer". Errno is 104.

Any other suggestions?


Reply via email to