GDBusMessage: Don't reset serial number when copying

Ryan pointed out that it's safe to do this because we have the
G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag and that it simplifies
how filter functions work.

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen 2010-09-09 15:15:13 -04:00
parent a51df8cefb
commit 7c66068544
4 changed files with 9 additions and 14 deletions

View File

@ -528,12 +528,12 @@ void g_dbus_connection_signal_unsubscribe (GDBusConnection
* return copy; * return copy;
* } * }
* ]| * ]|
* If the returned #GDBusMessage is different from @message and the * If the returned #GDBusMessage is different from @message and cannot
* serial number is unset (e.g. zero), then @message's serial number * be sent on @connection (it could use features, such as file
* will be used on the returned message (so in this case the returned * descriptors, not compatible with @connection), then a warning is
* message must be unlocked). Additionally, if the returned message * logged to <emphasis>standard error</emphasis>. Applications can
* cannot be sent on @connection, then a warning is logged to * check this ahead of time using g_dbus_message_to_blob() passing a
* <emphasis>standard error</emphasis>. * #GDBusCapabilityFlags value obtained from @connection.
* *
* Returns: (transfer full) (allow-none): A #GDBusMessage that will be freed with * Returns: (transfer full) (allow-none): A #GDBusMessage that will be freed with
* g_object_unref() or %NULL to drop the message. Passive filter * g_object_unref() or %NULL to drop the message. Passive filter

View File

@ -3190,7 +3190,7 @@ g_dbus_message_lock (GDBusMessage *message)
* *
* Copies @message. The copy is a deep copy and the returned * Copies @message. The copy is a deep copy and the returned
* #GDBusMessage is completely identical except that it is guaranteed * #GDBusMessage is completely identical except that it is guaranteed
* to not be locked and the serial will be set to 0. * to not be locked.
* *
* This operation can fail if e.g. @message contains file descriptors * This operation can fail if e.g. @message contains file descriptors
* and the per-process or system-wide open files limit is reached. * and the per-process or system-wide open files limit is reached.
@ -3217,6 +3217,7 @@ g_dbus_message_copy (GDBusMessage *message,
ret->flags = message->flags; ret->flags = message->flags;
ret->byte_order = message->byte_order; ret->byte_order = message->byte_order;
ret->major_protocol_version = message->major_protocol_version; ret->major_protocol_version = message->major_protocol_version;
ret->serial = message->serial;
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
if (message->fd_list != NULL) if (message->fd_list != NULL)

View File

@ -1244,14 +1244,12 @@ maybe_write_next_message (GDBusWorker *worker)
*/ */
if (data != NULL) if (data != NULL)
{ {
guint32 old_serial;
GDBusMessage *old_message; GDBusMessage *old_message;
guchar *new_blob; guchar *new_blob;
gsize new_blob_size; gsize new_blob_size;
GError *error; GError *error;
old_message = data->message; old_message = data->message;
old_serial = g_dbus_message_get_serial (old_message);
data->message = _g_dbus_worker_emit_message_about_to_be_sent (worker, data->message); data->message = _g_dbus_worker_emit_message_about_to_be_sent (worker, data->message);
if (data->message == old_message) if (data->message == old_message)
{ {
@ -1269,10 +1267,6 @@ maybe_write_next_message (GDBusWorker *worker)
else else
{ {
/* filters altered the message -> reencode */ /* filters altered the message -> reencode */
if (g_dbus_message_get_serial (data->message) == 0)
g_dbus_message_set_serial (data->message, old_serial);
error = NULL; error = NULL;
new_blob = g_dbus_message_to_blob (data->message, new_blob = g_dbus_message_to_blob (data->message,
&new_blob_size, &new_blob_size,

View File

@ -108,7 +108,7 @@ message_copy (void)
g_assert_cmpint (G_OBJECT (m)->ref_count, ==, 1); g_assert_cmpint (G_OBJECT (m)->ref_count, ==, 1);
g_assert_cmpint (G_OBJECT (copy)->ref_count, ==, 1); g_assert_cmpint (G_OBJECT (copy)->ref_count, ==, 1);
g_assert_cmpint (g_dbus_message_get_serial (copy), ==, 0); g_assert_cmpint (g_dbus_message_get_serial (copy), ==, g_dbus_message_get_serial (m));
g_assert_cmpint (g_dbus_message_get_byte_order (copy), ==, g_dbus_message_get_byte_order (m)); g_assert_cmpint (g_dbus_message_get_byte_order (copy), ==, g_dbus_message_get_byte_order (m));
g_assert_cmpint (g_dbus_message_get_flags (copy), ==, g_dbus_message_get_flags (m)); g_assert_cmpint (g_dbus_message_get_flags (copy), ==, g_dbus_message_get_flags (m));
g_assert_cmpint (g_dbus_message_get_message_type (copy), ==, g_dbus_message_get_message_type (m)); g_assert_cmpint (g_dbus_message_get_message_type (copy), ==, g_dbus_message_get_message_type (m));