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 --- test/watch.c | 99 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 44 deletions(-) (limited to 'test') diff --git a/test/watch.c b/test/watch.c index 73f5e97d..bdb18306 100644 --- a/test/watch.c +++ b/test/watch.c @@ -237,24 +237,28 @@ do_mainloop (void) while (link != NULL) { DBusList *next = _dbus_list_get_next_link (&watches, link); - int fd; DBusWatch *watch; - unsigned int flags; watch = link->data; - - fd = dbus_watch_get_fd (watch); - flags = dbus_watch_get_flags (watch); - - max_fd = MAX (max_fd, fd); - - if (flags & DBUS_WATCH_READABLE) - FD_SET (fd, &read_set); - - if (flags & DBUS_WATCH_WRITABLE) - FD_SET (fd, &write_set); - FD_SET (fd, &err_set); + if (dbus_watch_get_enabled (watch)) + { + int fd; + unsigned int flags; + + fd = dbus_watch_get_fd (watch); + flags = dbus_watch_get_flags (watch); + + max_fd = MAX (max_fd, fd); + + if (flags & DBUS_WATCH_READABLE) + FD_SET (fd, &read_set); + + if (flags & DBUS_WATCH_WRITABLE) + FD_SET (fd, &write_set); + + FD_SET (fd, &err_set); + } link = next; } @@ -266,10 +270,7 @@ do_mainloop (void) while (link != NULL) { DBusList *next = _dbus_list_get_next_link (&watches, link); - int fd; DBusWatch *watch; - unsigned int flags; - unsigned int condition; if (initial_watch_serial != watch_list_serial) { @@ -286,44 +287,52 @@ do_mainloop (void) } watch = link->data; + + if (dbus_watch_get_enabled (watch)) + { + int fd; + unsigned int flags; + unsigned int condition; + - fd = dbus_watch_get_fd (watch); - flags = dbus_watch_get_flags (watch); + fd = dbus_watch_get_fd (watch); + flags = dbus_watch_get_flags (watch); - condition = 0; + condition = 0; - if ((flags & DBUS_WATCH_READABLE) && - FD_ISSET (fd, &read_set)) - condition |= DBUS_WATCH_READABLE; + if ((flags & DBUS_WATCH_READABLE) && + FD_ISSET (fd, &read_set)) + condition |= DBUS_WATCH_READABLE; - if ((flags & DBUS_WATCH_WRITABLE) && - FD_ISSET (fd, &write_set)) - condition |= DBUS_WATCH_WRITABLE; + if ((flags & DBUS_WATCH_WRITABLE) && + FD_ISSET (fd, &write_set)) + condition |= DBUS_WATCH_WRITABLE; - if (FD_ISSET (fd, &err_set)) - condition |= DBUS_WATCH_ERROR; + if (FD_ISSET (fd, &err_set)) + condition |= DBUS_WATCH_ERROR; - if (condition != 0) - { - WatchData *wd; + if (condition != 0) + { + WatchData *wd; - wd = dbus_watch_get_data (watch); + wd = dbus_watch_get_data (watch); - if (wd->type == WATCH_CONNECTION) - { - DBusConnection *connection = wd->data; + if (wd->type == WATCH_CONNECTION) + { + DBusConnection *connection = wd->data; - dbus_connection_handle_watch (connection, + dbus_connection_handle_watch (connection, + watch, + condition); + } + else if (wd->type == WATCH_SERVER) + { + DBusServer *server = wd->data; + + dbus_server_handle_watch (server, watch, condition); - } - else if (wd->type == WATCH_SERVER) - { - DBusServer *server = wd->data; - - dbus_server_handle_watch (server, - watch, - condition); + } } } @@ -345,6 +354,7 @@ setup_connection (DBusConnection *connection) if (!dbus_connection_set_watch_functions (connection, (DBusAddWatchFunction) add_connection_watch, (DBusRemoveWatchFunction) remove_connection_watch, + NULL, connection, NULL)) _dbus_assert_not_reached ("not enough memory"); @@ -359,6 +369,7 @@ setup_server (DBusServer *server) if (!dbus_server_set_watch_functions (server, (DBusAddWatchFunction) add_server_watch, (DBusRemoveWatchFunction) remove_server_watch, + NULL, server, NULL)) _dbus_assert_not_reached ("not enough memory"); -- cgit