Logo Search packages:      
Sourcecode: znc version File versions

int Csock::Read ( char *  data,
int  len 
) [virtual]

Read from the socket Just pass in a pointer, big enough to hold len bytes

Parameters:
data the buffer to read into
len the size of the buffer
Returns:
Returns READ_EOF for EOF Returns READ_ERR for ERROR Returns READ_EAGAIN for Try Again ( EAGAIN ) Returns READ_CONNREFUSED for connection refused Returns READ_TIMEDOUT for a connection that timed out at the TCP level Otherwise returns the bytes read into data

Definition at line 1152 of file Csocket.cpp.

References READ_CONNREFUSED, READ_EAGAIN, READ_ERR, READ_TIMEDOUT, ReadSelect(), SEL_OK, SEL_TIMEOUT, and SslIsEstablished().

{
      int bytes = 0;
      memset( (char *)data, '\0', len );

      if ( ( IsReadPaused() ) && ( SslIsEstablished() ) )
            return( READ_EAGAIN ); // allow the handshake to complete first

      if ( m_bBLOCK )
      {
            switch( ReadSelect() )
            {
                  case SEL_OK:
                        break;
                  case SEL_TIMEOUT:
                        return( READ_TIMEDOUT );
                  default:
                        return( READ_ERR );
            }
      }

#ifdef HAVE_LIBSSL
      if ( m_bssl )
            bytes = SSL_read( m_ssl, data, len );
      else
#endif /* HAVE_LIBSSL */
#ifdef _WIN32
            bytes = recv( m_iReadSock, data, len, 0 );
#else
            bytes = read( m_iReadSock, data, len );
#endif /* _WIN32 */
      if ( bytes == -1 )
      {
            if ( GetSockError() == ECONNREFUSED )
                  return( READ_CONNREFUSED );

            if ( GetSockError() == ETIMEDOUT )
                  return( READ_TIMEDOUT );

            if ( ( GetSockError() == EINTR ) || ( GetSockError() == EAGAIN ) )
                  return( READ_EAGAIN );

#ifdef _WIN32
            if ( GetSockError() == WSAEWOULDBLOCK )
                  return( READ_EAGAIN );
#endif /* _WIN32 */

#ifdef HAVE_LIBSSL
            if ( m_bssl )
            {
                  int iErr = SSL_get_error( m_ssl, bytes );
                  if ( ( iErr != SSL_ERROR_WANT_READ ) && ( iErr != SSL_ERROR_WANT_WRITE ) )
                        return( READ_ERR );
                  else
                        return( READ_EAGAIN );
            }
#else
            return( READ_ERR );
#endif /* HAVE_LIBSSL */
      }

      if( bytes > 0 ) // becareful not to add negative bytes :P
            m_iBytesRead += (unsigned long long)bytes;

      return( bytes );
}


Generated by  Doxygen 1.6.0   Back to index