[Openais] Maybe clean up poll_dispatch_delete a bit

Jeff jeff3140 at gmail.com
Fri Apr 14 04:55:48 PDT 2006


Hello folks,

We are looking at the openais library as a possible transport for a
project we are undertaking and so I've been reading a bit of the code.
It struck me that poll_dispatch_delete() in exec/aispoll.c could be
tightened up a bit. The 2nd "if (found)" block was being executed even
if the search loop preceeding it did not find a match as long as the
1st search loop did. It may be that this is an impossible state, but
the code implies otherwise.

It wasn't clear to me whether poll_dispatch_delete() should return 0
if either loop finds a match or only if both do so I preserved the
existing behavior.

--- exec/aispoll.c	2006-04-13 15:15:06.000000000 -0400
+++ execnew/aispoll.c	2006-04-14 07:40:48.897448000 -0400
@@ -250,8 +250,7 @@
 	struct poll_instance *poll_instance;
 	int i;
 	SaErrorT error;
-	int found = 0;
-	int res = 0;
+	int res;

 	error = saHandleInstanceGet (&poll_instance_database, handle,
 		(void *)&poll_instance);
@@ -263,33 +262,25 @@
 	/*
 	 * Find dispatch fd to delete
 	 */
+	res = -EBADF;
 	for (i = 0; i < poll_instance->poll_entry_count; i++) {
 		if (poll_instance->poll_entries[i].ufd.fd == fd) {
-			found = 1;
+		        poll_instance->poll_entries[i].ufd.fd = -1;
+			poll_instance->poll_entries[i].ufd.revents = 0;
+			res = 0;
 			break;
 		}
 	}

-	if (found) {
-		poll_instance->poll_entries[i].ufd.fd = -1;
-		poll_instance->poll_entries[i].ufd.revents = 0;
-	}
-
 	for (i = 0; i < poll_instance->poll_entry_count; i++) {
 		if (poll_instance->ufds[i].fd == fd) {
-			found = 1;
+		        poll_instance->ufds[i].fd = -1;
+			poll_instance->ufds[i].revents = 0;
+			res = 0;
 			break;
 		}
 	}

-	res = -EBADF;
-	if (found) {
-		poll_instance->ufds[i].fd = -1;
-		poll_instance->ufds[i].revents = 0;
-		res = 0;
-	}
-
-
 	saHandleInstancePut (&poll_instance_database, handle);

 error_exit:




More information about the Openais mailing list