summaryrefslogtreecommitdiff
path: root/bus/connection.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-09 22:15:05 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-09 22:15:05 +0000
commit7caf646fdf595946eb28202e2df3f847d28c7151 (patch)
treea55a420bb416e4b4ff2e8a73616788c1f118c50e /bus/connection.c
parent1708094c0e00ab433bb0a51981f8b77d24aee256 (diff)
downloaddbus-7caf646fdf595946eb28202e2df3f847d28c7151.tar.gz
2003-04-09 Havoc Pennington <hp@redhat.com>
* test/test-utils.c: use dispatch status function to fix this up * bus/connection.c (connection_watch_callback): don't dispatch from here (connection_timeout_callback): don't dispatch from here (bus_connections_setup_connection): set the dispatch status function (bus_connection_disconnected): unset it * dbus/dbus-mainloop.c (_dbus_loop_queue_dispatch): new function used to add a connection to be dispatched (_dbus_loop_iterate): do the dispatching at the end of each iteration * dbus/dbus-connection.c (dbus_connection_set_dispatch_status_function): new function allowing us to fix up main loop usage (_dbus_connection_last_unref): free all the various function user data (dbus_connection_dispatch): call the DispatchStatusFunction whenever this function returns (dbus_connection_handle_watch): call DispatchStatusFunction (dbus_connection_send_with_reply_and_block): call DispatchStatusFunction (reply_handler_timeout): call DispatchStatusFunction (dbus_connection_flush): call DispatchStatusFunction
Diffstat (limited to 'bus/connection.c')
-rw-r--r--bus/connection.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/bus/connection.c b/bus/connection.c
index f5a0ac16..aeb4f6e0 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -170,6 +170,9 @@ bus_connection_disconnected (DBusConnection *connection)
dbus_connection_set_unix_user_function (connection,
NULL, NULL, NULL);
+
+ dbus_connection_set_dispatch_status_function (connection,
+ NULL, NULL, NULL);
bus_connection_remove_transactions (connection);
@@ -190,15 +193,9 @@ connection_watch_callback (DBusWatch *watch,
{
DBusConnection *connection = data;
dbus_bool_t retval;
-
- dbus_connection_ref (connection);
retval = dbus_connection_handle_watch (connection, watch, condition);
- bus_connection_dispatch_all_messages (connection);
-
- dbus_connection_unref (connection);
-
return retval;
}
@@ -229,14 +226,8 @@ connection_timeout_callback (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- dbus_connection_ref (connection);
-
/* can return FALSE on OOM but we just let it fire again later */
dbus_timeout_handle (timeout);
-
- bus_connection_dispatch_all_messages (connection);
-
- dbus_connection_unref (connection);
}
static dbus_bool_t
@@ -259,6 +250,20 @@ remove_connection_timeout (DBusTimeout *timeout,
timeout, connection_timeout_callback, connection);
}
+static void
+dispatch_status_function (DBusConnection *connection,
+ DBusDispatchStatus new_status,
+ void *data)
+{
+ DBusLoop *loop = data;
+
+ if (new_status != DBUS_DISPATCH_COMPLETE)
+ {
+ while (!_dbus_loop_queue_dispatch (loop, connection))
+ _dbus_wait_for_memory ();
+ }
+}
+
static dbus_bool_t
allow_user_function (DBusConnection *connection,
unsigned long uid,
@@ -405,6 +410,11 @@ bus_connections_setup_connection (BusConnections *connections,
dbus_connection_set_unix_user_function (connection,
allow_user_function,
NULL, NULL);
+
+ dbus_connection_set_dispatch_status_function (connection,
+ dispatch_status_function,
+ bus_context_get_loop (connections->context),
+ NULL);
/* Setup the connection with the dispatcher */
if (!bus_dispatch_add_connection (connection))
@@ -415,6 +425,15 @@ bus_connections_setup_connection (BusConnections *connections,
bus_dispatch_remove_connection (connection);
goto out;
}
+
+ if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
+ {
+ if (!_dbus_loop_queue_dispatch (bus_context_get_loop (connections->context), connection))
+ {
+ bus_dispatch_remove_connection (connection);
+ goto out;
+ }
+ }
dbus_connection_ref (connection);
retval = TRUE;
@@ -437,6 +456,9 @@ bus_connections_setup_connection (BusConnections *connections,
dbus_connection_set_unix_user_function (connection,
NULL, NULL, NULL);
+ dbus_connection_set_dispatch_status_function (connection,
+ NULL, NULL, NULL);
+
if (!dbus_connection_set_data (connection,
connection_data_slot,
NULL, NULL))