void HttpListenerList::recvListeners() { int startfd = 300; char achSockAddr[128]; socklen_t len; while( 1 ) { len = 128; if ( getpeername( startfd, (struct sockaddr *)achSockAddr, &len ) != -1 ) break; // Must not be connected len = 128; if ( getsockname( startfd, (struct sockaddr *)achSockAddr, &len ) == -1 ) break; // Must be a server socket if ( ((struct sockaddr *)achSockAddr)->sa_family != PF_UNIX ) { int fd = dup( startfd ); HttpListener * pListener = new HttpListener(); pListener->assign( fd, (struct sockaddr *)achSockAddr ); push_back( pListener ); sort( s_compare ); } close( startfd ); ++startfd; } }
HttpListener* HttpListenerList::get( const char * pName, const char * pAddr ) { iterator iter; char achBuf[256]; if ( pName ) { iter = bfind( pName, f_compare ); if ( iter != end() ) return *iter; } if ( pAddr ) { iter = bfind( pAddr, f_compare ); if ( iter != end() ) { HttpListener * p = *iter; p->setName( pName ); sort( s_compare ); return p; } if ( strncmp( pAddr, "0.0.0.0:", 8 ) == 0 ) { snprintf( achBuf, 256, "*:%s", pAddr + 8 ); pAddr = achBuf; } for( iterator iter = begin(); iter != end(); ++iter ) { if ( strcasecmp( pAddr, (*iter)->getAddrStr() ) == 0 ) { HttpListener * p = *iter; p->setName( pName ); sort( s_compare ); return p; } } } return NULL; }
HttpListener* HttpListenerList::get( const char * pName, const char * pAddr ) { iterator iter; if ( pName ) { iter = bfind( pName, f_compare ); if ( iter != end() ) return *iter; } if ( pAddr ) { iter = bfind( pAddr, f_compare ); if ( iter != end() ) { HttpListener * p = *iter; erase( iter ); p->setName( pName ); push_back( p ); sort( s_compare ); return p; } } return NULL; }