25 #include "dbus-shared.h"
26 #include "dbus-connection.h"
27 #include "dbus-list.h"
28 #include "dbus-timeout.h"
29 #include "dbus-transport.h"
30 #include "dbus-watch.h"
31 #include "dbus-connection-internal.h"
32 #include "dbus-pending-call-internal.h"
33 #include "dbus-list.h"
34 #include "dbus-hash.h"
35 #include "dbus-message-internal.h"
36 #include "dbus-message-private.h"
37 #include "dbus-threads.h"
38 #include "dbus-protocol.h"
39 #include "dbus-dataslot.h"
40 #include "dbus-string.h"
41 #include "dbus-signature.h"
42 #include "dbus-pending-call.h"
43 #include "dbus-object-tree.h"
44 #include "dbus-threads-internal.h"
46 #include "dbus-marshal-basic.h"
48 #ifdef DBUS_ENABLE_SMACK
49 #include <sys/smack.h>
53 #ifdef DBUS_DISABLE_CHECKS
54 #define TOOK_LOCK_CHECK(connection)
55 #define RELEASING_LOCK_CHECK(connection)
56 #define HAVE_LOCK_CHECK(connection)
58 #define TOOK_LOCK_CHECK(connection) do { \
59 _dbus_assert (!(connection)->have_connection_lock); \
60 (connection)->have_connection_lock = TRUE; \
62 #define RELEASING_LOCK_CHECK(connection) do { \
63 _dbus_assert ((connection)->have_connection_lock); \
64 (connection)->have_connection_lock = FALSE; \
66 #define HAVE_LOCK_CHECK(connection) _dbus_assert ((connection)->have_connection_lock)
72 #define CONNECTION_LOCK(connection) do { \
73 if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
74 _dbus_rmutex_lock ((connection)->mutex); \
75 TOOK_LOCK_CHECK (connection); \
78 #define CONNECTION_UNLOCK(connection) _dbus_connection_unlock (connection)
80 #define SLOTS_LOCK(connection) do { \
81 _dbus_rmutex_lock ((connection)->slot_mutex); \
84 #define SLOTS_UNLOCK(connection) do { \
85 _dbus_rmutex_unlock ((connection)->slot_mutex); \
88 #define DISPATCH_STATUS_NAME(s) \
89 ((s) == DBUS_DISPATCH_COMPLETE ? "complete" : \
90 (s) == DBUS_DISPATCH_DATA_REMAINS ? "data remains" : \
91 (s) == DBUS_DISPATCH_NEED_MEMORY ? "need memory" : \
217 #ifdef DBUS_ENABLE_VERBOSE_MODE
218 static int enabled = -1;
220 _dbus_trace_ref (
"DBusConnection", connection, old_refcount, new_refcount,
221 why,
"DBUS_CONNECTION_TRACE", &enabled);
252 #if HAVE_DECL_MSG_NOSIGNAL
312 #ifdef DBUS_ENABLE_SMACK
313 char *peer_smack_label;
338 #ifndef DBUS_DISABLE_CHECKS
342 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
348 static void _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
350 static void _dbus_connection_last_unref (
DBusConnection *connection);
351 static void _dbus_connection_acquire_dispatch (
DBusConnection *connection);
352 static void _dbus_connection_release_dispatch (
DBusConnection *connection);
354 static void _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection);
362 #ifdef DBUS_DISABLE_ASSERT
415 _dbus_verbose (
"UNLOCK\n");
423 RELEASING_LOCK_CHECK (connection);
461 status = _dbus_connection_get_dispatch_status_unlocked (connection);
462 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
474 _dbus_connection_set_dispatch (connection,
FALSE);
480 _dbus_connection_set_dispatch (connection,
TRUE);
484 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
533 message = link->
data;
537 if (reply_serial != 0)
555 _dbus_connection_wakeup_mainloop (connection);
557 _dbus_verbose (
"Message %p (%s %s %s %s '%s' reply to %u) added to incoming queue %p, %d incoming\n",
574 _dbus_message_trace_ref (message, -1, -1,
575 "_dbus_conection_queue_received_message_link");
590 HAVE_LOCK_CHECK (connection);
596 _dbus_connection_wakeup_mainloop (connection);
598 _dbus_message_trace_ref (link->
data, -1, -1,
599 "_dbus_connection_queue_synthesized_message_link");
601 _dbus_verbose (
"Synthesized message %p added to incoming queue %p, %d incoming\n",
616 HAVE_LOCK_CHECK (connection);
634 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
653 HAVE_LOCK_CHECK (connection);
672 HAVE_LOCK_CHECK (connection);
689 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from outgoing queue %p, %d left to send\n",
732 HAVE_LOCK_CHECK (connection);
755 retval = (* add_function) (connection->
watches, watch);
756 else if (remove_function)
759 (* remove_function) (connection->
watches, watch);
764 (* toggle_function) (connection->
watches, watch, enabled);
788 return protected_change_watch (connection, watch,
806 protected_change_watch (connection, watch,
829 protected_change_watch (connection, watch,
856 HAVE_LOCK_CHECK (connection);
879 retval = (* add_function) (connection->
timeouts, timeout);
880 else if (remove_function)
883 (* remove_function) (connection->
timeouts, timeout);
888 (* toggle_function) (connection->
timeouts, timeout, enabled);
912 return protected_change_timeout (connection, timeout,
930 protected_change_timeout (connection, timeout,
951 protected_change_timeout (connection, timeout,
958 _dbus_connection_attach_pending_call_unlocked (
DBusConnection *connection,
964 HAVE_LOCK_CHECK (connection);
984 HAVE_LOCK_CHECK (connection);
996 HAVE_LOCK_CHECK (connection);
1003 HAVE_LOCK_CHECK (connection);
1009 free_pending_call_on_hash_removal (
void *data)
1021 HAVE_LOCK_CHECK (connection);
1043 _dbus_connection_detach_pending_call_unlocked (
DBusConnection *connection,
1054 _dbus_connection_detach_pending_call_and_unlock (
DBusConnection *connection,
1090 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
1104 int timeout_milliseconds)
1108 HAVE_LOCK_CHECK (connection);
1116 _dbus_verbose (
"locking io_path_mutex\n");
1119 _dbus_verbose (
"start connection->io_path_acquired = %d timeout = %d\n",
1122 we_acquired =
FALSE;
1126 if (timeout_milliseconds != -1)
1128 _dbus_verbose (
"waiting %d for IO path to be acquirable\n",
1129 timeout_milliseconds);
1133 timeout_milliseconds))
1149 _dbus_verbose (
"waiting for IO path to be acquirable\n");
1162 _dbus_verbose (
"end connection->io_path_acquired = %d we_acquired = %d\n",
1165 _dbus_verbose (
"unlocking io_path_mutex\n");
1170 HAVE_LOCK_CHECK (connection);
1187 HAVE_LOCK_CHECK (connection);
1189 _dbus_verbose (
"locking io_path_mutex\n");
1194 _dbus_verbose (
"start connection->io_path_acquired = %d\n",
1200 _dbus_verbose (
"unlocking io_path_mutex\n");
1243 int timeout_milliseconds)
1245 _dbus_verbose (
"start\n");
1247 HAVE_LOCK_CHECK (connection);
1250 flags &= ~DBUS_ITERATION_DO_WRITING;
1252 if (_dbus_connection_acquire_io_path (connection,
1253 (flags & DBUS_ITERATION_BLOCK) ? timeout_milliseconds : 0))
1255 HAVE_LOCK_CHECK (connection);
1259 _dbus_verbose (
"pending call completed while acquiring I/O path");
1261 else if ( (pending !=
NULL) &&
1262 _dbus_connection_peek_for_reply_unlocked (connection,
1265 _dbus_verbose (
"pending call completed while acquiring I/O path (reply found in queue)");
1270 flags, timeout_milliseconds);
1273 _dbus_connection_release_io_path (connection);
1276 HAVE_LOCK_CHECK (connection);
1278 _dbus_verbose (
"end\n");
1304 pending_replies =
NULL;
1305 timeout_list =
NULL;
1306 disconnect_link =
NULL;
1307 disconnect_message =
NULL;
1308 outgoing_counter =
NULL;
1312 if (watch_list ==
NULL)
1316 if (timeout_list ==
NULL)
1323 if (pending_replies ==
NULL)
1327 if (connection ==
NULL)
1330 #ifdef DBUS_ENABLE_SMACK
1336 if (smack_new_label_from_socket(sock_fd, &label) >= 0) {
1337 connection->peer_smack_label = label;
1371 if (disconnect_message ==
NULL)
1375 if (disconnect_link ==
NULL)
1379 if (outgoing_counter ==
NULL)
1383 if (objects ==
NULL)
1386 if (_dbus_modify_sigpipe)
1392 connection->
watches = watch_list;
1393 connection->
timeouts = timeout_list;
1398 connection->
objects = objects;
1405 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
1428 _dbus_connection_trace_ref (connection, 0, 1,
"new_for_transport");
1432 if (disconnect_message !=
NULL)
1435 if (disconnect_link !=
NULL)
1438 if (connection !=
NULL)
1448 if (pending_replies)
1457 if (outgoing_counter)
1481 HAVE_LOCK_CHECK (connection);
1484 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
1501 HAVE_LOCK_CHECK (connection);
1507 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
1510 if (old_refcount == 1)
1511 _dbus_connection_last_unref (connection);
1515 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1542 unsigned int condition,
1551 _dbus_verbose (
"start\n");
1555 if (!_dbus_connection_acquire_io_path (connection, 1))
1562 HAVE_LOCK_CHECK (connection);
1566 _dbus_connection_release_io_path (connection);
1568 HAVE_LOCK_CHECK (connection);
1570 _dbus_verbose (
"middle\n");
1572 status = _dbus_connection_get_dispatch_status_unlocked (connection);
1575 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
1577 _dbus_verbose (
"end\n");
1603 shared_connections_shutdown (
void *data)
1626 close_connection_on_shutdown (connection);
1637 shared_connections =
NULL;
1639 if (shared_connections_no_guid !=
NULL)
1643 while (connection !=
NULL)
1646 close_connection_on_shutdown (connection);
1653 shared_connections_no_guid =
NULL;
1662 _dbus_verbose (
"checking for existing connection\n");
1673 if (shared_connections ==
NULL)
1675 _dbus_verbose (
"creating shared_connections hash table\n");
1680 if (shared_connections ==
NULL)
1689 shared_connections =
NULL;
1694 _dbus_verbose (
" successfully created shared_connections\n");
1729 if (_dbus_connection_get_is_connected_unlocked (connection))
1732 *result = connection;
1733 _dbus_verbose (
"looked up existing connection to server guid %s\n",
1738 _dbus_verbose (
"looked up existing connection to server guid %s but it was disconnected so ignoring it\n",
1755 char *guid_in_connection;
1757 HAVE_LOCK_CHECK (connection);
1788 if (guid_key ==
NULL)
1792 if (guid_in_connection ==
NULL)
1808 guid_key, connection))
1818 _dbus_verbose (
"stored connection to %s to be shared\n",
1831 HAVE_LOCK_CHECK (connection);
1845 _dbus_verbose (
"dropping connection to %s out of the shared table\n",
1875 if (transport ==
NULL)
1877 _DBUS_ASSERT_ERROR_IS_SET (error);
1885 if (connection ==
NULL)
1887 _DBUS_SET_OOM (error);
1891 #ifndef DBUS_DISABLE_CHECKS
1910 _dbus_connection_open_internal (
const char *address,
1920 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1922 _dbus_verbose (
"opening %s connection to: %s\n",
1923 shared ?
"shared" :
"private", address);
1928 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1932 for (i = 0; i < len; i++)
1936 if (!connection_lookup_shared (entries[i], &connection))
1937 _DBUS_SET_OOM (&tmp_error);
1940 if (connection ==
NULL)
1942 connection = connection_try_from_address_entry (entries[i],
1945 if (connection !=
NULL && shared)
1956 if (!connection_record_shared_unlocked (connection, guid))
1958 _DBUS_SET_OOM (&tmp_error);
1959 _dbus_connection_close_possibly_shared_and_unlock (connection);
1971 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1979 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1980 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1982 if (connection ==
NULL)
1984 _DBUS_ASSERT_ERROR_IS_SET (&first_error);
2009 _dbus_connection_close_possibly_shared_and_unlock (connection);
2013 _dbus_connection_preallocate_send_unlocked (
DBusConnection *connection)
2017 HAVE_LOCK_CHECK (connection);
2022 if (preallocated ==
NULL)
2037 return preallocated;
2049 _dbus_connection_send_preallocated_unlocked_no_update (
DBusConnection *connection,
2066 preallocated =
NULL;
2072 _dbus_verbose (
"Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n",
2093 serial = _dbus_connection_get_next_client_serial (connection);
2096 *client_serial = serial;
2104 _dbus_verbose (
"Message %p serial is %u\n",
2114 DBUS_ITERATION_DO_WRITING,
2119 _dbus_connection_wakeup_mainloop (connection);
2123 _dbus_connection_send_preallocated_and_unlock (
DBusConnection *connection,
2130 HAVE_LOCK_CHECK (connection);
2132 _dbus_connection_send_preallocated_unlocked_no_update (connection,
2134 message, client_serial);
2136 _dbus_verbose (
"middle\n");
2137 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2140 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2162 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2163 if (preallocated ==
NULL)
2169 _dbus_connection_send_preallocated_and_unlock (connection,
2212 _dbus_connection_close_possibly_shared_and_unlock (connection);
2228 _dbus_memory_pause_based_on_timeout (
int timeout_milliseconds)
2230 if (timeout_milliseconds == -1)
2232 else if (timeout_milliseconds < 100)
2234 else if (timeout_milliseconds <= 1000)
2267 if (error_msg !=
NULL)
2290 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2294 HAVE_LOCK_CHECK (connection);
2298 while (link !=
NULL)
2304 _dbus_verbose (
"%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial);
2322 HAVE_LOCK_CHECK (connection);
2326 while (link !=
NULL)
2343 connection_timeout_and_complete_all_pending_calls_unlocked (
DBusConnection *connection)
2373 HAVE_LOCK_CHECK (connection);
2383 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2391 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2397 reply = check_for_reply_unlocked (connection,
2401 _dbus_verbose (
"checked for reply\n");
2403 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2405 complete_pending_call_and_unlock (connection, pending, reply);
2409 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2410 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2436 long start_tv_sec, start_tv_usec;
2437 long tv_sec, tv_usec;
2442 int timeout_milliseconds, elapsed_milliseconds;
2454 _dbus_connection_flush_unlocked (connection);
2468 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2469 timeout_milliseconds,
2471 start_tv_sec, start_tv_usec);
2475 timeout_milliseconds = -1;
2477 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2482 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2489 DBUS_ITERATION_DO_READING |
2490 DBUS_ITERATION_BLOCK,
2491 timeout_milliseconds);
2495 _dbus_verbose (
"top of recheck\n");
2497 HAVE_LOCK_CHECK (connection);
2501 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2508 _dbus_verbose (
"Pending call completed by dispatch\n");
2509 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2516 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2521 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2522 (tv_usec - start_tv_usec) / 1000;
2524 if (!_dbus_connection_get_is_connected_unlocked (connection))
2528 error_msg = generate_local_error_message (client_serial,
2530 "Connection was disconnected before a reply was received");
2533 complete_pending_call_and_unlock (connection, pending, error_msg);
2538 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2539 else if (timeout ==
NULL)
2547 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2549 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2556 DBUS_ITERATION_DO_READING |
2557 DBUS_ITERATION_BLOCK,
2558 timeout_milliseconds - elapsed_milliseconds);
2561 goto recheck_status;
2563 else if (tv_sec < start_tv_sec)
2564 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2565 else if (elapsed_milliseconds < timeout_milliseconds)
2567 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2575 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2577 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2584 DBUS_ITERATION_DO_READING |
2585 DBUS_ITERATION_BLOCK,
2586 timeout_milliseconds - elapsed_milliseconds);
2589 goto recheck_status;
2592 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2593 elapsed_milliseconds);
2598 complete_pending_call_and_unlock (connection, pending,
NULL);
2602 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2603 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2649 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2650 _dbus_return_val_if_error_is_set (error,
NULL);
2652 connection = _dbus_connection_open_internal (address,
2692 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2693 _dbus_return_val_if_error_is_set (error,
NULL);
2695 connection = _dbus_connection_open_internal (address,
2713 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2716 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2723 free_outgoing_message (
void *element,
2742 _dbus_verbose (
"Finalizing connection %p\n", connection);
2769 while (link !=
NULL)
2775 _dbus_message_filter_unref (filter);
2792 free_outgoing_message,
2822 #ifdef DBUS_ENABLE_SMACK
2823 if (connection->peer_smack_label)
2824 free (connection->peer_smack_label);
2854 _dbus_return_if_fail (connection !=
NULL);
2859 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2862 if (old_refcount == 1)
2864 #ifndef DBUS_DISABLE_CHECKS
2867 _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",
2869 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2870 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2874 _dbus_connection_last_unref (connection);
2888 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2892 HAVE_LOCK_CHECK (connection);
2894 _dbus_verbose (
"Disconnecting %p\n", connection);
2913 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2916 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2967 _dbus_return_if_fail (connection !=
NULL);
2972 #ifndef DBUS_DISABLE_CHECKS
2977 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2982 _dbus_connection_close_possibly_shared_and_unlock (connection);
2986 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2988 HAVE_LOCK_CHECK (connection);
3010 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3013 res = _dbus_connection_get_is_connected_unlocked (connection);
3032 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3066 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3111 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3141 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3149 #ifdef HAVE_UNIX_FD_PASSING
3181 _dbus_return_if_fail (connection !=
NULL);
3202 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3207 _dbus_connection_preallocate_send_unlocked (connection);
3211 return preallocated;
3227 _dbus_return_if_fail (connection !=
NULL);
3228 _dbus_return_if_fail (preallocated !=
NULL);
3229 _dbus_return_if_fail (connection == preallocated->
connection);
3255 _dbus_return_if_fail (connection !=
NULL);
3256 _dbus_return_if_fail (preallocated !=
NULL);
3257 _dbus_return_if_fail (message !=
NULL);
3258 _dbus_return_if_fail (preallocated->
connection == connection);
3267 #ifdef HAVE_UNIX_FD_PASSING
3270 message->n_unix_fds > 0)
3281 _dbus_connection_send_preallocated_and_unlock (connection,
3283 message, client_serial);
3287 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3296 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3297 if (preallocated ==
NULL)
3300 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3339 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3340 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3344 #ifdef HAVE_UNIX_FD_PASSING
3347 message->n_unix_fds > 0)
3364 reply_handler_timeout (
void *data)
3379 _dbus_verbose (
"middle\n");
3380 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3383 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3435 int timeout_milliseconds)
3441 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3442 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3443 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3446 *pending_return =
NULL;
3450 #ifdef HAVE_UNIX_FD_PASSING
3453 message->n_unix_fds > 0)
3465 if (!_dbus_connection_get_is_connected_unlocked (connection))
3473 timeout_milliseconds,
3474 reply_handler_timeout);
3476 if (pending ==
NULL)
3486 serial = _dbus_connection_get_next_client_serial (connection);
3497 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3501 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3503 _dbus_connection_detach_pending_call_and_unlock (connection,
3505 goto error_unlocked;
3509 *pending_return = pending;
3512 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3518 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3521 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3523 if (pending_return ==
NULL)
3570 int timeout_milliseconds,
3576 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3577 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3578 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3579 _dbus_return_val_if_error_is_set (error,
NULL);
3581 #ifdef HAVE_UNIX_FD_PASSING
3585 message->n_unix_fds > 0)
3596 &pending, timeout_milliseconds))
3598 _DBUS_SET_OOM (error);
3602 if (pending ==
NULL)
3645 HAVE_LOCK_CHECK (connection);
3648 _dbus_connection_get_is_connected_unlocked (connection))
3650 _dbus_verbose (
"doing iteration in\n");
3651 HAVE_LOCK_CHECK (connection);
3654 DBUS_ITERATION_DO_READING |
3655 DBUS_ITERATION_DO_WRITING |
3656 DBUS_ITERATION_BLOCK,
3660 HAVE_LOCK_CHECK (connection);
3661 _dbus_verbose (
"middle\n");
3662 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3664 HAVE_LOCK_CHECK (connection);
3683 _dbus_return_if_fail (connection !=
NULL);
3687 status = _dbus_connection_flush_unlocked (connection);
3689 HAVE_LOCK_CHECK (connection);
3691 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3693 _dbus_verbose (
"end\n");
3707 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3708 int timeout_milliseconds,
3723 _dbus_verbose (
"doing dispatch\n");
3729 _dbus_verbose (
"pausing for memory\n");
3730 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3736 if (_dbus_connection_get_is_connected_unlocked (connection))
3738 _dbus_verbose (
"doing iteration\n");
3741 DBUS_ITERATION_DO_READING |
3742 DBUS_ITERATION_DO_WRITING |
3743 DBUS_ITERATION_BLOCK,
3744 timeout_milliseconds);
3748 HAVE_LOCK_CHECK (connection);
3754 progress_possible = connection->
n_incoming != 0 ||
3757 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3763 return progress_possible;
3803 int timeout_milliseconds)
3805 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3806 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3807 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3835 int timeout_milliseconds)
3837 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3838 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3839 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3848 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3851 HAVE_LOCK_CHECK (connection);
3888 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3890 _dbus_verbose (
"start\n");
3901 _dbus_connection_acquire_dispatch (connection);
3910 check_disconnected_message_arrived_unlocked (connection, message);
3913 if (message ==
NULL)
3914 _dbus_connection_release_dispatch (connection);
3918 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3939 _dbus_return_if_fail (connection !=
NULL);
3940 _dbus_return_if_fail (message !=
NULL);
3950 _dbus_connection_release_dispatch (connection);
3952 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3953 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3955 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3974 _dbus_return_if_fail (connection !=
NULL);
3975 _dbus_return_if_fail (message !=
NULL);
3989 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3994 _dbus_connection_release_dispatch (connection);
3996 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3997 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3998 _dbus_message_trace_ref (message, -1, -1,
3999 "dbus_connection_steal_borrowed_message");
4006 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
4008 HAVE_LOCK_CHECK (connection);
4019 _dbus_verbose (
"Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n",
4035 _dbus_message_trace_ref (link->
data, -1, -1,
4036 "_dbus_connection_pop_message_link_unlocked");
4038 check_disconnected_message_arrived_unlocked (connection, link->
data);
4050 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
4054 HAVE_LOCK_CHECK (connection);
4056 link = _dbus_connection_pop_message_link_unlocked (connection);
4062 message = link->
data;
4073 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4076 HAVE_LOCK_CHECK (connection);
4088 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4100 _dbus_message_trace_ref (message_link->
data, -1, -1,
4101 "_dbus_connection_putback_message_link_unlocked");
4113 if (message_link ==
NULL)
4115 _DBUS_SET_OOM (error);
4121 _dbus_connection_acquire_dispatch (connection);
4122 HAVE_LOCK_CHECK (connection);
4128 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4140 _dbus_message_trace_ref (message_link->
data, -1, -1,
4141 "_dbus_connection_putback_message");
4143 _dbus_connection_release_dispatch (connection);
4145 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4146 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4159 _dbus_connection_acquire_dispatch (connection);
4160 HAVE_LOCK_CHECK (connection);
4168 _dbus_verbose (
"Message %p removed from incoming queue\n", message);
4171 _dbus_verbose (
"Message %p not found in the incoming queue\n", message);
4173 _dbus_connection_release_dispatch (connection);
4175 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4176 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4205 _dbus_verbose (
"start\n");
4215 _dbus_connection_acquire_dispatch (connection);
4216 HAVE_LOCK_CHECK (connection);
4218 message = _dbus_connection_pop_message_unlocked (connection);
4220 _dbus_verbose (
"Returning popped message %p\n", message);
4222 _dbus_connection_release_dispatch (connection);
4224 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4225 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4240 HAVE_LOCK_CHECK (connection);
4245 _dbus_verbose (
"locking dispatch_mutex\n");
4250 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4259 _dbus_verbose (
"unlocking dispatch_mutex\n");
4276 HAVE_LOCK_CHECK (connection);
4278 _dbus_verbose (
"locking dispatch_mutex\n");
4286 _dbus_verbose (
"unlocking dispatch_mutex\n");
4303 HAVE_LOCK_CHECK (connection);
4321 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4333 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4335 HAVE_LOCK_CHECK (connection);
4339 _dbus_verbose (
"Sending disconnect message\n");
4344 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4360 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4362 HAVE_LOCK_CHECK (connection);
4377 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4378 DISPATCH_STATUS_NAME (status), is_connected);
4388 notify_disconnected_unlocked (connection);
4396 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4409 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4416 HAVE_LOCK_CHECK (connection);
4436 connection_forget_shared_unlocked (connection);
4442 _dbus_verbose (
"Exiting on Disconnected signal\n");
4451 if (changed &&
function)
4453 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4454 connection, new_status,
4455 DISPATCH_STATUS_NAME (new_status));
4456 (* function) (connection, new_status, data);
4494 _dbus_verbose (
"start\n");
4498 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4509 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4542 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4562 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4575 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4579 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4590 expire_link->
data = ret;
4607 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4613 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4662 DBusList *link, *filter_list_copy, *message_link;
4671 _dbus_verbose (
"\n");
4674 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4678 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4687 _dbus_connection_acquire_dispatch (connection);
4688 HAVE_LOCK_CHECK (connection);
4690 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4691 if (message_link ==
NULL)
4695 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4697 _dbus_connection_release_dispatch (connection);
4699 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4701 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4708 message = message_link->
data;
4710 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4735 _dbus_verbose (
"Dispatching a pending reply\n");
4736 complete_pending_call_and_unlock (connection, pending, message);
4740 _dbus_verbose (
"pending call completed in dispatch\n");
4745 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4751 _dbus_connection_release_dispatch (connection);
4752 HAVE_LOCK_CHECK (connection);
4754 _dbus_connection_failed_pop (connection, message_link);
4757 _dbus_connection_update_dispatch_status_and_unlock (connection,
4774 while (link !=
NULL)
4781 _dbus_verbose (
" filter was removed in a callback function\n");
4786 _dbus_verbose (
" running filter on message %p\n", message);
4806 _dbus_verbose (
"No memory\n");
4811 _dbus_verbose (
"filter handled message in dispatch\n");
4818 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4829 HAVE_LOCK_CHECK (connection);
4838 _dbus_verbose (
"object tree handled message in dispatch\n");
4849 _dbus_verbose (
" sending error %s\n",
4855 _dbus_verbose (
"no memory for error string in dispatch\n");
4860 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4867 _dbus_verbose (
"no memory for error string in dispatch\n");
4879 _dbus_verbose (
"no memory for error reply in dispatch\n");
4885 if (expire_link ==
NULL)
4889 _dbus_verbose (
"no memory for error send in dispatch\n");
4893 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4895 if (preallocated ==
NULL)
4902 _dbus_verbose (
"no memory for error send in dispatch\n");
4906 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4914 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4930 _dbus_verbose (
"out of memory\n");
4936 _dbus_connection_putback_message_link_unlocked (connection,
4939 message_link =
NULL;
4944 _dbus_verbose (
" ... done dispatching\n");
4947 _dbus_connection_release_dispatch (connection);
4948 HAVE_LOCK_CHECK (connection);
4950 if (message !=
NULL)
4964 if (message_link !=
NULL)
4967 _dbus_verbose (
"before final status update\n");
4968 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4971 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
5049 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5054 add_function, remove_function,
5056 data, free_data_function);
5112 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5117 add_function, remove_function,
5119 data, free_data_function);
5149 _dbus_return_if_fail (connection !=
NULL);
5163 (*old_free_data) (old_data);
5195 _dbus_return_if_fail (connection !=
NULL);
5209 (*old_free_data) (old_data);
5235 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5267 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5309 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5310 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5345 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5346 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5361 #ifdef DBUS_ENABLE_SMACK
5374 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5375 _dbus_return_val_if_fail (label !=
NULL,
FALSE);
5377 *label = connection->peer_smack_label;
5378 return *label !=
NULL;
5400 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5401 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5402 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5445 void *old_data =
NULL;
5448 _dbus_return_if_fail (connection !=
NULL);
5452 function, data, free_data_function,
5453 &old_data, &old_free_function);
5456 if (old_free_function !=
NULL)
5457 (* old_free_function) (old_data);
5493 char **windows_sid_p)
5497 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5498 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5544 void *old_data =
NULL;
5547 _dbus_return_if_fail (connection !=
NULL);
5551 function, data, free_data_function,
5552 &old_data, &old_free_function);
5555 if (old_free_function !=
NULL)
5556 (* old_free_function) (old_data);
5589 _dbus_return_if_fail (connection !=
NULL);
5617 _dbus_return_if_fail (connection !=
NULL);
5653 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5654 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5667 _dbus_message_filter_unref (filter);
5705 _dbus_return_if_fail (connection !=
NULL);
5706 _dbus_return_if_fail (
function !=
NULL);
5713 while (link !=
NULL)
5715 filter = link->
data;
5717 if (filter->
function ==
function &&
5732 #ifndef DBUS_DISABLE_CHECKS
5735 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5736 function, user_data);
5748 _dbus_message_filter_unref (filter);
5767 _dbus_connection_register_object_path (
DBusConnection *connection,
5774 char **decomposed_path;
5784 (
const char **) decomposed_path, vtable,
5813 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5814 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5815 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5816 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5818 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5845 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5846 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5847 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5848 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5850 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5883 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5884 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5885 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5886 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5888 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5917 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5918 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5919 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5920 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5922 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5947 char **decomposed_path;
5949 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5950 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5951 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5980 char **decomposed_path;
5982 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5983 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5984 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
6014 const char *parent_path,
6015 char ***child_entries)
6017 char **decomposed_path;
6019 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
6020 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
6021 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
6022 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
6030 (
const char **) decomposed_path,
6075 _dbus_return_if_fail (*slot_p >= 0);
6112 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
6113 _dbus_return_val_if_fail (slot >= 0,
FALSE);
6115 SLOTS_LOCK (connection);
6119 slot, data, free_data_func,
6120 &old_free_func, &old_data);
6122 SLOTS_UNLOCK (connection);
6128 (* old_free_func) (old_data);
6157 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
6158 _dbus_return_val_if_fail (slot >= 0,
NULL);
6160 SLOTS_LOCK (connection);
6166 SLOTS_UNLOCK (connection);
6180 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6195 _dbus_return_if_fail (connection !=
NULL);
6214 _dbus_return_val_if_fail (connection !=
NULL, 0);
6234 _dbus_return_if_fail (connection !=
NULL);
6253 _dbus_return_val_if_fail (connection !=
NULL, 0);
6290 _dbus_return_if_fail (connection !=
NULL);
6309 _dbus_return_val_if_fail (connection !=
NULL, 0);
6332 _dbus_return_if_fail (connection !=
NULL);
6351 _dbus_return_val_if_fail (connection !=
NULL, 0);
6374 _dbus_return_val_if_fail (connection !=
NULL, 0);
6382 #ifdef DBUS_ENABLE_STATS
6398 if (in_messages !=
NULL)
6401 _dbus_transport_get_stats (connection->
transport,
6402 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6404 if (out_messages !=
NULL)
6407 if (out_bytes !=
NULL)
6410 if (out_fds !=
NULL)
6413 if (out_peak_bytes !=
NULL)
6414 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6416 if (out_peak_fds !=
NULL)
6417 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6435 _dbus_return_val_if_fail (connection !=
NULL, 0);
6443 #ifdef DBUS_ENABLE_EMBEDDED_TESTS