[Opensrf-commits] r1844 - trunk/src/router (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Nov 5 16:03:41 EST 2009


Author: scottmk
Date: 2009-11-05 16:03:36 -0500 (Thu, 05 Nov 2009)
New Revision: 1844

Modified:
   trunk/src/router/osrf_router.c
Log:
Several bug fixes:

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


Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2009-11-05 20:23:49 UTC (rev 1843)
+++ trunk/src/router/osrf_router.c	2009-11-05 21:03:36 UTC (rev 1844)
@@ -203,7 +203,6 @@
 
 		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 @@
 		/* 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 ) {
+		/* 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 );
 
-			osrfRouterClass* class;
-			osrfHashIterator* itr = router->class_itr;  // remove a layer of indirection
-			osrfHashIteratorReset( itr );
+		while( (class = osrfHashIteratorNext(itr)) ) {   // for each class
 
-			while( (class = osrfHashIteratorNext(itr)) ) {
+			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 @@
 						/* 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 @@
 			message_free( error );
 		}
 
+		/* remove the dead node */
+		osrfRouterClassRemoveNode( router, classname, msg->sender);
 		return NULL;
 
 	} else {



More information about the opensrf-commits mailing list