added a function to check the file descriptor before adding it to
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 7 Sep 2005 13:50:55 +0000 (13:50 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 7 Sep 2005 13:50:55 +0000 (13:50 +0000)
the select call

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@531 9efc2488-bf62-4759-914b-345cdb29e865

src/router/router.c
src/router/router.h

index 386fac0..71fe745 100644 (file)
@@ -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 ) {
 
index 8690835..85a5f74 100644 (file)
@@ -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.