summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2006-07-14 03:09:22 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2006-07-14 03:09:22 +0000
commit5efe8e7f1d97931710558495a951e0b35afbfb72 (patch)
tree2fbb5d61947f61616c3f9ef6e5b51b0439133b0a
parent7628b541258d906e27e2000a402ed2d02383479c (diff)
* dbus-connection.c (dbus_connection_send_with_reply): return TRUE
and set pending_reply out arg to NULL is connection is disconnected (connection_timeout_and_complete_all_pending_calls_unlocked): New static method for cleaning up pending calls on disconnect (_dbus_connection_get_dispatch_status_unlocked): If we have pending calls queued timeouts on disconnect * dbus/dbus-pending-call.ci (_dbus_pending_call_set_connection): Remove
-rw-r--r--ChangeLog12
-rw-r--r--dbus/dbus-connection.c63
-rw-r--r--dbus/dbus-pending-call-internal.h2
-rw-r--r--dbus/dbus-pending-call.c38
4 files changed, 73 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index d9f45113..28b77ffa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-07-13 John (J5) Palmieri <johnp@redhat.com>
+
+ * dbus-connection.c (dbus_connection_send_with_reply): return TRUE
+ and set pending_reply out arg to NULL is connection is disconnected
+ (connection_timeout_and_complete_all_pending_calls_unlocked): New
+ static method for cleaning up pending calls on disconnect
+ (_dbus_connection_get_dispatch_status_unlocked): If we have pending
+ calls queued timeouts on disconnect
+
+ * dbus/dbus-pending-call.ci (_dbus_pending_call_set_connection):
+ Remove
+
2006-07-13 Carlos Garcia Campos <carlosgc@gnome.org>
* bus/activation.[ch] (bus_activation_list_services): new function to
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 169b474e..fd80ac11 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -386,6 +386,8 @@ _dbus_connection_queue_received_message_link (DBusConnection *connection,
}
}
+
+
connection->n_incoming += 1;
_dbus_connection_wakeup_mainloop (connection);
@@ -832,7 +834,6 @@ free_pending_call_on_hash_removal (void *data)
_dbus_pending_call_set_timeout_added (pending, FALSE);
}
- _dbus_pending_call_clear_connection (pending);
dbus_pending_call_unref (pending);
}
}
@@ -2359,9 +2360,9 @@ reply_handler_timeout (void *data)
*
* @param connection the connection
* @param message the message to send
- * @param pending_return return location for a #DBusPendingCall object, or #NULL
+ * @param pending_return return location for a #DBusPendingCall object, or #NULLif connection is disconnected
* @param timeout_milliseconds timeout in milliseconds or -1 for default
- * @returns #TRUE if the message is successfully queued, #FALSE if no memory.
+ * @returns #FALSE if no memory, #TRUE otherwise.
*
*/
dbus_bool_t
@@ -2380,16 +2381,28 @@ dbus_connection_send_with_reply (DBusConnection *connection,
if (pending_return)
*pending_return = NULL;
-
+
+ CONNECTION_LOCK (connection);
+
+ if (!_dbus_connection_get_is_connected_unlocked (connection))
+ {
+ CONNECTION_UNLOCK (connection);
+
+ *pending_return = NULL;
+
+ return TRUE;
+ }
+
pending = _dbus_pending_call_new (connection,
timeout_milliseconds,
reply_handler_timeout);
if (pending == NULL)
- return FALSE;
+ {
+ CONNECTION_UNLOCK (connection);
+ return FALSE;
+ }
- CONNECTION_LOCK (connection);
-
/* Assign a serial to the message */
serial = dbus_message_get_serial (message);
if (serial == 0)
@@ -2469,6 +2482,33 @@ check_for_reply_unlocked (DBusConnection *connection,
}
static void
+connection_timeout_and_complete_all_pending_calls_unlocked (DBusConnection *connection)
+{
+ DBusHashIter iter;
+
+ _dbus_hash_iter_init (connection->pending_replies, &iter);
+
+ /* create list while we remove the iters from the hash
+ because we need to go over it a couple of times */
+ while (_dbus_hash_iter_next (&iter))
+ {
+ DBusPendingCall *pending;
+
+ pending = (DBusPendingCall *) _dbus_hash_iter_get_value (&iter);
+ dbus_pending_call_ref (pending);
+
+ _dbus_pending_call_queue_timeout_error (pending,
+ connection);
+ _dbus_connection_remove_timeout_unlocked (connection,
+ _dbus_pending_call_get_timeout (pending));
+
+ _dbus_hash_iter_remove_entry (&iter);
+
+ dbus_pending_call_unref (pending);
+ }
+}
+
+static void
complete_pending_call_and_unlock (DBusPendingCall *pending,
DBusMessage *message)
{
@@ -3300,7 +3340,10 @@ _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection)
_DBUS_FUNCTION_NAME);
connection_forget_shared_unlocked (connection);
-
+
+ /* If we have pending calls queued timeouts on disconnect */
+ connection_timeout_and_complete_all_pending_calls_unlocked (connection);
+
/* We haven't sent the disconnect message already,
* and all real messages have been queued up.
*/
@@ -3734,10 +3777,12 @@ dbus_connection_dispatch (DBusConnection *connection)
"Disconnected"))
{
_dbus_bus_check_connection_and_unref (connection);
+
if (connection->exit_on_disconnect)
{
+ CONNECTION_UNLOCK (connection);
+
_dbus_verbose ("Exiting on Disconnected signal\n");
- CONNECTION_UNLOCK (connection);
_dbus_exit (1);
_dbus_assert_not_reached ("Call to exit() returned");
}
diff --git a/dbus/dbus-pending-call-internal.h b/dbus/dbus-pending-call-internal.h
index 21475e24..0a5aa25c 100644
--- a/dbus/dbus-pending-call-internal.h
+++ b/dbus/dbus-pending-call-internal.h
@@ -39,8 +39,6 @@ dbus_uint32_t _dbus_pending_call_get_reply_serial (DBusPendingCall *pending)
void _dbus_pending_call_set_reply_serial (DBusPendingCall *pending,
dbus_uint32_t serial);
DBusConnection *_dbus_pending_call_get_connection (DBusPendingCall *pending);
-void _dbus_pending_call_set_connection (DBusPendingCall *pending,
- DBusConnection *connection);
void _dbus_pending_call_complete (DBusPendingCall *pending);
void _dbus_pending_call_set_reply (DBusPendingCall *pending,
diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c
index 66573f66..e3bfbb42 100644
--- a/dbus/dbus-pending-call.c
+++ b/dbus/dbus-pending-call.c
@@ -83,7 +83,7 @@ _dbus_pending_call_new (DBusConnection *connection,
DBusTimeout *timeout;
_dbus_assert (timeout_milliseconds >= 0 || timeout_milliseconds == -1);
-
+
if (timeout_milliseconds == -1)
timeout_milliseconds = _DBUS_DEFAULT_TIMEOUT_VALUE;
@@ -119,8 +119,11 @@ _dbus_pending_call_new (DBusConnection *connection,
pending->refcount.value = 1;
pending->connection = connection;
+ dbus_connection_ref (pending->connection);
+
pending->timeout = timeout;
+
_dbus_data_slot_list_init (&pending->slot_list);
return pending;
@@ -285,34 +288,6 @@ _dbus_pending_call_get_connection (DBusPendingCall *pending)
}
/**
- * Sets the connection associated with the pending call
- *
- * @param pending the pending_call
- * @param connection the connection which is associated with the pending call
- */
-void
-_dbus_pending_call_set_connection (DBusPendingCall *pending,
- DBusConnection *connection)
-{
- _dbus_assert (pending != NULL);
-
- pending->connection = connection;
-}
-
-/**
- * NULLs out the connection
- *
- * @param pending the pending_call
- */
-void
-_dbus_pending_call_clear_connection (DBusPendingCall *pending)
-{
- _dbus_assert (pending != NULL);
-
- pending->connection = NULL;
-}
-
-/**
* Sets the reply message associated with the pending call to a timeout error
*
* @param pending the pending_call
@@ -403,12 +378,13 @@ dbus_pending_call_unref (DBusPendingCall *pending)
/* If we get here, we should be already detached
* from the connection, or never attached.
*/
- _dbus_assert (pending->connection == NULL);
_dbus_assert (!pending->timeout_added);
+
+ dbus_connection_unref (pending->connection);
/* this assumes we aren't holding connection lock... */
_dbus_data_slot_list_free (&pending->slot_list);
-
+
if (pending->timeout != NULL)
_dbus_timeout_unref (pending->timeout);