Logo Search packages:      
Sourcecode: znc version File versions  Download package

bool Csock::Listen ( u_short  iPort,
int  iMaxConns = SOMAXCONN,
const CS_STRING &  sBindHost = "",
u_int  iTimeout = 0 
) [virtual]

Listens for connections

Parameters:
iPort the port to listen on
iMaxConns the maximum amount of connections to allow

Definition at line 624 of file Csocket.cpp.

References LISTENER, and SOCKET().

{
      m_iConnType = LISTENER;
      m_itimeout = iTimeout;

      m_sBindHost = sBindHost;
      if ( !sBindHost.empty() )
      {
            if( GetAddrInfo( sBindHost, this, m_address ) != 0 )
                  return( false );
      }

      m_iReadSock = m_iWriteSock = SOCKET( true );

      if ( m_iReadSock == -1 )
            return( false );

      m_address.SinFamily();
      m_address.SinPort( iPort );

      if( !GetIPv6() )
      {
            if ( bind( m_iReadSock, (struct sockaddr *) m_address.GetSockAddr(), m_address.GetSockAddrLen() ) == -1 )
                  return( false );
      }
#ifdef HAVE_IPV6
      else
      {
            if ( bind( m_iReadSock, (struct sockaddr *) m_address.GetSockAddr6(), m_address.GetSockAddrLen6() ) == -1 )
                  return( false );
      }
#endif /* HAVE_IPV6 */

      if ( listen( m_iReadSock, iMaxConns ) == -1 )
            return( false );

      if ( !m_bBLOCK )
      {
            // set it none blocking
#ifdef _WIN32
            u_long iOpts = 1;
            ioctlsocket( m_iReadSock, FIONBIO, &iOpts );
#else
            int fdflags = fcntl ( m_iReadSock, F_GETFL, 0);
            fcntl( m_iReadSock, F_SETFL, fdflags|O_NONBLOCK );
#endif /* _WIN32 */
      }

      return( true );
}


Generated by  Doxygen 1.6.0   Back to index