summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-timeout.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-14 01:27:58 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-14 01:27:58 +0000
commit3bea935316ff048e68dea6a26c2e8e9fd314477f (patch)
tree498e62121c89d78693070d04e6bc6a6462efe2a7 /dbus/dbus-timeout.c
parent81c30364c291045d556c88f6818033104e627b6e (diff)
2003-03-13 Havoc Pennington <hp@redhat.com>
* 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
Diffstat (limited to 'dbus/dbus-timeout.c')
-rw-r--r--dbus/dbus-timeout.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/dbus/dbus-timeout.c b/dbus/dbus-timeout.c
index 379aeee3..408de422 100644
--- a/dbus/dbus-timeout.c
+++ b/dbus/dbus-timeout.c
@@ -181,15 +181,50 @@ _dbus_timeout_list_free (DBusTimeoutList *timeout_list)
* @param remove_function the remove timeout function.
* @param data the data for those functions.
* @param free_data_function the function to free the data.
+ * @returns #FALSE if no memory
*
*/
-void
+dbus_bool_t
_dbus_timeout_list_set_functions (DBusTimeoutList *timeout_list,
DBusAddTimeoutFunction add_function,
DBusRemoveTimeoutFunction remove_function,
void *data,
DBusFreeFunction free_data_function)
{
+ /* Add timeouts with the new function, failing on OOM */
+ if (add_function != NULL)
+ {
+ DBusList *link;
+
+ link = _dbus_list_get_first_link (&timeout_list->timeouts);
+ while (link != NULL)
+ {
+ DBusList *next = _dbus_list_get_next_link (&timeout_list->timeouts,
+ link);
+
+ if (!(* add_function) (link->data, data))
+ {
+ /* remove it all again and return FALSE */
+ DBusList *link2;
+
+ link2 = _dbus_list_get_first_link (&timeout_list->timeouts);
+ while (link2 != link)
+ {
+ DBusList *next = _dbus_list_get_next_link (&timeout_list->timeouts,
+ link2);
+
+ (* remove_function) (link2->data, data);
+
+ link2 = next;
+ }
+
+ return FALSE;
+ }
+
+ link = next;
+ }
+ }
+
/* Remove all current timeouts from previous timeout handlers */
if (timeout_list->remove_timeout_function != NULL)
@@ -207,13 +242,7 @@ _dbus_timeout_list_set_functions (DBusTimeoutList *timeout_list,
timeout_list->timeout_data = data;
timeout_list->timeout_free_data_function = free_data_function;
- /* Re-add all pending timeouts */
- if (timeout_list->add_timeout_function != NULL)
- {
- _dbus_list_foreach (&timeout_list->timeouts,
- (DBusForeachFunction) timeout_list->add_timeout_function,
- timeout_list->timeout_data);
- }
+ return TRUE;
}
/**
@@ -234,14 +263,21 @@ _dbus_timeout_list_add_timeout (DBusTimeoutList *timeout_list,
_dbus_timeout_ref (timeout);
if (timeout_list->add_timeout_function != NULL)
- (* timeout_list->add_timeout_function) (timeout,
- timeout_list->timeout_data);
+ {
+ if (!(* timeout_list->add_timeout_function) (timeout,
+ timeout_list->timeout_data))
+ {
+ _dbus_list_remove_last (&timeout_list->timeouts, timeout);
+ _dbus_timeout_unref (timeout);
+ return FALSE;
+ }
+ }
return TRUE;
}
/**
- * Removes a timeout from the watch list, invoking the
+ * Removes a timeout from the timeout list, invoking the
* application's DBusRemoveTimeoutFunction if appropriate.
*
* @param timeout_list the timeout list.