dbus/dbus dbus-connection.c,1.115,1.116

John Palmieri johnp at kemper.freedesktop.org
Thu Mar 2 14:24:30 PST 2006


Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv16884/dbus

Modified Files:
	dbus-connection.c 
Log Message:
2006-03-02  John (J5) Palmieri  <johnp at redhat.com>

	* dbus/dbus-connection.c: 
	(_dbus_connection_block_pending_call):
	Check to see if our data has already been read off the connection
	by another blocking pending call before we block in poll.
	(check_for_reply_and_update_dispatch_unlocked):
	Code taken from _dbus_connection_block_pending_call - checks for
	an already read reply and updates the dispatch if there is one.

	* test/name-test/test-pending-call-dispatch.c:
	New test for making sure we don't get stuck polling a 
	dbus connection which has no data on the socket when
	blocking out of order on two or more pending calls.


Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- dbus-connection.c	30 Nov 2005 20:30:02 -0000	1.115
+++ dbus-connection.c	2 Mar 2006 22:24:28 -0000	1.116
@@ -2533,6 +2533,36 @@
   return NULL;
 }
 
+static dbus_bool_t
+check_for_reply_and_update_dispatch_unlocked (DBusPendingCall *pending)
+{
+  DBusMessage *reply;
+  DBusDispatchStatus status;
+  DBusConnection *connection;
+
+  connection = pending->connection;
+
+  reply = check_for_reply_unlocked (connection, pending->reply_serial);
+  if (reply != NULL)
+    {
+      _dbus_verbose ("%s checked for reply\n", _DBUS_FUNCTION_NAME);
+
+      _dbus_verbose ("dbus_connection_send_with_reply_and_block(): got reply\n");
+
+      _dbus_pending_call_complete_and_unlock (pending, reply);
+      dbus_message_unref (reply);
+
+      CONNECTION_LOCK (connection);
+      status = _dbus_connection_get_dispatch_status_unlocked (connection);
+      _dbus_connection_update_dispatch_status_and_unlock (connection, status);
+      dbus_pending_call_unref (pending);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 /**
  * When a function that blocks has been called with a timeout, and we
  * run out of memory, the time to wait for memory is based on the
@@ -2616,6 +2646,11 @@
                  start_tv_sec, start_tv_usec,
                  end_tv_sec, end_tv_usec);
 
+  /* check to see if we already got the data off the socket */
+  /* from another blocked pending call */
+  if (check_for_reply_and_update_dispatch_unlocked (pending))
+    return;
+
   /* Now we wait... */
   /* always block at least once as we know we don't have the reply yet */
   _dbus_connection_do_iteration_unlocked (connection,
@@ -2645,27 +2680,8 @@
     }
   
   if (status == DBUS_DISPATCH_DATA_REMAINS)
-    {
-      DBusMessage *reply;
-      
-      reply = check_for_reply_unlocked (connection, client_serial);
-      if (reply != NULL)
-        {
-          _dbus_verbose ("%s checked for reply\n", _DBUS_FUNCTION_NAME);
-
-          _dbus_verbose ("dbus_connection_send_with_reply_and_block(): got reply\n");
-          
-          _dbus_pending_call_complete_and_unlock (pending, reply);
-          dbus_message_unref (reply);
-
-          CONNECTION_LOCK (connection);
-          status = _dbus_connection_get_dispatch_status_unlocked (connection);
-          _dbus_connection_update_dispatch_status_and_unlock (connection, status);
-          dbus_pending_call_unref (pending);
-          
-          return;
-        }
-    }
+    if (check_for_reply_and_update_dispatch_unlocked (pending))
+      return;  
   
   _dbus_get_current_time (&tv_sec, &tv_usec);
   



More information about the dbus-commit mailing list