From acc9bb24033cdb93be6b9c00012f86ac56904cc9 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 7 Jul 2010 11:02:08 -0400 Subject: [PATCH] GDBus: Only rewrite serial number if g_dbus_message_get_serial() returns 0 While this a dangerous thing to allow (collissions, reply_serial not matching up etc.), the added flexibility makes this a good trade-off - for example, with this feature, it's now a lot easier to build message routers. Signed-off-by: David Zeuthen --- gio/gdbusconnection.c | 27 ++++++++++++++++++++------- gio/tests/gdbus-connection.c | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index e853281e4..9b94d1d95 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -1026,7 +1026,11 @@ g_dbus_connection_send_message_unlocked (GDBusConnection *connection, if (blob == NULL) goto out; - serial_to_use = ++connection->priv->last_serial; /* TODO: handle overflow */ + serial_to_use = g_dbus_message_get_serial (message); + if (serial_to_use == 0) + { + serial_to_use = ++connection->priv->last_serial; /* TODO: handle overflow */ + } switch (blob[0]) { @@ -1079,8 +1083,11 @@ g_dbus_connection_send_message_unlocked (GDBusConnection *connection, * * Asynchronously sends @message to the peer represented by @connection. * - * If @out_serial is not %NULL, then the serial number assigned to - * @message by @connection will be written to this location prior to + * If g_dbus_message_get_serial() returns non-zero for @message, then + * that value is used for the message serial number. Otherwise a + * serial number will be assigned by @connection and set on @message + * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then + * the serial number used will be written to this location prior to * submitting the message to the underlying transport. * * If @connection is closed then the operation will fail with @@ -1392,8 +1399,11 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connect * * Asynchronously sends @message to the peer represented by @connection. * - * If @out_serial is not %NULL, then the serial number assigned to - * @message by @connection will be written to this location prior to + * If g_dbus_message_get_serial() returns non-zero for @message, then + * that value is used for the message serial number. Otherwise a + * serial number will be assigned by @connection and set on @message + * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then + * the serial number used will be written to this location prior to * submitting the message to the underlying transport. * * If @connection is closed then the operation will fail with @@ -1525,8 +1535,11 @@ send_message_with_reply_sync_cb (GDBusConnection *connection, * timeout is reached. See g_dbus_connection_send_message_with_reply() * for the asynchronous version of this method. * - * If @out_serial is not %NULL, then the serial number assigned to - * @message by @connection will be written to this location prior to + * If g_dbus_message_get_serial() returns non-zero for @message, then + * that value is used for the message serial number. Otherwise a + * serial number will be assigned by @connection and set on @message + * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then + * the serial number used will be written to this location prior to * submitting the message to the underlying transport. * * If @connection is closed then the operation will fail with diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c index 01113ee72..3c63caebb 100644 --- a/gio/tests/gdbus-connection.c +++ b/gio/tests/gdbus-connection.c @@ -618,12 +618,14 @@ test_connection_filter (void) while (data.num_handled == 0) g_thread_yield (); + g_dbus_message_set_serial (m, 0); g_dbus_connection_send_message (c, m, &data.serial, &error); g_assert_no_error (error); while (data.num_handled == 1) g_thread_yield (); + g_dbus_message_set_serial (m, 0); r = g_dbus_connection_send_message_with_reply_sync (c, m, -1, @@ -637,6 +639,7 @@ test_connection_filter (void) g_dbus_connection_remove_filter (c, filter_id); + g_dbus_message_set_serial (m, 0); r = g_dbus_connection_send_message_with_reply_sync (c, m, -1,