void io_sig_handler(int num) { fd_set rfds; int conn_id, ret, selret, count; struct timeval timeout; if(num){} do { timeout.tv_sec = 0; /* Don't wait, just poll */ timeout.tv_usec = 0; list_to_fds( &rfds ); #ifdef __linux__ selret = poll(Pollfds, Pollfd_size, 0); #else selret = select(FD_SETSIZE, &rfds, NULL, NULL, &timeout); #endif if(selret > 0) { conn_id = 0; while( (ret = fds_get_entry( &rfds, &conn_id )) > 0 ) { if( Net_conns[conn_id].reading ) { count = 0; do { if(Net_conns[conn_id].channel) { do_read( conn_id ); count = get_bytes_to_read(conn_id); } else { count = 0; } }while(count > 0 ); } else { do_accept( conn_id ); } MY_FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds ); } } }while(selret > 0); }
void tcpip_task( void *dummy) { /* wait for an IO signal, find out what is happening and * call the right routine to handle the situation. */ fd_set rfds, efds, *pfds; int conn_id, ret, count; #ifndef WIN32 int data; #endif if(dummy){} while(1) { while(!DIM_IO_valid) dim_usleep(1000); list_to_fds( &rfds ); FD_ZERO(&efds); #ifdef WIN32 pfds = &efds; #else pfds = &rfds; #endif FD_SET( DIM_IO_path[0], pfds ); ret = select(FD_SETSIZE, &rfds, NULL, &efds, NULL); if(ret > 0) { if(FD_ISSET(DIM_IO_path[0], pfds) ) { #ifndef WIN32 read(DIM_IO_path[0], &data, 4); DIM_IO_Done = 0; #endif FD_CLR( (unsigned)DIM_IO_path[0], pfds ); } /* { DISABLE_AST */ while( (ret = fds_get_entry( &rfds, &conn_id )) > 0 ) { if( Net_conns[conn_id].reading ) { count = 0; do { DISABLE_AST if(Net_conns[conn_id].channel) { do_read( conn_id ); count = get_bytes_to_read(conn_id); } else { count = 0; } ENABLE_AST }while(count > 0 ); } else { DISABLE_AST do_accept( conn_id ); ENABLE_AST } FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds ); } /* ENABLE_AST } */ #ifndef WIN32 return; #endif }