Several bug fixes:
authorscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 5 Nov 2009 21:03:36 +0000 (21:03 +0000)
committerscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 5 Nov 2009 21:03:36 +0000 (21:03 +0000)
1. In osrfRouterRun(): eliminate the counting of sockets.  Rely
on the traversal of the class list to cover all the active
sockets.  Otherwise we would enter an infinite loop if we had just
deleted a class with an active socket.

2. In osrfRouterClassHandleIncoming(): in the case of an error
message that we can't reroute to a different node, do a continue
instead of a return.  Otherwise we delay any further messages that
may be enqueued for the same class, and possibly skip them entirely.

Also, in the same scenario: free the message before continuing, in
order to avoid a memory leak, and clear the transaction id for the
logging routines.

3. In osrfRouterClassHandleBounce(): remove the dead node when it is the
last one left for its class.  Remove the class as well, since it is
no longer usable.  We had been leaving the dead node around, for no
good reason.

M    src/router/osrf_router.c

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

src/router/osrf_router.c

index fde72bd..3145966 100644 (file)
@@ -203,7 +203,6 @@ void osrfRouterRun( osrfRouter* router ) {
 
                fd_set set;
                int maxfd = _osrfRouterFillFDSet( router, &set );
-               int numhandled = 0;
 
                // Wait indefinitely for an incoming message
                if( (selectret = select(maxfd + 1, &set, NULL, NULL, NULL)) < 0 ) {
@@ -224,33 +223,28 @@ void osrfRouterRun( osrfRouter* router ) {
                /* see if there is a top level router message */
                if( FD_ISSET(routerfd, &set) ) {
                        osrfLogDebug( OSRF_LOG_MARK, "Top router socket is active: %d", routerfd );
-                       numhandled++;
                        osrfRouterHandleIncoming( router );
                }
 
-               /* now check each of the connected classes and see if they have data to route */
-               while( numhandled < selectret ) {
-
-                       osrfRouterClass* class;
-                       osrfHashIterator* itr = router->class_itr;  // remove a layer of indirection
-                       osrfHashIteratorReset( itr );
+               /* Check each of the connected classes and see if they have data to route */
+               osrfRouterClass* class;
+               osrfHashIterator* itr = router->class_itr;  // remove a layer of indirection
+               osrfHashIteratorReset( itr );
 
-                       while( (class = osrfHashIteratorNext(itr)) ) {
+               while( (class = osrfHashIteratorNext(itr)) ) {   // for each class
 
-                               const char* classname = osrfHashIteratorKey(itr);
+                       const char* classname = osrfHashIteratorKey(itr);
 
-                               if( classname ) {
+                       if( classname ) {
 
-                                       osrfLogDebug( OSRF_LOG_MARK, "Checking %s for activity...", classname );
+                               osrfLogDebug( OSRF_LOG_MARK, "Checking %s for activity...", classname );
 
-                                       int sockfd = client_sock_fd( class->connection );
-                                       if(FD_ISSET( sockfd, &set )) {
-                                               osrfLogDebug( OSRF_LOG_MARK, "Socket is active: %d", sockfd );
-                                               numhandled++;
-                                               osrfRouterClassHandleIncoming( router, classname, class );
-                                       }
+                               int sockfd = client_sock_fd( class->connection );
+                               if(FD_ISSET( sockfd, &set )) {
+                                       osrfLogDebug( OSRF_LOG_MARK, "Socket is active: %d", sockfd );
+                                       osrfRouterClassHandleIncoming( router, classname, class );
                                }
-                       } // end while
+                       }
                } // end while
        } // end while
 }
@@ -344,7 +338,7 @@ static void osrfRouterClassHandleIncoming( osrfRouter* router, const char* class
                                                /* we have no one to send the requested message to */
                                                message_free( msg );
                                                osrfLogClearXid();
-                                               return;
+                                               continue;
                                        }
                                        osrfRouterClassHandleMessage( router, class, bouncedMessage );
                                        message_free( bouncedMessage );
@@ -506,6 +500,8 @@ static transport_message* osrfRouterClassHandleBounce( osrfRouter* router,
                        message_free( error );
                }
 
+               /* remove the dead node */
+               osrfRouterClassRemoveNode( router, classname, msg->sender);
                return NULL;
 
        } else {