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_DISABLE_CHECKS
49 #define TOOK_LOCK_CHECK(connection)
50 #define RELEASING_LOCK_CHECK(connection)
51 #define HAVE_LOCK_CHECK(connection)
53 #define TOOK_LOCK_CHECK(connection) do { \
54 _dbus_assert (!(connection)->have_connection_lock); \
55 (connection)->have_connection_lock = TRUE; \
57 #define RELEASING_LOCK_CHECK(connection) do { \
58 _dbus_assert ((connection)->have_connection_lock); \
59 (connection)->have_connection_lock = FALSE; \
61 #define HAVE_LOCK_CHECK(connection) _dbus_assert ((connection)->have_connection_lock)
67 #define CONNECTION_LOCK(connection) do { \
68 if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
69 _dbus_rmutex_lock ((connection)->mutex); \
70 TOOK_LOCK_CHECK (connection); \
73 #define CONNECTION_UNLOCK(connection) _dbus_connection_unlock (connection)
75 #define SLOTS_LOCK(connection) do { \
76 _dbus_rmutex_lock ((connection)->slot_mutex); \
79 #define SLOTS_UNLOCK(connection) do { \
80 _dbus_rmutex_unlock ((connection)->slot_mutex); \
83 #define DISPATCH_STATUS_NAME(s) \
84 ((s) == DBUS_DISPATCH_COMPLETE ? "complete" : \
85 (s) == DBUS_DISPATCH_DATA_REMAINS ? "data remains" : \
86 (s) == DBUS_DISPATCH_NEED_MEMORY ? "need memory" : \
212 #ifdef DBUS_ENABLE_VERBOSE_MODE
213 static int enabled = -1;
215 _dbus_trace_ref (
"DBusConnection", connection, old_refcount, new_refcount,
216 why,
"DBUS_CONNECTION_TRACE", &enabled);
247 #if HAVE_DECL_MSG_NOSIGNAL
329 #ifndef DBUS_DISABLE_CHECKS
333 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
339 static void _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
341 static void _dbus_connection_last_unref (
DBusConnection *connection);
342 static void _dbus_connection_acquire_dispatch (
DBusConnection *connection);
343 static void _dbus_connection_release_dispatch (
DBusConnection *connection);
345 static void _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection);
353 #ifdef DBUS_DISABLE_ASSERT
406 _dbus_verbose (
"UNLOCK\n");
414 RELEASING_LOCK_CHECK (connection);
442 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
491 message = link->
data;
495 if (reply_serial != 0)
513 _dbus_connection_wakeup_mainloop (connection);
515 _dbus_verbose (
"Message %p (%s %s %s %s '%s' reply to %u) added to incoming queue %p, %d incoming\n",
532 _dbus_message_trace_ref (message, -1, -1,
533 "_dbus_conection_queue_received_message_link");
548 HAVE_LOCK_CHECK (connection);
554 _dbus_connection_wakeup_mainloop (connection);
556 _dbus_message_trace_ref (link->
data, -1, -1,
557 "_dbus_connection_queue_synthesized_message_link");
559 _dbus_verbose (
"Synthesized message %p added to incoming queue %p, %d incoming\n",
574 HAVE_LOCK_CHECK (connection);
592 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
611 HAVE_LOCK_CHECK (connection);
630 HAVE_LOCK_CHECK (connection);
647 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from outgoing queue %p, %d left to send\n",
690 HAVE_LOCK_CHECK (connection);
713 retval = (* add_function) (connection->
watches, watch);
714 else if (remove_function)
717 (* remove_function) (connection->
watches, watch);
722 (* toggle_function) (connection->
watches, watch, enabled);
746 return protected_change_watch (connection, watch,
764 protected_change_watch (connection, watch,
787 protected_change_watch (connection, watch,
814 HAVE_LOCK_CHECK (connection);
837 retval = (* add_function) (connection->
timeouts, timeout);
838 else if (remove_function)
841 (* remove_function) (connection->
timeouts, timeout);
846 (* toggle_function) (connection->
timeouts, timeout, enabled);
870 return protected_change_timeout (connection, timeout,
888 protected_change_timeout (connection, timeout,
909 protected_change_timeout (connection, timeout,
916 _dbus_connection_attach_pending_call_unlocked (
DBusConnection *connection,
922 HAVE_LOCK_CHECK (connection);
942 HAVE_LOCK_CHECK (connection);
954 HAVE_LOCK_CHECK (connection);
961 HAVE_LOCK_CHECK (connection);
967 free_pending_call_on_hash_removal (
void *data)
979 HAVE_LOCK_CHECK (connection);
1001 _dbus_connection_detach_pending_call_unlocked (
DBusConnection *connection,
1012 _dbus_connection_detach_pending_call_and_unlock (
DBusConnection *connection,
1048 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
1062 int timeout_milliseconds)
1066 HAVE_LOCK_CHECK (connection);
1074 _dbus_verbose (
"locking io_path_mutex\n");
1077 _dbus_verbose (
"start connection->io_path_acquired = %d timeout = %d\n",
1080 we_acquired =
FALSE;
1084 if (timeout_milliseconds != -1)
1086 _dbus_verbose (
"waiting %d for IO path to be acquirable\n",
1087 timeout_milliseconds);
1091 timeout_milliseconds))
1107 _dbus_verbose (
"waiting for IO path to be acquirable\n");
1120 _dbus_verbose (
"end connection->io_path_acquired = %d we_acquired = %d\n",
1123 _dbus_verbose (
"unlocking io_path_mutex\n");
1128 HAVE_LOCK_CHECK (connection);
1145 HAVE_LOCK_CHECK (connection);
1147 _dbus_verbose (
"locking io_path_mutex\n");
1152 _dbus_verbose (
"start connection->io_path_acquired = %d\n",
1158 _dbus_verbose (
"unlocking io_path_mutex\n");
1201 int timeout_milliseconds)
1203 _dbus_verbose (
"start\n");
1205 HAVE_LOCK_CHECK (connection);
1208 flags &= ~DBUS_ITERATION_DO_WRITING;
1210 if (_dbus_connection_acquire_io_path (connection,
1211 (flags & DBUS_ITERATION_BLOCK) ? timeout_milliseconds : 0))
1213 HAVE_LOCK_CHECK (connection);
1217 _dbus_verbose (
"pending call completed while acquiring I/O path");
1219 else if ( (pending !=
NULL) &&
1220 _dbus_connection_peek_for_reply_unlocked (connection,
1223 _dbus_verbose (
"pending call completed while acquiring I/O path (reply found in queue)");
1228 flags, timeout_milliseconds);
1231 _dbus_connection_release_io_path (connection);
1234 HAVE_LOCK_CHECK (connection);
1236 _dbus_verbose (
"end\n");
1262 pending_replies =
NULL;
1263 timeout_list =
NULL;
1264 disconnect_link =
NULL;
1265 disconnect_message =
NULL;
1266 outgoing_counter =
NULL;
1270 if (watch_list ==
NULL)
1274 if (timeout_list ==
NULL)
1281 if (pending_replies ==
NULL)
1285 if (connection ==
NULL)
1316 if (disconnect_message ==
NULL)
1320 if (disconnect_link ==
NULL)
1324 if (outgoing_counter ==
NULL)
1328 if (objects ==
NULL)
1331 if (_dbus_modify_sigpipe)
1337 connection->
watches = watch_list;
1338 connection->
timeouts = timeout_list;
1343 connection->
objects = objects;
1350 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
1373 _dbus_connection_trace_ref (connection, 0, 1,
"new_for_transport");
1377 if (disconnect_message !=
NULL)
1380 if (disconnect_link !=
NULL)
1383 if (connection !=
NULL)
1393 if (pending_replies)
1402 if (outgoing_counter)
1426 HAVE_LOCK_CHECK (connection);
1429 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
1446 HAVE_LOCK_CHECK (connection);
1452 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
1455 if (old_refcount == 1)
1456 _dbus_connection_last_unref (connection);
1460 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1487 unsigned int condition,
1496 _dbus_verbose (
"start\n");
1500 if (!_dbus_connection_acquire_io_path (connection, 1))
1507 HAVE_LOCK_CHECK (connection);
1511 _dbus_connection_release_io_path (connection);
1513 HAVE_LOCK_CHECK (connection);
1515 _dbus_verbose (
"middle\n");
1517 status = _dbus_connection_get_dispatch_status_unlocked (connection);
1520 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
1522 _dbus_verbose (
"end\n");
1548 shared_connections_shutdown (
void *data)
1571 close_connection_on_shutdown (connection);
1582 shared_connections =
NULL;
1584 if (shared_connections_no_guid !=
NULL)
1588 while (connection !=
NULL)
1591 close_connection_on_shutdown (connection);
1598 shared_connections_no_guid =
NULL;
1607 _dbus_verbose (
"checking for existing connection\n");
1618 if (shared_connections ==
NULL)
1620 _dbus_verbose (
"creating shared_connections hash table\n");
1625 if (shared_connections ==
NULL)
1634 shared_connections =
NULL;
1639 _dbus_verbose (
" successfully created shared_connections\n");
1674 if (_dbus_connection_get_is_connected_unlocked (connection))
1677 *result = connection;
1678 _dbus_verbose (
"looked up existing connection to server guid %s\n",
1683 _dbus_verbose (
"looked up existing connection to server guid %s but it was disconnected so ignoring it\n",
1700 char *guid_in_connection;
1702 HAVE_LOCK_CHECK (connection);
1733 if (guid_key ==
NULL)
1737 if (guid_in_connection ==
NULL)
1753 guid_key, connection))
1763 _dbus_verbose (
"stored connection to %s to be shared\n",
1776 HAVE_LOCK_CHECK (connection);
1790 _dbus_verbose (
"dropping connection to %s out of the shared table\n",
1820 if (transport ==
NULL)
1822 _DBUS_ASSERT_ERROR_IS_SET (error);
1830 if (connection ==
NULL)
1832 _DBUS_SET_OOM (error);
1836 #ifndef DBUS_DISABLE_CHECKS
1855 _dbus_connection_open_internal (
const char *address,
1865 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1867 _dbus_verbose (
"opening %s connection to: %s\n",
1868 shared ?
"shared" :
"private", address);
1873 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1877 for (i = 0; i < len; i++)
1881 if (!connection_lookup_shared (entries[i], &connection))
1882 _DBUS_SET_OOM (&tmp_error);
1885 if (connection ==
NULL)
1887 connection = connection_try_from_address_entry (entries[i],
1890 if (connection !=
NULL && shared)
1901 if (!connection_record_shared_unlocked (connection, guid))
1903 _DBUS_SET_OOM (&tmp_error);
1904 _dbus_connection_close_possibly_shared_and_unlock (connection);
1916 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1924 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1925 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1927 if (connection ==
NULL)
1929 _DBUS_ASSERT_ERROR_IS_SET (&first_error);
1954 _dbus_connection_close_possibly_shared_and_unlock (connection);
1958 _dbus_connection_preallocate_send_unlocked (
DBusConnection *connection)
1962 HAVE_LOCK_CHECK (connection);
1967 if (preallocated ==
NULL)
1982 return preallocated;
1994 _dbus_connection_send_preallocated_unlocked_no_update (
DBusConnection *connection,
2011 preallocated =
NULL;
2017 _dbus_verbose (
"Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n",
2038 serial = _dbus_connection_get_next_client_serial (connection);
2041 *client_serial = serial;
2049 _dbus_verbose (
"Message %p serial is %u\n",
2059 DBUS_ITERATION_DO_WRITING,
2064 _dbus_connection_wakeup_mainloop (connection);
2068 _dbus_connection_send_preallocated_and_unlock (
DBusConnection *connection,
2075 HAVE_LOCK_CHECK (connection);
2077 _dbus_connection_send_preallocated_unlocked_no_update (connection,
2079 message, client_serial);
2081 _dbus_verbose (
"middle\n");
2082 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2085 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2107 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2108 if (preallocated ==
NULL)
2114 _dbus_connection_send_preallocated_and_unlock (connection,
2157 _dbus_connection_close_possibly_shared_and_unlock (connection);
2173 _dbus_memory_pause_based_on_timeout (
int timeout_milliseconds)
2175 if (timeout_milliseconds == -1)
2177 else if (timeout_milliseconds < 100)
2179 else if (timeout_milliseconds <= 1000)
2187 const char *error_name,
2188 const char *error_msg)
2212 if (error_msg !=
NULL)
2235 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2239 HAVE_LOCK_CHECK (connection);
2243 while (link !=
NULL)
2249 _dbus_verbose (
"%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial);
2267 HAVE_LOCK_CHECK (connection);
2271 while (link !=
NULL)
2288 connection_timeout_and_complete_all_pending_calls_unlocked (
DBusConnection *connection)
2318 HAVE_LOCK_CHECK (connection);
2329 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2337 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2343 reply = check_for_reply_unlocked (connection,
2347 _dbus_verbose (
"checked for reply\n");
2349 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2351 complete_pending_call_and_unlock (connection, pending, reply);
2355 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2356 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2382 long start_tv_sec, start_tv_usec;
2383 long tv_sec, tv_usec;
2388 int timeout_milliseconds, elapsed_milliseconds;
2400 _dbus_connection_flush_unlocked (connection);
2414 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2415 timeout_milliseconds,
2417 start_tv_sec, start_tv_usec);
2421 timeout_milliseconds = -1;
2423 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2428 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2435 DBUS_ITERATION_DO_READING |
2436 DBUS_ITERATION_BLOCK,
2437 timeout_milliseconds);
2441 _dbus_verbose (
"top of recheck\n");
2443 HAVE_LOCK_CHECK (connection);
2447 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2454 _dbus_verbose (
"Pending call completed by dispatch\n");
2455 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2462 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2467 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2468 (tv_usec - start_tv_usec) / 1000;
2470 if (!_dbus_connection_get_is_connected_unlocked (connection))
2474 error_msg = generate_local_error_message (client_serial,
2476 "Connection was disconnected before a reply was received");
2479 complete_pending_call_and_unlock (connection, pending, error_msg);
2480 if (error_msg !=
NULL)
2486 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2487 else if (timeout ==
NULL)
2495 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2497 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2504 DBUS_ITERATION_DO_READING |
2505 DBUS_ITERATION_BLOCK,
2506 timeout_milliseconds - elapsed_milliseconds);
2509 goto recheck_status;
2511 else if (tv_sec < start_tv_sec)
2512 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2513 else if (elapsed_milliseconds < timeout_milliseconds)
2515 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2523 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2525 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2532 DBUS_ITERATION_DO_READING |
2533 DBUS_ITERATION_BLOCK,
2534 timeout_milliseconds - elapsed_milliseconds);
2537 goto recheck_status;
2540 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2541 elapsed_milliseconds);
2546 complete_pending_call_and_unlock (connection, pending,
NULL);
2550 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2551 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2575 DBusPendingFdsChangeFunction callback,
2624 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2625 _dbus_return_val_if_error_is_set (error,
NULL);
2627 connection = _dbus_connection_open_internal (address,
2667 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2668 _dbus_return_val_if_error_is_set (error,
NULL);
2670 connection = _dbus_connection_open_internal (address,
2688 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2691 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2698 free_outgoing_message (
void *element,
2717 _dbus_verbose (
"Finalizing connection %p\n", connection);
2744 while (link !=
NULL)
2750 _dbus_message_filter_unref (filter);
2765 free_outgoing_message,
2822 _dbus_return_if_fail (connection !=
NULL);
2827 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2830 if (old_refcount == 1)
2832 #ifndef DBUS_DISABLE_CHECKS
2835 _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",
2837 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection." :
2838 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.");
2842 _dbus_connection_last_unref (connection);
2856 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2860 HAVE_LOCK_CHECK (connection);
2862 _dbus_verbose (
"Disconnecting %p\n", connection);
2881 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2884 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2935 _dbus_return_if_fail (connection !=
NULL);
2940 #ifndef DBUS_DISABLE_CHECKS
2945 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.");
2950 _dbus_connection_close_possibly_shared_and_unlock (connection);
2954 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2956 HAVE_LOCK_CHECK (connection);
2978 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2981 res = _dbus_connection_get_is_connected_unlocked (connection);
3000 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3034 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3079 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3109 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3117 #ifdef HAVE_UNIX_FD_PASSING
3149 _dbus_return_if_fail (connection !=
NULL);
3170 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3175 _dbus_connection_preallocate_send_unlocked (connection);
3179 return preallocated;
3195 _dbus_return_if_fail (connection !=
NULL);
3196 _dbus_return_if_fail (preallocated !=
NULL);
3197 _dbus_return_if_fail (connection == preallocated->
connection);
3223 _dbus_return_if_fail (connection !=
NULL);
3224 _dbus_return_if_fail (preallocated !=
NULL);
3225 _dbus_return_if_fail (message !=
NULL);
3226 _dbus_return_if_fail (preallocated->
connection == connection);
3235 #ifdef HAVE_UNIX_FD_PASSING
3238 message->n_unix_fds > 0)
3249 _dbus_connection_send_preallocated_and_unlock (connection,
3251 message, client_serial);
3255 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3264 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3265 if (preallocated ==
NULL)
3268 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3307 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3308 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3312 #ifdef HAVE_UNIX_FD_PASSING
3315 message->n_unix_fds > 0)
3332 reply_handler_timeout (
void *data)
3347 _dbus_verbose (
"middle\n");
3348 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3351 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3403 int timeout_milliseconds)
3409 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3410 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3411 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3414 *pending_return =
NULL;
3418 #ifdef HAVE_UNIX_FD_PASSING
3421 message->n_unix_fds > 0)
3433 if (!_dbus_connection_get_is_connected_unlocked (connection))
3441 timeout_milliseconds,
3442 reply_handler_timeout);
3444 if (pending ==
NULL)
3454 serial = _dbus_connection_get_next_client_serial (connection);
3465 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3469 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3471 _dbus_connection_detach_pending_call_and_unlock (connection,
3473 goto error_unlocked;
3477 *pending_return = pending;
3480 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3486 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3489 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3491 if (pending_return ==
NULL)
3538 int timeout_milliseconds,
3544 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3545 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3546 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3547 _dbus_return_val_if_error_is_set (error,
NULL);
3549 #ifdef HAVE_UNIX_FD_PASSING
3553 message->n_unix_fds > 0)
3564 &pending, timeout_milliseconds))
3566 _DBUS_SET_OOM (error);
3570 if (pending ==
NULL)
3613 HAVE_LOCK_CHECK (connection);
3616 _dbus_connection_get_is_connected_unlocked (connection))
3618 _dbus_verbose (
"doing iteration in\n");
3619 HAVE_LOCK_CHECK (connection);
3622 DBUS_ITERATION_DO_READING |
3623 DBUS_ITERATION_DO_WRITING |
3624 DBUS_ITERATION_BLOCK,
3628 HAVE_LOCK_CHECK (connection);
3629 _dbus_verbose (
"middle\n");
3630 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3632 HAVE_LOCK_CHECK (connection);
3651 _dbus_return_if_fail (connection !=
NULL);
3655 status = _dbus_connection_flush_unlocked (connection);
3657 HAVE_LOCK_CHECK (connection);
3659 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3661 _dbus_verbose (
"end\n");
3675 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3676 int timeout_milliseconds,
3691 _dbus_verbose (
"doing dispatch\n");
3697 _dbus_verbose (
"pausing for memory\n");
3698 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3704 if (_dbus_connection_get_is_connected_unlocked (connection))
3706 _dbus_verbose (
"doing iteration\n");
3709 DBUS_ITERATION_DO_READING |
3710 DBUS_ITERATION_DO_WRITING |
3711 DBUS_ITERATION_BLOCK,
3712 timeout_milliseconds);
3716 HAVE_LOCK_CHECK (connection);
3722 progress_possible = connection->
n_incoming != 0 ||
3725 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3731 return progress_possible;
3771 int timeout_milliseconds)
3773 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3774 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3775 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
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,
FALSE);
3816 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3819 HAVE_LOCK_CHECK (connection);
3856 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3858 _dbus_verbose (
"start\n");
3869 _dbus_connection_acquire_dispatch (connection);
3878 check_disconnected_message_arrived_unlocked (connection, message);
3881 if (message ==
NULL)
3882 _dbus_connection_release_dispatch (connection);
3886 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3907 _dbus_return_if_fail (connection !=
NULL);
3908 _dbus_return_if_fail (message !=
NULL);
3918 _dbus_connection_release_dispatch (connection);
3920 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3921 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3923 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3942 _dbus_return_if_fail (connection !=
NULL);
3943 _dbus_return_if_fail (message !=
NULL);
3957 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3962 _dbus_connection_release_dispatch (connection);
3964 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3965 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3966 _dbus_message_trace_ref (message, -1, -1,
3967 "dbus_connection_steal_borrowed_message");
3974 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3976 HAVE_LOCK_CHECK (connection);
3987 _dbus_verbose (
"Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n",
4003 _dbus_message_trace_ref (link->
data, -1, -1,
4004 "_dbus_connection_pop_message_link_unlocked");
4006 check_disconnected_message_arrived_unlocked (connection, link->
data);
4018 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
4022 HAVE_LOCK_CHECK (connection);
4024 link = _dbus_connection_pop_message_link_unlocked (connection);
4030 message = link->
data;
4041 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4044 HAVE_LOCK_CHECK (connection);
4056 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4068 _dbus_message_trace_ref (message_link->
data, -1, -1,
4069 "_dbus_connection_putback_message_link_unlocked");
4097 _dbus_verbose (
"start\n");
4107 _dbus_connection_acquire_dispatch (connection);
4108 HAVE_LOCK_CHECK (connection);
4110 message = _dbus_connection_pop_message_unlocked (connection);
4112 _dbus_verbose (
"Returning popped message %p\n", message);
4114 _dbus_connection_release_dispatch (connection);
4116 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4117 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4132 HAVE_LOCK_CHECK (connection);
4137 _dbus_verbose (
"locking dispatch_mutex\n");
4142 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4151 _dbus_verbose (
"unlocking dispatch_mutex\n");
4168 HAVE_LOCK_CHECK (connection);
4170 _dbus_verbose (
"locking dispatch_mutex\n");
4178 _dbus_verbose (
"unlocking dispatch_mutex\n");
4195 HAVE_LOCK_CHECK (connection);
4213 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4225 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4227 HAVE_LOCK_CHECK (connection);
4231 _dbus_verbose (
"Sending disconnect message\n");
4236 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4252 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4254 HAVE_LOCK_CHECK (connection);
4268 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4269 DISPATCH_STATUS_NAME (status), is_connected);
4279 notify_disconnected_unlocked (connection);
4287 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4300 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4307 HAVE_LOCK_CHECK (connection);
4327 connection_forget_shared_unlocked (connection);
4333 _dbus_verbose (
"Exiting on Disconnected signal\n");
4342 if (changed &&
function)
4344 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4345 connection, new_status,
4346 DISPATCH_STATUS_NAME (new_status));
4347 (* function) (connection, new_status, data);
4385 _dbus_verbose (
"start\n");
4389 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4400 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4433 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4447 const char *v_STRING;
4462 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4478 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
4492 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4496 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4507 expire_link->
data = ret;
4524 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4530 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4579 DBusList *link, *filter_list_copy, *message_link;
4588 _dbus_verbose (
"\n");
4591 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4595 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4604 _dbus_connection_acquire_dispatch (connection);
4605 HAVE_LOCK_CHECK (connection);
4607 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4608 if (message_link ==
NULL)
4612 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4614 _dbus_connection_release_dispatch (connection);
4616 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4618 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4625 message = message_link->
data;
4627 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4652 _dbus_verbose (
"Dispatching a pending reply\n");
4653 complete_pending_call_and_unlock (connection, pending, message);
4657 _dbus_verbose (
"pending call completed in dispatch\n");
4662 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4668 _dbus_connection_release_dispatch (connection);
4669 HAVE_LOCK_CHECK (connection);
4671 _dbus_connection_failed_pop (connection, message_link);
4674 _dbus_connection_update_dispatch_status_and_unlock (connection,
4691 while (link !=
NULL)
4698 _dbus_verbose (
" filter was removed in a callback function\n");
4703 _dbus_verbose (
" running filter on message %p\n", message);
4721 _dbus_verbose (
"No memory\n");
4726 _dbus_verbose (
"filter handled message in dispatch\n");
4733 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4744 HAVE_LOCK_CHECK (connection);
4753 _dbus_verbose (
"object tree handled message in dispatch\n");
4764 _dbus_verbose (
" sending error %s\n",
4770 _dbus_verbose (
"no memory for error string in dispatch\n");
4775 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4782 _dbus_verbose (
"no memory for error string in dispatch\n");
4794 _dbus_verbose (
"no memory for error reply in dispatch\n");
4800 if (expire_link ==
NULL)
4804 _dbus_verbose (
"no memory for error send in dispatch\n");
4808 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4810 if (preallocated ==
NULL)
4817 _dbus_verbose (
"no memory for error send in dispatch\n");
4821 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4829 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4843 _dbus_verbose (
"out of memory\n");
4849 _dbus_connection_putback_message_link_unlocked (connection,
4852 message_link =
NULL;
4857 _dbus_verbose (
" ... done dispatching\n");
4860 _dbus_connection_release_dispatch (connection);
4861 HAVE_LOCK_CHECK (connection);
4863 if (message !=
NULL)
4877 if (message_link !=
NULL)
4880 _dbus_verbose (
"before final status update\n");
4881 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4884 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4962 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4967 add_function, remove_function,
4969 data, free_data_function);
5025 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5030 add_function, remove_function,
5032 data, free_data_function);
5062 _dbus_return_if_fail (connection !=
NULL);
5076 (*old_free_data) (old_data);
5108 _dbus_return_if_fail (connection !=
NULL);
5122 (*old_free_data) (old_data);
5148 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5181 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5190 *fd = _dbus_socket_get_int (s);
5227 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5228 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5263 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5264 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5297 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5298 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5299 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5342 void *old_data =
NULL;
5345 _dbus_return_if_fail (connection !=
NULL);
5349 function, data, free_data_function,
5350 &old_data, &old_free_function);
5353 if (old_free_function !=
NULL)
5354 (* old_free_function) (old_data);
5359 _dbus_connection_get_linux_security_label (
DBusConnection *connection,
5372 result = _dbus_transport_get_linux_security_label (connection->
transport,
5416 char **windows_sid_p)
5420 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5421 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5467 void *old_data =
NULL;
5470 _dbus_return_if_fail (connection !=
NULL);
5474 function, data, free_data_function,
5475 &old_data, &old_free_function);
5478 if (old_free_function !=
NULL)
5479 (* old_free_function) (old_data);
5512 _dbus_return_if_fail (connection !=
NULL);
5540 _dbus_return_if_fail (connection !=
NULL);
5576 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5577 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5590 _dbus_message_filter_unref (filter);
5628 _dbus_return_if_fail (connection !=
NULL);
5629 _dbus_return_if_fail (
function !=
NULL);
5636 while (link !=
NULL)
5638 filter = link->
data;
5640 if (filter->
function ==
function &&
5655 #ifndef DBUS_DISABLE_CHECKS
5658 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added",
5659 function, user_data);
5671 _dbus_message_filter_unref (filter);
5690 _dbus_connection_register_object_path (
DBusConnection *connection,
5697 char **decomposed_path;
5707 (
const char **) decomposed_path, vtable,
5736 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5737 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5738 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5739 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5741 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5768 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5769 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5770 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5771 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5773 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5806 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5807 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5808 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5809 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5811 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5840 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5841 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5842 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5843 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5845 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5870 char **decomposed_path;
5872 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5873 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5874 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5903 char **decomposed_path;
5905 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5906 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5907 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5937 const char *parent_path,
5938 char ***child_entries)
5940 char **decomposed_path;
5942 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5943 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5944 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5945 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5953 (
const char **) decomposed_path,
5998 _dbus_return_if_fail (*slot_p >= 0);
6035 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
6036 _dbus_return_val_if_fail (slot >= 0,
FALSE);
6038 SLOTS_LOCK (connection);
6042 slot, data, free_data_func,
6043 &old_free_func, &old_data);
6045 SLOTS_UNLOCK (connection);
6051 (* old_free_func) (old_data);
6080 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
6081 _dbus_return_val_if_fail (slot >= 0,
NULL);
6083 SLOTS_LOCK (connection);
6089 SLOTS_UNLOCK (connection);
6103 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6118 _dbus_return_if_fail (connection !=
NULL);
6137 _dbus_return_val_if_fail (connection !=
NULL, 0);
6157 _dbus_return_if_fail (connection !=
NULL);
6176 _dbus_return_val_if_fail (connection !=
NULL, 0);
6213 _dbus_return_if_fail (connection !=
NULL);
6232 _dbus_return_val_if_fail (connection !=
NULL, 0);
6255 _dbus_return_if_fail (connection !=
NULL);
6274 _dbus_return_val_if_fail (connection !=
NULL, 0);
6297 _dbus_return_val_if_fail (connection !=
NULL, 0);
6305 #ifdef DBUS_ENABLE_STATS
6321 if (in_messages !=
NULL)
6324 _dbus_transport_get_stats (connection->
transport,
6325 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6327 if (out_messages !=
NULL)
6330 if (out_bytes !=
NULL)
6333 if (out_fds !=
NULL)
6336 if (out_peak_bytes !=
NULL)
6337 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6339 if (out_peak_fds !=
NULL)
6340 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6358 _dbus_return_val_if_fail (connection !=
NULL, 0);
6366 #ifdef DBUS_ENABLE_EMBEDDED_TESTS