summaryrefslogtreecommitdiffstats
path: root/glib
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-15 20:47:16 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-15 20:47:16 +0000
commitf587ce7845edb0eb01451368d01b5bc86b5904cd (patch)
treef3a549cd61df701882d818b5fc452b1438097f5b /glib
parentf05f87a825ab8ed5273674a7f65521ffc526f0d2 (diff)
2003-03-15 Havoc Pennington <hp@pobox.com>
Make it pass the Hello handling test including all OOM codepaths. Now to do other messages... * bus/services.c (bus_service_remove_owner): fix crash when removing owner from an empty list of owners (bus_registry_ensure): don't leave service in the list of a connection's owned services if we fail to put the service in the hash table. * bus/connection.c (bus_connection_preallocate_oom_error): set error flag on the OOM error. * dbus/dbus-connection.c (_dbus_connection_new_for_transport): handle _dbus_transport_set_connection failure * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): modify to create watches up front and simply enable/disable them as needed. (unix_connection_set): this can now fail on OOM * dbus/dbus-timeout.c, dbus/dbus-watch.c: add concept of enabling/disabling a watch or timeout. * bus/loop.c (bus_loop_iterate): don't touch disabled watches/timeouts * glib/dbus-gmain.c: adapt to enable/disable watches and timeouts
Diffstat (limited to 'glib')
-rw-r--r--glib/dbus-gmain.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/glib/dbus-gmain.c b/glib/dbus-gmain.c
index 6ce13888..5eb75d10 100644
--- a/glib/dbus-gmain.c
+++ b/glib/dbus-gmain.c
@@ -238,6 +238,9 @@ add_watch (DBusWatch *watch,
GPollFD *poll_fd;
DBusGSource *dbus_source;
guint flags;
+
+ if (!dbus_watch_get_enabled (watch))
+ return TRUE;
dbus_source = data;
@@ -269,6 +272,8 @@ remove_watch (DBusWatch *watch,
GPollFD *poll_fd;
poll_fd = dbus_watch_get_data (watch);
+ if (poll_fd == NULL)
+ return; /* probably a not-enabled watch that was added */
dbus_source->poll_fds = g_list_remove (dbus_source->poll_fds, poll_fd);
g_hash_table_remove (dbus_source->watches, poll_fd);
@@ -277,6 +282,19 @@ remove_watch (DBusWatch *watch,
g_free (poll_fd);
}
+static void
+watch_toggled (DBusWatch *watch,
+ void *data)
+{
+ /* Because we just exit on OOM, enable/disable is
+ * no different from add/remove
+ */
+ if (dbus_watch_get_enabled (watch))
+ add_watch (watch, data);
+ else
+ remove_watch (watch, data);
+}
+
static gboolean
timeout_handler (gpointer data)
{
@@ -293,6 +311,9 @@ add_timeout (DBusTimeout *timeout,
{
guint timeout_tag;
+ if (!dbus_timeout_get_enabled (timeout))
+ return TRUE;
+
timeout_tag = g_timeout_add (dbus_timeout_get_interval (timeout),
timeout_handler, timeout);
@@ -308,10 +329,25 @@ remove_timeout (DBusTimeout *timeout,
guint timeout_tag;
timeout_tag = GPOINTER_TO_UINT (dbus_timeout_get_data (timeout));
-
- g_source_remove (timeout_tag);
+
+ if (timeout_tag != 0) /* if 0, probably timeout was disabled */
+ g_source_remove (timeout_tag);
+}
+
+static void
+timeout_toggled (DBusTimeout *timeout,
+ void *data)
+{
+ /* Because we just exit on OOM, enable/disable is
+ * no different from add/remove
+ */
+ if (dbus_timeout_get_enabled (timeout))
+ add_timeout (timeout, data);
+ else
+ remove_timeout (timeout, data);
}
+
static void
free_source (GSource *source)
{
@@ -363,12 +399,14 @@ dbus_connection_setup_with_g_main (DBusConnection *connection)
if (!dbus_connection_set_watch_functions (connection,
add_watch,
remove_watch,
+ watch_toggled,
source, NULL))
goto nomem;
if (!dbus_connection_set_timeout_functions (connection,
add_timeout,
remove_timeout,
+ timeout_toggled,
NULL, NULL))
goto nomem;
@@ -412,11 +450,13 @@ dbus_server_setup_with_g_main (DBusServer *server)
dbus_server_set_watch_functions (server,
add_watch,
remove_watch,
+ watch_toggled,
source, NULL);
dbus_server_set_timeout_functions (server,
add_timeout,
remove_timeout,
+ timeout_toggled,
NULL, NULL);
g_source_attach (source, NULL);