From f587ce7845edb0eb01451368d01b5bc86b5904cd Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 15 Mar 2003 20:47:16 +0000 Subject: 2003-03-15 Havoc Pennington 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 --- bus/loop.c | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'bus/loop.c') diff --git a/bus/loop.c b/bus/loop.c index 10614745..ea0ec106 100644 --- a/bus/loop.c +++ b/bus/loop.c @@ -294,9 +294,26 @@ bus_loop_iterate (dbus_bool_t block) bus_loop_quit (); goto next_iteration; } + + /* count enabled watches */ + n_fds = 0; + link = _dbus_list_get_first_link (&callbacks); + while (link != NULL) + { + DBusList *next = _dbus_list_get_next_link (&callbacks, link); + Callback *cb = link->data; + if (cb->type == CALLBACK_WATCH) + { + WatchCallback *wcb = WATCH_CALLBACK (cb); + + if (dbus_watch_get_enabled (wcb->watch)) + ++n_fds; + } - n_fds = watch_count; + link = next; + } + /* fill our array of fds and watches */ if (n_fds > 0) { fds = dbus_new0 (DBusPollFD, n_fds); @@ -323,18 +340,21 @@ bus_loop_iterate (dbus_bool_t block) { unsigned int flags; WatchCallback *wcb = WATCH_CALLBACK (cb); + + if (dbus_watch_get_enabled (wcb->watch)) + { + watches_for_fds[i] = wcb; - watches_for_fds[i] = wcb; - - flags = dbus_watch_get_flags (wcb->watch); + flags = dbus_watch_get_flags (wcb->watch); - fds[i].fd = dbus_watch_get_fd (wcb->watch); - if (flags & DBUS_WATCH_READABLE) - fds[i].events |= _DBUS_POLLIN; - if (flags & DBUS_WATCH_WRITABLE) - fds[i].events |= _DBUS_POLLOUT; + fds[i].fd = dbus_watch_get_fd (wcb->watch); + if (flags & DBUS_WATCH_READABLE) + fds[i].events |= _DBUS_POLLIN; + if (flags & DBUS_WATCH_WRITABLE) + fds[i].events |= _DBUS_POLLOUT; - ++i; + ++i; + } } link = next; @@ -359,7 +379,8 @@ bus_loop_iterate (dbus_bool_t block) DBusList *next = _dbus_list_get_next_link (&callbacks, link); Callback *cb = link->data; - if (cb->type == CALLBACK_TIMEOUT) + if (cb->type == CALLBACK_TIMEOUT && + dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout)) { TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb); unsigned long interval; @@ -427,7 +448,8 @@ bus_loop_iterate (dbus_bool_t block) if (exited) goto next_iteration; - if (cb->type == CALLBACK_TIMEOUT) + if (cb->type == CALLBACK_TIMEOUT && + dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout)) { TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb); unsigned long interval; @@ -513,7 +535,8 @@ bus_loop_iterate (dbus_bool_t block) * weird POLLFOO thing like POLLWRBAND */ - if (condition != 0) + if (condition != 0 && + dbus_watch_get_enabled (wcb->watch)) { (* wcb->function) (wcb->watch, condition, -- cgit