From 4d985d98906577e3344fc1107d341b8ac969db1e Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 30 Jan 2005 20:06:52 +0000 Subject: 2005-01-30 Havoc Pennington * glib/dbus-gmain.c: add a custom GSource back that just checks whether the message queue has anything in it; otherwise, there are cases where we won't see messages in the queue since there was no IO visible to the glib main loop * dbus/dbus-connection-internal.h (_DBUS_DEFAULT_TIMEOUT_VALUE): increase default message timeout to 25 seconds --- ChangeLog | 10 +++++ dbus/dbus-connection-internal.h | 4 +- glib/dbus-gmain.c | 93 +++++++++++++++++++++++++++++++++++++---- test/glib/test-service-glib.c | 10 +++-- 4 files changed, 104 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4eed51df..db61a286 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-01-30 Havoc Pennington + + * glib/dbus-gmain.c: add a custom GSource back that just checks + whether the message queue has anything in it; otherwise, there are + cases where we won't see messages in the queue since there was no + IO visible to the glib main loop + + * dbus/dbus-connection-internal.h (_DBUS_DEFAULT_TIMEOUT_VALUE): + increase default message timeout to 25 seconds + 2005-01-30 Havoc Pennington * test/glib/test-profile.c (no_bus_stop_server): remove the diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 14184ad2..6800fefe 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -41,8 +41,8 @@ typedef enum DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */ } DBusIterationFlags; -/** default timeout value when waiting for a message reply */ -#define _DBUS_DEFAULT_TIMEOUT_VALUE (15 * 1000) +/** default timeout value when waiting for a message reply, 25 seconds */ +#define _DBUS_DEFAULT_TIMEOUT_VALUE (25 * 1000) void _dbus_connection_lock (DBusConnection *connection); void _dbus_connection_unlock (DBusConnection *connection); diff --git a/glib/dbus-gmain.c b/glib/dbus-gmain.c index c3a9f10a..63e1d79e 100644 --- a/glib/dbus-gmain.c +++ b/glib/dbus-gmain.c @@ -53,12 +53,72 @@ * @{ */ +/** + * A GSource subclass for dispatching DBusConnection messages. + * We need this on top of the IO handlers, because sometimes + * there are messages to dispatch queued up but no IO pending. + */ +typedef struct +{ + GSource source; /**< the parent GSource */ + DBusConnection *connection; /**< the connection to dispatch */ +} DBusGMessageQueue; + +static gboolean message_queue_prepare (GSource *source, + gint *timeout); +static gboolean message_queue_check (GSource *source); +static gboolean message_queue_dispatch (GSource *source, + GSourceFunc callback, + gpointer user_data); + +static GSourceFuncs message_queue_funcs = { + message_queue_prepare, + message_queue_check, + message_queue_dispatch, + NULL +}; + +static gboolean +message_queue_prepare (GSource *source, + gint *timeout) +{ + DBusConnection *connection = ((DBusGMessageQueue *)source)->connection; + + *timeout = -1; + + return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS); +} + +static gboolean +message_queue_check (GSource *source) +{ + return FALSE; +} + +static gboolean +message_queue_dispatch (GSource *source, + GSourceFunc callback, + gpointer user_data) +{ + DBusConnection *connection = ((DBusGMessageQueue *)source)->connection; + + dbus_connection_ref (connection); + + while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS) + ; + + dbus_connection_unref (connection); + + return TRUE; +} + typedef struct { GMainContext *context; /**< the main context */ GSList *ios; /**< all IOHandler */ GSList *timeouts; /**< all TimeoutHandler */ DBusConnection *connection; /**< NULL if this is really for a server not a connection */ + GSource *message_queue_source; /**< DBusGMessageQueue */ } ConnectionSetup; @@ -80,7 +140,8 @@ static dbus_int32_t connection_slot = -1; static dbus_int32_t server_slot = -1; static ConnectionSetup* -connection_setup_new (GMainContext *context) +connection_setup_new (GMainContext *context, + DBusConnection *connection) { ConnectionSetup *cs; @@ -89,7 +150,17 @@ connection_setup_new (GMainContext *context) g_assert (context != NULL); cs->context = context; - g_main_context_ref (cs->context); + g_main_context_ref (cs->context); + + if (connection) + { + cs->connection = connection; + + cs->message_queue_source = g_source_new (&message_queue_funcs, + sizeof (DBusGMessageQueue)); + ((DBusGMessageQueue*)cs->message_queue_source)->connection = connection; + g_source_attach (cs->message_queue_source, cs->context); + } return cs; } @@ -333,6 +404,16 @@ connection_setup_free (ConnectionSetup *cs) while (cs->timeouts) timeout_handler_destroy_source (cs->timeouts->data); + + if (cs->message_queue_source) + { + GSource *source; + + source = cs->message_queue_source; + cs->message_queue_source = NULL; + + g_source_destroy (source); + } g_main_context_unref (cs->context); g_free (cs); @@ -434,7 +515,7 @@ connection_setup_new_from_old (GMainContext *context, g_assert (old->context != context); - cs = connection_setup_new (context); + cs = connection_setup_new (context, old->connection); tmp = old->ios; while (tmp != NULL) @@ -512,13 +593,11 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, } if (cs == NULL) - cs = connection_setup_new (context); + cs = connection_setup_new (context, connection); if (!dbus_connection_set_data (connection, connection_slot, cs, (DBusFreeFunction)connection_setup_free)) goto nomem; - - cs->connection = connection; if (!dbus_connection_set_watch_functions (connection, add_watch, @@ -590,7 +669,7 @@ dbus_server_setup_with_g_main (DBusServer *server, } if (cs == NULL) - cs = connection_setup_new (context); + cs = connection_setup_new (context, NULL); if (!dbus_server_set_data (server, server_slot, cs, (DBusFreeFunction)connection_setup_free)) diff --git a/test/glib/test-service-glib.c b/test/glib/test-service-glib.c index 413bcc20..2fa3095c 100644 --- a/test/glib/test-service-glib.c +++ b/test/glib/test-service-glib.c @@ -128,8 +128,10 @@ main (int argc, char **argv) DBusGPendingCall *call; const char *v_STRING; guint32 v_UINT32; - + g_type_init (); + + g_printerr ("Launching test-service-glib\n"); loop = g_main_loop_new (NULL, FALSE); @@ -182,12 +184,12 @@ main (int argc, char **argv) exit (1); } - g_print ("GLib test service has name '%s'\n", v_STRING); - g_print ("GLib test service entering main loop\n"); + g_printerr ("GLib test service has name '%s'\n", v_STRING); + g_printerr ("GLib test service entering main loop\n"); g_main_loop_run (loop); - g_print ("Successfully completed %s\n", argv[0]); + g_printerr ("Successfully completed %s\n", argv[0]); return 0; } -- cgit