From: erickson Date: Tue, 21 Jun 2005 14:41:59 +0000 (+0000) Subject: hunting segfaults... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3b4b7ae2f15a3163b645192f74395218757af4fc;p=working%2FOpenSRF.git hunting segfaults... git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@369 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/jserver/jserver-c.c b/src/jserver/jserver-c.c index c8d447e..b30ce5a 100644 --- a/src/jserver/jserver-c.c +++ b/src/jserver/jserver-c.c @@ -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; diff --git a/src/utils/socket_bundle.c b/src/utils/socket_bundle.c index 113f2f8..1a5497f 100644 --- a/src/utils/socket_bundle.c +++ b/src/utils/socket_bundle.c @@ -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;