From: erickson Date: Wed, 7 Sep 2005 13:50:55 +0000 (+0000) Subject: added a function to check the file descriptor before adding it to X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2c0cd0b7e77486896ab999af93a60dcc96e551f5;p=working%2FOpenSRF.git added a function to check the file descriptor before adding it to the select call git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@531 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/router/router.c b/src/router/router.c index 386fac0..71fe745 100644 --- a/src/router/router.c +++ b/src/router/router.c @@ -196,19 +196,43 @@ int fill_fd_set( transport_router_registrar* router, fd_set* set ) { max_fd = router_fd; FD_SET( router_fd, set ); - server_class_node* cur_node = router->server_class_list; - while( cur_node != NULL ) { - int cur_class_fd = cur_node->jabber->t_client->session->sock_id; - if( cur_class_fd > max_fd ) - max_fd = cur_class_fd; - FD_SET( cur_class_fd, set ); - cur_node = cur_node->next; + while(1) { + + server_class_node* cur_node = router->server_class_list; + while( cur_node != NULL ) { + int cur_class_fd = cur_node->jabber->t_client->session->sock_id; + + if( check_fd(cur_class_fd) < 0 ) { + warning_handler("Found a dead node for %s", cur_node->server_class); + remove_server_class( router, cur_node ); + break; + + } else { + if( cur_class_fd > max_fd ) max_fd = cur_class_fd; + FD_SET( cur_class_fd, set ); + } + cur_node = cur_node->next; + } + if( cur_node == NULL ) break; } FD_CLR( 0, set ); return max_fd; } +int check_fd( int fd ) { + + fd_set tmpset; + FD_ZERO(&tmpset); + FD_SET(fd, &tmpset); + + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 0; + + return select(fd + 1, &tmpset, NULL, NULL, &tv); +} + void listen_loop( transport_router_registrar* router ) { diff --git a/src/router/router.h b/src/router/router.h index 8690835..85a5f74 100644 --- a/src/router/router.h +++ b/src/router/router.h @@ -253,6 +253,10 @@ osrf_message** router_registrar_process_app_request( transport_router_registrar* , osrf_message* omsg, int* num_responses ); +/* returns < 0 if the fd is not valid */ +int check_fd( int fd ); + + // ---------------------------------------------------------------------- // Adds a handler for the SIGUSR1 that we send to wake all the // listening threads.