dbus/dbus dbus-connection-internal.h,1.13,1.14 dbus-connection.c,1.72,1.73 dbus-transport.c,1.34,1.35

Havoc Pennington hp@pdx.freedesktop.org
Sun, 26 Oct 2003 07:36:17 -0800


Update of /cvs/dbus/dbus/dbus
In directory pdx:/tmp/cvs-serv1046/dbus

Modified Files:
	dbus-connection-internal.h dbus-connection.c dbus-transport.c 
Log Message:
2003-10-26  Havoc Pennington  <hp@redhat.com>

	* dbus/dbus-connection.c: fix docs to properly describe the
	disconnected message
	(_dbus_connection_notify_disconnected): remove this function; 
	we can't synchronously add the disconnected message, we have to 
	do it after we've queued any remaining real messages
	(_dbus_connection_get_dispatch_status_unlocked): queue the
	disconnect message only if the transport has finished queueing all
	its real messages and is disconnected.
	(dbus_connection_disconnect): update the dispatch status here



Index: dbus-connection-internal.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection-internal.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- dbus-connection-internal.h	30 Sep 2003 02:32:52 -0000	1.13
+++ dbus-connection-internal.h	26 Oct 2003 15:36:15 -0000	1.14
@@ -77,7 +77,6 @@
 void              _dbus_connection_do_iteration                (DBusConnection     *connection,
                                                                 unsigned int        flags,
                                                                 int                 timeout_milliseconds);
-void              _dbus_connection_notify_disconnected         (DBusConnection     *connection);
 
 DBusPendingCall*  _dbus_pending_call_new                       (DBusConnection     *connection,
                                                                 int                 timeout_milliseconds,

Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- dbus-connection.c	21 Oct 2003 05:46:51 -0000	1.72
+++ dbus-connection.c	26 Oct 2003 15:36:15 -0000	1.73
@@ -99,15 +99,17 @@
  * handle the details here for you by setting up watch functions.
  *
  * When a connection is disconnected, you are guaranteed to get a
- * message with the name #DBUS_MESSAGE_LOCAL_DISCONNECT.
+ * signal "Disconnected" from the interface
+ * #DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL, path
+ * #DBUS_PATH_ORG_FREEDESKTOP_LOCAL.
  *
  * You may not drop the last reference to a #DBusConnection
  * until that connection has been disconnected.
  *
  * You may dispatch the unprocessed incoming message queue even if the
- * connection is disconnected. However, #DBUS_MESSAGE_LOCAL_DISCONNECT
- * will always be the last message in the queue (obviously no messages
- * are received after disconnection).
+ * connection is disconnected. However, "Disconnected" will always be
+ * the last message in the queue (obviously no messages are received
+ * after disconnection).
  *
  * #DBusConnection has thread locks and drops them when invoking user
  * callbacks, so in general is transparently threadsafe. However,
@@ -577,25 +579,6 @@
                                        timeout, enabled);
 }
 
-/**
- * Tells the connection that the transport has been disconnected.
- * Results in posting a disconnect message on the incoming message
- * queue.  Only has an effect the first time it's called.
- *
- * @param connection the connection
- */
-void
-_dbus_connection_notify_disconnected (DBusConnection *connection)
-{
-  if (connection->disconnect_message_link)
-    {
-      /* We haven't sent the disconnect message already */
-      _dbus_connection_queue_synthesized_message_link (connection,
-						       connection->disconnect_message_link);
-      connection->disconnect_message_link = NULL;
-    }
-}
-
 static dbus_bool_t
 _dbus_connection_attach_pending_call_unlocked (DBusConnection  *connection,
                                                DBusPendingCall *pending)
@@ -1305,18 +1288,27 @@
  * function does not affect the connection's reference count.  It's
  * safe to disconnect a connection more than once; all calls after the
  * first do nothing. It's impossible to "reconnect" a connection, a
- * new connection must be created.
+ * new connection must be created. This function may result in a call
+ * to the DBusDispatchStatusFunction set with
+ * dbus_connection_set_dispatch_status_function(), as the disconnect
+ * message it generates needs to be dispatched.
  *
  * @param connection the connection.
  */
 void
 dbus_connection_disconnect (DBusConnection *connection)
 {
+  DBusDispatchStatus status;
+  
   _dbus_return_if_fail (connection != NULL);
   
   CONNECTION_LOCK (connection);
   _dbus_transport_disconnect (connection->transport);
-  CONNECTION_UNLOCK (connection);
+  
+  status = _dbus_connection_get_dispatch_status_unlocked (connection);
+
+  /* this calls out to user code */
+  _dbus_connection_update_dispatch_status_and_unlock (connection, status);
 }
 
 static dbus_bool_t
@@ -2351,6 +2343,18 @@
       
       status = _dbus_transport_get_dispatch_status (connection->transport);
 
+      if (status == DBUS_DISPATCH_COMPLETE &&
+          connection->disconnect_message_link &&
+          !_dbus_transport_get_is_connected (connection->transport))
+        {
+          /* We haven't sent the disconnect message already,
+           * and all real messages have been queued up.
+           */
+          _dbus_connection_queue_synthesized_message_link (connection,
+                                                           connection->disconnect_message_link);
+          connection->disconnect_message_link = NULL;
+        }
+      
       if (status != DBUS_DISPATCH_COMPLETE)
         return status;
       else if (connection->n_incoming > 0)

Index: dbus-transport.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- dbus-transport.c	30 Sep 2003 02:32:53 -0000	1.34
+++ dbus-transport.c	26 Oct 2003 15:36:15 -0000	1.35
@@ -415,9 +415,6 @@
   (* transport->vtable->disconnect) (transport);
   
   transport->disconnected = TRUE;
-
-  if (transport->connection)
-    _dbus_connection_notify_disconnected (transport->connection);
 }
 
 /**