dbus/dbus dbus-connection.c, 1.121, 1.122 dbus-pending-call-internal.h, 1.1, 1.2 dbus-pending-call.c, 1.12, 1.13

John Palmieri johnp at kemper.freedesktop.org
Thu Jul 13 20:09:24 PDT 2006


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

Modified Files:
	dbus-connection.c dbus-pending-call-internal.h 
	dbus-pending-call.c 
Log Message:
* dbus-connection.c (dbus_connection_send_with_reply): return TRUE
  and set pending_reply out arg to NULL is connection is disconnected
  (connection_timeout_and_complete_all_pending_calls_unlocked): New
  static method for cleaning up pending calls on disconnect
  (_dbus_connection_get_dispatch_status_unlocked): If we have pending
  calls queued timeouts on disconnect

* dbus/dbus-pending-call.ci (_dbus_pending_call_set_connection):
  Remove


Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- dbus-connection.c	12 Jul 2006 15:57:01 -0000	1.121
+++ dbus-connection.c	14 Jul 2006 03:09:22 -0000	1.122
@@ -386,6 +386,8 @@
 	}
     }
   
+  
+
   connection->n_incoming += 1;
 
   _dbus_connection_wakeup_mainloop (connection);
@@ -832,7 +834,6 @@
           _dbus_pending_call_set_timeout_added (pending, FALSE);
         }
      
-      _dbus_pending_call_clear_connection (pending);
       dbus_pending_call_unref (pending);
     }
 }
@@ -2359,9 +2360,9 @@
  * 
  * @param connection the connection
  * @param message the message to send
- * @param pending_return return location for a #DBusPendingCall object, or #NULL
+ * @param pending_return return location for a #DBusPendingCall object, or #NULLif connection is disconnected
  * @param timeout_milliseconds timeout in milliseconds or -1 for default
- * @returns #TRUE if the message is successfully queued, #FALSE if no memory.
+ * @returns #FALSE if no memory, #TRUE otherwise.
  *
  */
 dbus_bool_t
@@ -2380,16 +2381,28 @@
 
   if (pending_return)
     *pending_return = NULL;
-  
+
+  CONNECTION_LOCK (connection);
+
+   if (!_dbus_connection_get_is_connected_unlocked (connection))
+    {
+      CONNECTION_UNLOCK (connection);
+
+      *pending_return = NULL;
+
+      return TRUE;
+    }
+
   pending = _dbus_pending_call_new (connection,
                                     timeout_milliseconds,
                                     reply_handler_timeout);
 
   if (pending == NULL)
-    return FALSE;
+    {
+      CONNECTION_UNLOCK (connection);
+      return FALSE;
+    }
 
-  CONNECTION_LOCK (connection);
-  
   /* Assign a serial to the message */
   serial = dbus_message_get_serial (message);
   if (serial == 0)
@@ -2469,6 +2482,33 @@
 }
 
 static void
+connection_timeout_and_complete_all_pending_calls_unlocked (DBusConnection *connection)
+{
+  DBusHashIter iter;
+
+  _dbus_hash_iter_init (connection->pending_replies, &iter);
+
+  /* create list while we remove the iters from the hash
+     because we need to go over it a couple of times */
+  while (_dbus_hash_iter_next (&iter))
+    {
+      DBusPendingCall *pending;
+ 
+      pending = (DBusPendingCall *) _dbus_hash_iter_get_value (&iter);
+      dbus_pending_call_ref (pending);
+     
+      _dbus_pending_call_queue_timeout_error (pending, 
+                                              connection);
+      _dbus_connection_remove_timeout_unlocked (connection,
+                                                _dbus_pending_call_get_timeout (pending));
+   
+      _dbus_hash_iter_remove_entry (&iter);
+
+      dbus_pending_call_unref (pending);
+    }
+}
+
+static void
 complete_pending_call_and_unlock (DBusPendingCall *pending,
                                   DBusMessage     *message)
 {
@@ -3300,7 +3340,10 @@
                              _DBUS_FUNCTION_NAME);
 
               connection_forget_shared_unlocked (connection);
-              
+             
+              /* If we have pending calls queued timeouts on disconnect */
+              connection_timeout_and_complete_all_pending_calls_unlocked (connection);
+ 
               /* We haven't sent the disconnect message already,
                * and all real messages have been queued up.
                */
@@ -3734,10 +3777,12 @@
                                   "Disconnected"))
         {
           _dbus_bus_check_connection_and_unref (connection);
+
           if (connection->exit_on_disconnect)
             {
+              CONNECTION_UNLOCK (connection);            
+ 
               _dbus_verbose ("Exiting on Disconnected signal\n");
-              CONNECTION_UNLOCK (connection);
               _dbus_exit (1);
               _dbus_assert_not_reached ("Call to exit() returned");
             }

Index: dbus-pending-call-internal.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-pending-call-internal.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-pending-call-internal.h	12 Jul 2006 15:57:01 -0000	1.1
+++ dbus-pending-call-internal.h	14 Jul 2006 03:09:22 -0000	1.2
@@ -39,8 +39,6 @@
 void            _dbus_pending_call_set_reply_serial  (DBusPendingCall *pending,
                                                       dbus_uint32_t serial);
 DBusConnection *_dbus_pending_call_get_connection    (DBusPendingCall *pending);
-void            _dbus_pending_call_set_connection    (DBusPendingCall *pending,
-                                                     DBusConnection *connection);
 
 void              _dbus_pending_call_complete                  (DBusPendingCall    *pending);
 void              _dbus_pending_call_set_reply                 (DBusPendingCall    *pending,

Index: dbus-pending-call.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-pending-call.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dbus-pending-call.c	12 Jul 2006 15:57:01 -0000	1.12
+++ dbus-pending-call.c	14 Jul 2006 03:09:22 -0000	1.13
@@ -83,7 +83,7 @@
   DBusTimeout *timeout;
 
   _dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
-  
+ 
   if (timeout_milliseconds == -1)
     timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
 
@@ -119,8 +119,11 @@
   
   pending->refcount.value = 1;
   pending->connection = connection;
+  dbus_connection_ref (pending->connection);
+
   pending->timeout = timeout;
 
+
   _dbus_data_slot_list_init (&pending->slot_list);
   
   return pending;
@@ -285,34 +288,6 @@
 }
 
 /**
- * Sets the connection associated with the pending call
- *
- * @param pending the pending_call
- * @param connection the connection which is associated with the pending call
- */
-void
-_dbus_pending_call_set_connection (DBusPendingCall *pending,
-                                   DBusConnection *connection)
-{
-  _dbus_assert (pending != NULL);  
-
-  pending->connection = connection;
-}
-
-/**
- * NULLs out the connection
- *
- * @param pending the pending_call 
- */
-void 
-_dbus_pending_call_clear_connection (DBusPendingCall *pending)
-{
-  _dbus_assert (pending != NULL);  
-
-  pending->connection = NULL;
-}
-
-/**
  * Sets the reply message associated with the pending call to a timeout error
  *
  * @param pending the pending_call
@@ -403,12 +378,13 @@
       /* If we get here, we should be already detached
        * from the connection, or never attached.
        */
-      _dbus_assert (pending->connection == NULL);
       _dbus_assert (!pending->timeout_added);  
+     
+      dbus_connection_unref (pending->connection);
 
       /* this assumes we aren't holding connection lock... */
       _dbus_data_slot_list_free (&pending->slot_list);
-      
+
       if (pending->timeout != NULL)
         _dbus_timeout_unref (pending->timeout);
       



More information about the dbus-commit mailing list