+ dbus_mutex_unlock (connection->mutex);
+}
+
+static DBusDataSlotAllocator slot_allocator;
+_DBUS_DEFINE_GLOBAL_LOCK (connection_slots);
+
+/**
+ * Allocates an integer ID to be used for storing application-specific
+ * data on any DBusConnection. The allocated ID may then be used
+ * with dbus_connection_set_data() and dbus_connection_get_data().
+ * If allocation fails, -1 is returned. Again, the allocated
+ * slot is global, i.e. all DBusConnection objects will
+ * have a slot with the given integer ID reserved.
+ *
+ * @returns -1 on failure, otherwise the data slot ID
+ */
+int
+dbus_connection_allocate_data_slot (void)
+{
+ return _dbus_data_slot_allocator_alloc (&slot_allocator,
+ _DBUS_LOCK_NAME (connection_slots));
+}
+
+/**
+ * Deallocates a global ID for connection data slots.
+ * dbus_connection_get_data() and dbus_connection_set_data()
+ * may no longer be used with this slot.
+ * Existing data stored on existing DBusConnection objects
+ * will be freed when the connection is finalized,
+ * but may not be retrieved (and may only be replaced
+ * if someone else reallocates the slot).
+ *
+ * @param slot the slot to deallocate
+ */
+void
+dbus_connection_free_data_slot (int slot)
+{
+ _dbus_data_slot_allocator_free (&slot_allocator, slot);
+}
+
+/**
+ * Stores a pointer on a DBusConnection, along
+ * with an optional function to be used for freeing
+ * the data when the data is set again, or when
+ * the connection is finalized. The slot number
+ * must have been allocated with dbus_connection_allocate_data_slot().
+ *
+ * @param connection the connection
+ * @param slot the slot number
+ * @param data the data to store
+ * @param free_data_func finalizer function for the data
+ * @returns #TRUE if there was enough memory to store the data
+ */
+dbus_bool_t
+dbus_connection_set_data (DBusConnection *connection,
+ int slot,
+ void *data,
+ DBusFreeFunction free_data_func)
+{
+ DBusFreeFunction old_free_func;
+ void *old_data;
+ dbus_bool_t retval;
+
+ _dbus_return_val_if_fail (connection != NULL, FALSE);
+ _dbus_return_val_if_fail (slot >= 0, FALSE);
+
+ dbus_mutex_lock (connection->mutex);
+
+ retval = _dbus_data_slot_list_set (&slot_allocator,
+ &connection->slot_list,
+ slot, data, free_data_func,
+ &old_free_func, &old_data);
+
+ dbus_mutex_unlock (connection->mutex);
+
+ if (retval)
+ {
+ /* Do the actual free outside the connection lock */
+ if (old_free_func)
+ (* old_free_func) (old_data);
+ }
+
+ return retval;
+}
+
+/**
+ * Retrieves data previously set with dbus_connection_set_data().
+ * The slot must still be allocated (must not have been freed).
+ *
+ * @param connection the connection
+ * @param slot the slot to get data from
+ * @returns the data, or #NULL if not found
+ */
+void*
+dbus_connection_get_data (DBusConnection *connection,
+ int slot)
+{
+ void *res;
+
+ _dbus_return_val_if_fail (connection != NULL, NULL);
+
+ dbus_mutex_lock (connection->mutex);
+
+ res = _dbus_data_slot_list_get (&slot_allocator,
+ &connection->slot_list,
+ slot);
+
+ dbus_mutex_unlock (connection->mutex);
+
+ return res;
+}
+
+/**
+ * This function sets a global flag for whether dbus_connection_new()
+ * will set SIGPIPE behavior to SIG_IGN.
+ *
+ * @param will_modify_sigpipe #TRUE to allow sigpipe to be set to SIG_IGN
+ */
+void
+dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe)
+{
+ _dbus_modify_sigpipe = will_modify_sigpipe != FALSE;
+}
+
+/**
+ * Specifies the maximum size message this connection is allowed to
+ * receive. Larger messages will result in disconnecting the
+ * connection.
+ *
+ * @param connection a #DBusConnection
+ * @param size maximum message size the connection can receive, in bytes
+ */
+void
+dbus_connection_set_max_message_size (DBusConnection *connection,
+ long size)
+{
+ _dbus_return_if_fail (connection != NULL);
+
+ dbus_mutex_lock (connection->mutex);
+ _dbus_transport_set_max_message_size (connection->transport,
+ size);
+ dbus_mutex_unlock (connection->mutex);
+}
+
+/**
+ * Gets the value set by dbus_connection_set_max_message_size().
+ *
+ * @param connection the connection
+ * @returns the max size of a single message
+ */
+long
+dbus_connection_get_max_message_size (DBusConnection *connection)
+{
+ long res;
+
+ _dbus_return_val_if_fail (connection != NULL, 0);
+
+ dbus_mutex_lock (connection->mutex);
+ res = _dbus_transport_get_max_message_size (connection->transport);
+ dbus_mutex_unlock (connection->mutex);
+ return res;
+}
+
+/**
+ * Sets the maximum total number of bytes that can be used for all messages
+ * received on this connection. Messages count toward the maximum until
+ * they are finalized. When the maximum is reached, the connection will
+ * not read more data until some messages are finalized.
+ *
+ * The semantics of the maximum are: if outstanding messages are
+ * already above the maximum, additional messages will not be read.
+ * The semantics are not: if the next message would cause us to exceed
+ * the maximum, we don't read it. The reason is that we don't know the
+ * size of a message until after we read it.
+ *
+ * Thus, the max live messages size can actually be exceeded
+ * by up to the maximum size of a single message.
+ *
+ * Also, if we read say 1024 bytes off the wire in a single read(),
+ * and that contains a half-dozen small messages, we may exceed the
+ * size max by that amount. But this should be inconsequential.
+ *
+ * This does imply that we can't call read() with a buffer larger
+ * than we're willing to exceed this limit by.
+ *
+ * @param connection the connection
+ * @param size the maximum size in bytes of all outstanding messages
+ */
+void
+dbus_connection_set_max_received_size (DBusConnection *connection,
+ long size)
+{
+ _dbus_return_if_fail (connection != NULL);
+
+ dbus_mutex_lock (connection->mutex);
+ _dbus_transport_set_max_received_size (connection->transport,
+ size);
+ dbus_mutex_unlock (connection->mutex);
+}
+
+/**
+ * Gets the value set by dbus_connection_set_max_received_size().
+ *
+ * @param connection the connection
+ * @returns the max size of all live messages
+ */
+long
+dbus_connection_get_max_received_size (DBusConnection *connection)
+{
+ long res;
+
+ _dbus_return_val_if_fail (connection != NULL, 0);
+
+ dbus_mutex_lock (connection->mutex);
+ res = _dbus_transport_get_max_received_size (connection->transport);
+ dbus_mutex_unlock (connection->mutex);
+ return res;
+}
+
+/**
+ * Gets the approximate size in bytes of all messages in the outgoing
+ * message queue. The size is approximate in that you shouldn't use
+ * it to decide how many bytes to read off the network or anything
+ * of that nature, as optimizations may choose to tell small white lies
+ * to avoid performance overhead.
+ *
+ * @param connection the connection
+ * @returns the number of bytes that have been queued up but not sent
+ */
+long
+dbus_connection_get_outgoing_size (DBusConnection *connection)
+{
+ long res;
+
+ _dbus_return_val_if_fail (connection != NULL, 0);
+
+ dbus_mutex_lock (connection->mutex);
+ res = _dbus_counter_get_value (connection->outgoing_counter);
+ dbus_mutex_unlock (connection->mutex);
+ return res;