From d1618721b333f8dba8750b1297575df10a2df671 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 16 Oct 2014 15:55:46 +0100 Subject: [PATCH 3/8] DBusTransport, DBusConnection: make the disconnection error available --- dbus/dbus-connection-internal.h | 3 +++ dbus/dbus-connection.c | 41 ++++++++++++++++++++++++++++------------- dbus/dbus-transport.h | 3 ++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 2897404..4933a72 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -134,6 +134,9 @@ const char* _dbus_connection_get_address (DBusConnection *connection); void _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection); +dbus_bool_t _dbus_connection_check_connected (DBusConnection *connection, + DBusError *error); + /** @} */ diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 4036819..5a3cf7a 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -343,7 +343,8 @@ static void _dbus_connection_acquire_dispatch (DB static void _dbus_connection_release_dispatch (DBusConnection *connection); static DBusDispatchStatus _dbus_connection_flush_unlocked (DBusConnection *connection); static void _dbus_connection_close_possibly_shared_and_unlock (DBusConnection *connection); -static dbus_bool_t _dbus_connection_get_is_connected_unlocked (DBusConnection *connection); +static dbus_bool_t _dbus_connection_get_is_connected_unlocked (DBusConnection *connection, + DBusError *error); static dbus_bool_t _dbus_connection_peek_for_reply_unlocked (DBusConnection *connection, dbus_uint32_t client_serial); @@ -1671,7 +1672,7 @@ connection_lookup_shared (DBusAddressEntry *entry, * that causes reentrancy headaches. */ CONNECTION_LOCK (connection); - if (_dbus_connection_get_is_connected_unlocked (connection)) + if (_dbus_connection_get_is_connected_unlocked (connection, NULL)) { _dbus_connection_ref_unlocked (connection); *result = connection; @@ -2466,7 +2467,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 + (tv_usec - start_tv_usec) / 1000; - if (!_dbus_connection_get_is_connected_unlocked (connection)) + if (!_dbus_connection_get_is_connected_unlocked (connection, NULL)) { DBusMessage *error_msg; @@ -2718,7 +2719,7 @@ _dbus_connection_last_unref (DBusConnection *connection) /* You have to disconnect the connection before unref:ing it. Otherwise * you won't get the disconnected message. */ - _dbus_assert (!_dbus_transport_get_is_connected (connection->transport)); + _dbus_assert (!_dbus_transport_get_is_connected (connection->transport, NULL)); _dbus_assert (connection->server_guid == NULL); /* ---- We're going to call various application callbacks here, hope it doesn't break anything... */ @@ -2829,7 +2830,7 @@ dbus_connection_unref (DBusConnection *connection) if (old_refcount == 1) { #ifndef DBUS_DISABLE_CHECKS - if (_dbus_transport_get_is_connected (connection->transport)) + if (_dbus_transport_get_is_connected (connection->transport, NULL)) { _dbus_warn_check_failed ("The last reference on a connection was dropped without closing the connection. This is a bug in an application. See dbus_connection_unref() documentation for details.\n%s", connection->shareable ? @@ -2951,10 +2952,11 @@ dbus_connection_close (DBusConnection *connection) } static dbus_bool_t -_dbus_connection_get_is_connected_unlocked (DBusConnection *connection) +_dbus_connection_get_is_connected_unlocked (DBusConnection *connection, + DBusError *error) { HAVE_LOCK_CHECK (connection); - return _dbus_transport_get_is_connected (connection->transport); + return _dbus_transport_get_is_connected (connection->transport, error); } /** @@ -2978,12 +2980,25 @@ dbus_connection_get_is_connected (DBusConnection *connection) _dbus_return_val_if_fail (connection != NULL, FALSE); CONNECTION_LOCK (connection); - res = _dbus_connection_get_is_connected_unlocked (connection); + res = _dbus_connection_get_is_connected_unlocked (connection, NULL); CONNECTION_UNLOCK (connection); return res; } +dbus_bool_t +_dbus_connection_check_connected (DBusConnection *connection, + DBusError *error) +{ + dbus_bool_t res; + + CONNECTION_LOCK (connection); + res = _dbus_connection_get_is_connected_unlocked (connection, error); + CONNECTION_UNLOCK (connection); + + return res; +} + /** * Gets whether the connection was authenticated. (Note that * if the connection was authenticated then disconnected, @@ -3430,7 +3445,7 @@ dbus_connection_send_with_reply (DBusConnection *connection, #endif - if (!_dbus_connection_get_is_connected_unlocked (connection)) + if (!_dbus_connection_get_is_connected_unlocked (connection, NULL)) { CONNECTION_UNLOCK (connection); @@ -3613,7 +3628,7 @@ _dbus_connection_flush_unlocked (DBusConnection *connection) HAVE_LOCK_CHECK (connection); while (connection->n_outgoing > 0 && - _dbus_connection_get_is_connected_unlocked (connection)) + _dbus_connection_get_is_connected_unlocked (connection, NULL)) { _dbus_verbose ("doing iteration in\n"); HAVE_LOCK_CHECK (connection); @@ -3701,7 +3716,7 @@ _dbus_connection_read_write_dispatch (DBusConnection *connection, else { CONNECTION_LOCK (connection); - if (_dbus_connection_get_is_connected_unlocked (connection)) + if (_dbus_connection_get_is_connected_unlocked (connection, NULL)) { _dbus_verbose ("doing iteration\n"); _dbus_connection_do_iteration_unlocked (connection, @@ -3722,7 +3737,7 @@ _dbus_connection_read_write_dispatch (DBusConnection *connection, progress_possible = connection->n_incoming != 0 || connection->disconnect_message_link != NULL; else - progress_possible = _dbus_connection_get_is_connected_unlocked (connection); + progress_possible = _dbus_connection_get_is_connected_unlocked (connection, NULL); CONNECTION_UNLOCK (connection); @@ -4263,7 +4278,7 @@ _dbus_connection_get_dispatch_status_unlocked (DBusConnection *connection) dbus_bool_t is_connected; status = _dbus_transport_get_dispatch_status (connection->transport); - is_connected = _dbus_transport_get_is_connected (connection->transport); + is_connected = _dbus_transport_get_is_connected (connection->transport, NULL); _dbus_verbose ("dispatch status = %s is_connected = %d\n", DISPATCH_STATUS_NAME (status), is_connected); diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h index c65a17a..fdab16b 100644 --- a/dbus/dbus-transport.h +++ b/dbus/dbus-transport.h @@ -36,7 +36,6 @@ DBusTransport* _dbus_transport_open (DBusAddressEntry DBusError *error); DBusTransport* _dbus_transport_ref (DBusTransport *transport); void _dbus_transport_unref (DBusTransport *transport); -dbus_bool_t _dbus_transport_get_is_connected (DBusTransport *transport); void _dbus_transport_disconnect (DBusTransport *transport, const char *error, const char *format, @@ -45,6 +44,8 @@ void _dbus_transport_disconnect_va (DBusTransport const char *error, const char *format, va_list args); +dbus_bool_t _dbus_transport_get_is_connected (DBusTransport *transport, + DBusError *error); dbus_bool_t _dbus_transport_peek_is_authenticated (DBusTransport *transport); dbus_bool_t _dbus_transport_try_to_authenticate (DBusTransport *transport); dbus_bool_t _dbus_transport_get_is_anonymous (DBusTransport *transport); -- 2.1.1