hunting segfaults...
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 21 Jun 2005 14:41:59 +0000 (14:41 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 21 Jun 2005 14:41:59 +0000 (14:41 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@369 9efc2488-bf62-4759-914b-345cdb29e865

src/jserver/jserver-c.c
src/utils/socket_bundle.c

index c8d447e..b30ce5a 100644 (file)
@@ -157,6 +157,7 @@ void _jserver_remove_client(jserver* js, char* addr) {
 
        if(node->addr && !strcmp(node->addr,addr)) {
                js->client = node->next;
+               debug_handler("Removing the first jserver client");
                socket_disconnect(js->mgr, node->id);
                _free_jclient_node(node);
                return;
@@ -169,6 +170,7 @@ void _jserver_remove_client(jserver* js, char* addr) {
        while(node) {
                if(node->addr && !strcmp(node->addr,addr)) {
                        tail_node->next = node->next;
+                       debug_handler("Removing a jserver client");
                        socket_disconnect(js->mgr, node->id);
                        _free_jclient_node(node);
                        return;
index 113f2f8..1a5497f 100644 (file)
@@ -293,31 +293,49 @@ int socket_wait_all(socket_manager* mgr, int timeout) {
 int _socket_route_data(
        socket_manager* mgr, int num_active, fd_set* read_set) {
 
-       socket_node* node = mgr->socket;
-       int handled = 0;
-       
-       while(node && (handled < num_active)) {
+       if(mgr == NULL) return -1;
 
-               int sock_fd = node->sock_fd;
 
-               /* does this socket have data? */
-               if( FD_ISSET( sock_fd, read_set ) ) {
+       /* come back here if someone yanks a socket_node from beneath us */
+       while(1) {
 
-                       debug_handler("Socket %d active", sock_fd);
-                       handled++;
-                       FD_CLR(sock_fd, read_set);
-
-                       if(node->endpoint == SERVER_SOCKET) 
-                               _socket_handle_new_client(mgr, node);
+               socket_node* node = mgr->socket;
+               int handled = 0;
+               int status = 0;
+               
+               while(node && (handled < num_active)) {
+       
+                       int sock_fd = node->sock_fd;
+       
+                       /* does this socket have data? */
+                       if( FD_ISSET( sock_fd, read_set ) ) {
+       
+                               debug_handler("Socket %d active", sock_fd);
+                               handled++;
+                               FD_CLR(sock_fd, read_set);
+       
+                               if(node->endpoint == SERVER_SOCKET) 
+                                       _socket_handle_new_client(mgr, node);
+       
+                               if(node->endpoint == CLIENT_SOCKET ) 
+                                       status = _socket_handle_client_data(mgr, node);
+       
+                               /* someone may have yanked a socket_node out from under 
+                                       us...start over with the first socket */
+                               if(status == -1)  {
+                                       debug_handler("Backtracking back to start of loop because "
+                                                       "of -1 return code from _socket_handle_client_data()");
+                               }
+                       }
 
-                       if(node->endpoint == CLIENT_SOCKET ) 
-                               _socket_handle_client_data(mgr, node);
+                       if(status == -1) break;
+                       node = node->next;
 
                } // is_set
-               
-               node = node->next;
 
-       } // while(node)
+               if(status == 0) break;
+               if(status == -1) status = 0;
+       } 
 
        return 0;
 }
@@ -385,8 +403,10 @@ int _socket_handle_client_data(socket_manager* mgr, socket_node* node) {
        }
 
        if(read_bytes == 0) {  /* socket closed by client */
-               if(mgr->on_socket_closed)
+               if(mgr->on_socket_closed) {
                        mgr->on_socket_closed(mgr->blob, sock_fd);
+                       return -1;
+               }
        }
 
        return 0;