@ -117,12 +117,11 @@ int main(void) {
# else
debug_config_init ( ) ;
for ( int i = 1 ; i < DEBUG_CATEGORY_COUNT ; i + + ) debug_set_category_level ( i , DEBUG_LEVEL_ERROR ) ;
for ( int i = 1 ; i < DEBUG_CATEGORY_COUNT ; i + + ) debug_set_category_level ( i , DEBUG_LEVEL_NON E ) ;
srand ( ( unsigned ) getpid ( ) ) ;
// Резервируем fd 0: dup на высокий fd, close(0), /dev/null на 0.
// Гарантирует что accept()/socket() никогда не вернут 0.
{ int fd = open ( " /dev/null " , O_RDONLY ) ; if ( fd = = 0 ) { /* уже ок */ } else if ( fd > 0 ) { dup2 ( fd , 0 ) ; close ( fd ) ; } else { close ( 0 ) ; open ( " /dev/null " , O_RDONLY ) ; } }
int fd0 = open ( " /dev/null " , O_RDONLY ) ;
if ( fd0 = = 0 ) { } else if ( fd0 > 0 ) { dup2 ( fd0 , 0 ) ; close ( fd0 ) ; } else { close ( 0 ) ; open ( " /dev/null " , O_RDONLY ) ; }
g_port = 25000 + ( rand ( ) % 10000 ) ;
g_ua = uasync_create ( ) ;
@ -136,7 +135,7 @@ int main(void) {
la . sin_family = AF_INET ; la . sin_port = htons ( ( uint16_t ) g_port ) ;
la . sin_addr . s_addr = inet_addr ( " 127.0.0.1 " ) ;
if ( bind ( lsock , ( struct sockaddr * ) & la , sizeof ( la ) ) < 0 ) { printf ( " [FAIL] bind: %s \n " , strerror ( errno ) ) ; goto cleanup ; }
if ( listen ( lsock , 32 ) < 0 ) { printf ( " [FAIL] listen: %s \n " , strerror ( errno ) ) ; goto cleanup ; }
if ( listen ( lsock , 1024 ) < 0 ) { printf ( " [FAIL] listen: %s \n " , strerror ( errno ) ) ; goto cleanup ; }
uasync_add_socket ( g_ua , lsock , on_accept_cb , NULL , NULL , NULL ) ;
for ( int i = 0 ; i < CHILDREN ; i + + ) {
@ -150,7 +149,7 @@ int main(void) {
g_mon_id = uasync_set_timeout ( g_ua , 100 , NULL , monitor , " mon " ) ;
void * to_id = uasync_set_timeout ( g_ua , TIMEOUT_MS * 10 , NULL , test_timeout , " to " ) ;
while ( ! g_done ) uasync_poll ( g_ua , 0 ) ;
while ( ! g_done ) uasync_poll ( g_ua , 5 0) ;
if ( to_id ) uasync_cancel_timeout ( g_ua , to_id ) ;