diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | dbus/dbus-connection-internal.h | 91 | ||||
-rw-r--r-- | dbus/dbus-connection.c | 37 | ||||
-rw-r--r-- | dbus/dbus-message-internal.h | 2 | ||||
-rw-r--r-- | dbus/dbus-message.c | 13 | ||||
-rw-r--r-- | dbus/dbus-transport-unix.c | 17 |
6 files changed, 110 insertions, 63 deletions
@@ -1,5 +1,18 @@ 2003-03-16 Havoc Pennington <hp@pobox.com> + * dbus/dbus-connection.c + (_dbus_connection_queue_received_message_link): new function that + can't fail due to OOM + + * dbus/dbus-message.c (_dbus_message_loader_pop_message_link): + new function pops a message together with a list link + containing it. + + * dbus/dbus-transport-unix.c (queue_messages): use new link-based + message queuing functions to avoid needing to alloc memory + +2003-03-16 Havoc Pennington <hp@pobox.com> + Oops - test code was only testing failure of around 30 of the mallocs in the test path, but it turns out there are 500+ mallocs. I believe this was due to misguided linking setup such diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 4d3ed130..f2714798 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -28,6 +28,7 @@ #include <dbus/dbus-message.h> #include <dbus/dbus-transport.h> #include <dbus/dbus-resources.h> +#include <dbus/dbus-list.h> DBUS_BEGIN_DECLS; @@ -37,56 +38,48 @@ typedef enum DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */ DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */ } DBusIterationFlags; +void _dbus_connection_lock (DBusConnection *connection); +void _dbus_connection_unlock (DBusConnection *connection); +void _dbus_connection_ref_unlocked (DBusConnection *connection); +dbus_bool_t _dbus_connection_queue_received_message (DBusConnection *connection, + DBusMessage *message); +void _dbus_connection_queue_received_message_link (DBusConnection *connection, + DBusList *link); +dbus_bool_t _dbus_connection_have_messages_to_send (DBusConnection *connection); +DBusMessage* _dbus_connection_get_message_to_send (DBusConnection *connection); +void _dbus_connection_message_sent (DBusConnection *connection, + DBusMessage *message); +dbus_bool_t _dbus_connection_add_watch (DBusConnection *connection, + DBusWatch *watch); +void _dbus_connection_remove_watch (DBusConnection *connection, + DBusWatch *watch); +void _dbus_connection_toggle_watch (DBusConnection *connection, + DBusWatch *watch, + dbus_bool_t enabled); +dbus_bool_t _dbus_connection_add_timeout (DBusConnection *connection, + DBusTimeout *timeout); +void _dbus_connection_remove_timeout (DBusConnection *connection, + DBusTimeout *timeout); +void _dbus_connection_toggle_timeout (DBusConnection *connection, + DBusTimeout *timeout, + dbus_bool_t enabled); +DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport); +void _dbus_connection_do_iteration (DBusConnection *connection, + unsigned int flags, + int timeout_milliseconds); +void _dbus_connection_notify_disconnected (DBusConnection *connection); +void _dbus_connection_handler_destroyed_locked (DBusConnection *connection, + DBusMessageHandler *handler); +void _dbus_connection_set_connection_counter (DBusConnection *connection, + DBusCounter *counter); +dbus_bool_t _dbus_message_handler_add_connection (DBusMessageHandler *handler, + DBusConnection *connection); +void _dbus_message_handler_remove_connection (DBusMessageHandler *handler, + DBusConnection *connection); +DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandler *handler, + DBusConnection *connection, + DBusMessage *message); -void _dbus_connection_lock (DBusConnection *connection); -void _dbus_connection_unlock (DBusConnection *connection); - -void _dbus_connection_ref_unlocked (DBusConnection *connection); - -dbus_bool_t _dbus_connection_queue_received_message (DBusConnection *connection, - DBusMessage *message); -dbus_bool_t _dbus_connection_have_messages_to_send (DBusConnection *connection); - -DBusMessage* _dbus_connection_get_message_to_send (DBusConnection *connection); -void _dbus_connection_message_sent (DBusConnection *connection, - DBusMessage *message); - -dbus_bool_t _dbus_connection_add_watch (DBusConnection *connection, - DBusWatch *watch); -void _dbus_connection_remove_watch (DBusConnection *connection, - DBusWatch *watch); -void _dbus_connection_toggle_watch (DBusConnection *connection, - DBusWatch *watch, - dbus_bool_t enabled); -dbus_bool_t _dbus_connection_add_timeout (DBusConnection *connection, - DBusTimeout *timeout); -void _dbus_connection_remove_timeout (DBusConnection *connection, - DBusTimeout *timeout); -void _dbus_connection_toggle_timeout (DBusConnection *connection, - DBusTimeout *timeout, - dbus_bool_t enabled); -DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport); - -void _dbus_connection_do_iteration (DBusConnection *connection, - unsigned int flags, - int timeout_milliseconds); - -void _dbus_connection_notify_disconnected (DBusConnection *connection); - -void _dbus_connection_handler_destroyed_locked (DBusConnection *connection, - DBusMessageHandler *handler); - - -void _dbus_connection_set_connection_counter (DBusConnection *connection, - DBusCounter *counter); - -dbus_bool_t _dbus_message_handler_add_connection (DBusMessageHandler *handler, - DBusConnection *connection); -void _dbus_message_handler_remove_connection (DBusMessageHandler *handler, - DBusConnection *connection); -DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandler *handler, - DBusConnection *connection, - DBusMessage *message); diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 6f02d258..35ffca0c 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -168,6 +168,7 @@ _dbus_connection_wakeup_mainloop (DBusConnection *connection) /** * Adds a message to the incoming message queue, returning #FALSE * if there's insufficient memory to queue the message. + * Does not take over refcount of the message. * * @param connection the connection. * @param message the message to queue. @@ -177,15 +178,40 @@ dbus_bool_t _dbus_connection_queue_received_message (DBusConnection *connection, DBusMessage *message) { + DBusList *link; + + link = _dbus_list_alloc_link (message); + if (link == NULL) + return FALSE; + + dbus_message_ref (message); + _dbus_connection_queue_received_message_link (connection, link); + + return TRUE; +} + +/** + * Adds a message-containing list link to the incoming message queue, + * taking ownership of the link and the message's current refcount. + * Cannot fail due to lack of memory. + * + * @param connection the connection. + * @param link the message link to queue. + */ +void +_dbus_connection_queue_received_message_link (DBusConnection *connection, + DBusList *link) +{ ReplyHandlerData *reply_handler_data; dbus_int32_t reply_serial; + DBusMessage *message; _dbus_assert (_dbus_transport_get_is_authenticated (connection->transport)); - if (!_dbus_list_append (&connection->incoming_messages, - message)) - return FALSE; - + _dbus_list_append_link (&connection->incoming_messages, + link); + message = link->data; + /* If this is a reply we're waiting on, remove timeout for it */ reply_serial = dbus_message_get_reply_serial (message); if (reply_serial != -1) @@ -201,7 +227,6 @@ _dbus_connection_queue_received_message (DBusConnection *connection, } } - dbus_message_ref (message); connection->n_incoming += 1; _dbus_connection_wakeup_mainloop (connection); @@ -211,8 +236,6 @@ _dbus_connection_queue_received_message (DBusConnection *connection, message, dbus_message_get_name (message), connection, connection->n_incoming); - - return TRUE; } /** diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h index 86796da9..9c4ee64b 100644 --- a/dbus/dbus-message-internal.h +++ b/dbus/dbus-message-internal.h @@ -25,6 +25,7 @@ #include <dbus/dbus-message.h> #include <dbus/dbus-resources.h> +#include <dbus/dbus-list.h> DBUS_BEGIN_DECLS; @@ -52,6 +53,7 @@ void _dbus_message_loader_return_buffer (DBusMessageLoader int bytes_read); DBusMessage* _dbus_message_loader_pop_message (DBusMessageLoader *loader); +DBusList* _dbus_message_loader_pop_message_link (DBusMessageLoader *loader); dbus_bool_t _dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader); diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index fe032dff..7d425772 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -2908,6 +2908,19 @@ _dbus_message_loader_pop_message (DBusMessageLoader *loader) return _dbus_list_pop_first (&loader->messages); } +/** + * Pops a loaded message inside a list link (passing ownership of the + * message and link to the caller). Returns #NULL if no messages have + * been loaded. + * + * @param loader the loader. + * @returns the next message link, or #NULL if none. + */ +DBusList* +_dbus_message_loader_pop_message_link (DBusMessageLoader *loader) +{ + return _dbus_list_pop_first_link (&loader->messages); +} /** * Checks whether the loader is confused due to bad data. diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index 17d74886..ed68658b 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -181,19 +181,22 @@ do_io_error (DBusTransport *transport) static void queue_messages (DBusTransport *transport) { - DBusMessage *message; + DBusList *link; /* Queue any messages */ - while ((message = _dbus_message_loader_pop_message (transport->loader))) + while ((link = _dbus_message_loader_pop_message_link (transport->loader))) { + DBusMessage *message; + + message = link->data; + _dbus_verbose ("queueing received message %p\n", message); _dbus_message_add_size_counter (message, transport->live_messages_size); - if (!_dbus_connection_queue_received_message (transport->connection, - message)) - /* FIXME woops! */; - - dbus_message_unref (message); + + /* pass ownership of link and message ref to connection */ + _dbus_connection_queue_received_message_link (transport->connection, + link); } if (_dbus_message_loader_get_is_corrupted (transport->loader)) |