From ff5283ab92c668453fd2f28c1715a1e0e9b949f5 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 27 Dec 2002 00:44:41 +0000 Subject: 2002-12-26 Havoc Pennington * dbus/dbus-marshal.h (DBUS_COMPILER_BYTE_ORDER): #ifdef WORDS_BIGENDIAN then compiler byte order is DBUS_BIG_ENDIAN, doh * dbus/dbus-marshal.c: Add macros to do int swapping in-place and avoid swap_bytes() overhead (ignoring possible assembly stuff for now). Main point is because I wanted unpack_uint32 to implement _dbus_verbose_bytes (_dbus_verbose_bytes): new function * dbus/dbus-string.c (_dbus_string_validate_ascii): new function * dbus/dbus-message.c (_dbus_message_loader_get_is_corrupted): add mechanism to handle a corrupt message stream (_dbus_message_loader_new): fix preallocation to only prealloc, not prelengthen * dbus/dbus-string.c (_dbus_string_skip_blank): fix this function (_dbus_string_test): enhance tests for copy/move and fix the functions * dbus/dbus-transport-unix.c: Hold references in more places to avoid reentrancy problems * dbus/dbus-transport.c: ditto * dbus/dbus-connection.c (dbus_connection_dispatch_message): don't leak reference count in no-message case * test/watch.c (do_mainloop): handle adding/removing watches during iteration over the watches. Also, ref the connection/server stored on a watch, so we don't try to mangle a destroyed one. * dbus/dbus-transport-unix.c (do_authentication): perform authentication * dbus/dbus-auth.c (get_state): add a state AUTHENTICATED_WITH_UNUSED_BYTES and return it if required (_dbus_auth_get_unused_bytes): append the unused bytes to the passed in string, rather than prepend * dbus/dbus-transport.c (_dbus_transport_init_base): create the auth conversation DBusAuth * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd) (_dbus_transport_new_for_domain_socket): when creating a transport, pass in whether it's a client-side or server-side transport so we know which DBusAuth to create --- dbus/dbus-connection.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'dbus/dbus-connection.c') diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 4a40f0b0..e5fa48f0 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -94,13 +94,18 @@ dbus_bool_t _dbus_connection_queue_received_message (DBusConnection *connection, DBusMessage *message) { + _dbus_assert (_dbus_transport_get_is_authenticated (connection->transport)); + if (!_dbus_list_append (&connection->incoming_messages, message)) return FALSE; - + dbus_message_ref (message); connection->n_incoming += 1; + _dbus_verbose ("Incoming message %p added to queue, %d incoming\n", + message, connection->n_incoming); + return TRUE; } @@ -140,11 +145,17 @@ void _dbus_connection_message_sent (DBusConnection *connection, DBusMessage *message) { + _dbus_assert (_dbus_transport_get_is_authenticated (connection->transport)); _dbus_assert (message == _dbus_list_get_last (&connection->outgoing_messages)); + _dbus_list_pop_last (&connection->outgoing_messages); dbus_message_unref (message); connection->n_outgoing -= 1; + + _dbus_verbose ("Message %p removed from outgoing queue, %d left to send\n", + message, connection->n_outgoing); + if (connection->n_outgoing == 0) _dbus_transport_messages_pending (connection->transport, connection->n_outgoing); @@ -164,10 +175,11 @@ dbus_bool_t _dbus_connection_add_watch (DBusConnection *connection, DBusWatch *watch) { - return _dbus_watch_list_add_watch (connection->watches, - watch); - - return TRUE; + if (connection->watches) /* null during finalize */ + return _dbus_watch_list_add_watch (connection->watches, + watch); + else + return FALSE; } /** @@ -182,8 +194,9 @@ void _dbus_connection_remove_watch (DBusConnection *connection, DBusWatch *watch) { - _dbus_watch_list_remove_watch (connection->watches, - watch); + if (connection->watches) /* null during finalize */ + _dbus_watch_list_remove_watch (connection->watches, + watch); } static void @@ -442,7 +455,8 @@ dbus_connection_unref (DBusConnection *connection) NULL, NULL, NULL); _dbus_watch_list_free (connection->watches); - + connection->watches = NULL; + _dbus_hash_iter_init (connection->handler_table, &iter); while (_dbus_hash_iter_next (&iter)) { @@ -545,6 +559,9 @@ dbus_connection_send_message (DBusConnection *connection, dbus_message_ref (message); connection->n_outgoing += 1; + _dbus_verbose ("Message %p added to outgoing queue, %d pending to send\n", + message, connection->n_outgoing); + _dbus_message_lock (message); if (connection->n_outgoing == 1) @@ -668,8 +685,15 @@ dbus_connection_pop_message (DBusConnection *connection) { if (connection->n_incoming > 0) { + DBusMessage *message; + + message = _dbus_list_pop_first (&connection->incoming_messages); connection->n_incoming -= 1; - return _dbus_list_pop_first (&connection->incoming_messages); + + _dbus_verbose ("Incoming message %p removed from queue, %d incoming\n", + message, connection->n_incoming); + + return message; } else return NULL; @@ -700,7 +724,10 @@ dbus_connection_dispatch_message (DBusConnection *connection) message = dbus_connection_pop_message (connection); if (message == NULL) - return FALSE; + { + dbus_connection_unref (connection); + return FALSE; + } filter_serial = connection->filters_serial; handler_serial = connection->handlers_serial; -- cgit