From 3bea935316ff048e68dea6a26c2e8e9fd314477f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 14 Mar 2003 01:27:58 +0000 Subject: 2003-03-13 Havoc Pennington * dbus/dbus-timeout.c (_dbus_timeout_list_set_functions): handle out of memory * dbus/dbus-watch.c (_dbus_watch_list_set_functions): handle out of memory * dbus/dbus-connection.h: Make AddWatchFunction and AddTimeoutFunction return a bool so they can fail on out-of-memory * bus/bus.c (bus_context_new): set up timeout handlers * bus/connection.c (bus_connections_setup_connection): set up timeout handlers * glib/dbus-gmain.c: adapt to the fact that set_functions stuff can fail * bus/bus.c (bus_context_new): adapt to changes * bus/connection.c: adapt to changes * test/watch.c: adapt to DBusWatch changes * bus/dispatch.c (bus_dispatch_test): started adding this but didn't finish --- bus/connection.c | 77 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 16 deletions(-) (limited to 'bus/connection.c') diff --git a/bus/connection.c b/bus/connection.c index cdc8be79..f0463392 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -108,11 +108,18 @@ bus_connection_disconnected (DBusConnection *connection) bus_dispatch_remove_connection (connection); /* no more watching */ - dbus_connection_set_watch_functions (connection, - NULL, NULL, - connection, - NULL); - + if (!dbus_connection_set_watch_functions (connection, + NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting watch functions to NULL failed"); + + if (!dbus_connection_set_timeout_functions (connection, + NULL, NULL, + connection, + NULL)) + _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + bus_connection_remove_transactions (connection); _dbus_list_remove (&d->connections->list, connection); @@ -140,12 +147,12 @@ connection_watch_callback (DBusWatch *watch, dbus_connection_unref (connection); } -static void +static dbus_bool_t add_connection_watch (DBusWatch *watch, DBusConnection *connection) { - bus_loop_add_watch (watch, connection_watch_callback, connection, - NULL); + return bus_loop_add_watch (watch, connection_watch_callback, connection, + NULL); } static void @@ -155,6 +162,27 @@ remove_connection_watch (DBusWatch *watch, bus_loop_remove_watch (watch, connection_watch_callback, connection); } +static void +connection_timeout_callback (DBusTimeout *timeout, + void *data) +{ + dbus_timeout_handle (timeout); +} + +static dbus_bool_t +add_connection_timeout (DBusTimeout *timeout, + DBusConnection *connection) +{ + return bus_loop_add_timeout (timeout, connection_timeout_callback, connection, NULL); +} + +static void +remove_connection_timeout (DBusTimeout *timeout, + DBusConnection *connection) +{ + bus_loop_remove_timeout (timeout, connection_timeout_callback, connection); +} + static void free_connection_data (void *data) { @@ -249,18 +277,35 @@ bus_connections_setup_connection (BusConnections *connections, dbus_connection_disconnect (connection); return FALSE; } - - dbus_connection_ref (connection); - dbus_connection_set_watch_functions (connection, - (DBusAddWatchFunction) add_connection_watch, - (DBusRemoveWatchFunction) remove_connection_watch, - connection, - NULL); + if (!dbus_connection_set_watch_functions (connection, + (DBusAddWatchFunction) add_connection_watch, + (DBusRemoveWatchFunction) remove_connection_watch, + connection, + NULL)) + { + dbus_connection_disconnect (connection); + return FALSE; + } + + if (!dbus_connection_set_timeout_functions (connection, + (DBusAddTimeoutFunction) add_connection_timeout, + (DBusRemoveTimeoutFunction) remove_connection_timeout, + connection, NULL)) + { + dbus_connection_disconnect (connection); + return FALSE; + } + /* Setup the connection with the dispatcher */ if (!bus_dispatch_add_connection (connection)) - return FALSE; + { + dbus_connection_disconnect (connection); + return FALSE; + } + + dbus_connection_ref (connection); return TRUE; } -- cgit