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);
348 dbus_uint32_t client_serial);
353 #ifdef DBUS_DISABLE_ASSERT
356 dbus_int32_t old_value;
368 dbus_int32_t old_value;
406 _dbus_verbose (
"UNLOCK\n");
414 RELEASING_LOCK_CHECK (connection);
442 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
484 dbus_uint32_t reply_serial;
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,
919 dbus_uint32_t reply_serial;
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)
1421 dbus_int32_t old_refcount;
1426 HAVE_LOCK_CHECK (connection);
1429 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
1444 dbus_int32_t old_refcount;
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);
1459 static dbus_uint32_t
1460 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1462 dbus_uint32_t serial;
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,
1997 dbus_uint32_t *client_serial)
1999 dbus_uint32_t serial;
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,
2071 dbus_uint32_t *client_serial)
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);
2100 dbus_uint32_t *client_serial)
2107 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2108 if (preallocated ==
NULL)
2114 _dbus_connection_send_preallocated_and_unlock (connection,
2148 dbus_int32_t refcount;
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)
2186 generate_local_error_message (dbus_uint32_t serial,
2212 if (error_msg !=
NULL)
2235 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2236 dbus_uint32_t client_serial)
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);
2263 dbus_uint32_t 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);
2328 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2336 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2342 reply = check_for_reply_unlocked (connection,
2346 _dbus_verbose (
"checked for reply\n");
2348 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2350 complete_pending_call_and_unlock (connection, pending, reply);
2354 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2355 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2381 long start_tv_sec, start_tv_usec;
2382 long tv_sec, tv_usec;
2385 dbus_uint32_t client_serial;
2387 int timeout_milliseconds, elapsed_milliseconds;
2399 _dbus_connection_flush_unlocked (connection);
2413 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2414 timeout_milliseconds,
2416 start_tv_sec, start_tv_usec);
2420 timeout_milliseconds = -1;
2422 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2427 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2434 DBUS_ITERATION_DO_READING |
2435 DBUS_ITERATION_BLOCK,
2436 timeout_milliseconds);
2440 _dbus_verbose (
"top of recheck\n");
2442 HAVE_LOCK_CHECK (connection);
2446 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2453 _dbus_verbose (
"Pending call completed by dispatch\n");
2454 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2461 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2466 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2467 (tv_usec - start_tv_usec) / 1000;
2469 if (!_dbus_connection_get_is_connected_unlocked (connection))
2473 error_msg = generate_local_error_message (client_serial,
2475 "Connection was disconnected before a reply was received");
2478 complete_pending_call_and_unlock (connection, pending, error_msg);
2483 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2484 else if (timeout ==
NULL)
2492 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2494 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2501 DBUS_ITERATION_DO_READING |
2502 DBUS_ITERATION_BLOCK,
2503 timeout_milliseconds - elapsed_milliseconds);
2506 goto recheck_status;
2508 else if (tv_sec < start_tv_sec)
2509 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2510 else if (elapsed_milliseconds < timeout_milliseconds)
2512 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2520 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2522 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2529 DBUS_ITERATION_DO_READING |
2530 DBUS_ITERATION_BLOCK,
2531 timeout_milliseconds - elapsed_milliseconds);
2534 goto recheck_status;
2537 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2538 elapsed_milliseconds);
2543 complete_pending_call_and_unlock (connection, pending,
NULL);
2547 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2548 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2594 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2595 _dbus_return_val_if_error_is_set (error,
NULL);
2597 connection = _dbus_connection_open_internal (address,
2637 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2638 _dbus_return_val_if_error_is_set (error,
NULL);
2640 connection = _dbus_connection_open_internal (address,
2656 dbus_int32_t old_refcount;
2658 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2661 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2668 free_outgoing_message (
void *element,
2687 _dbus_verbose (
"Finalizing connection %p\n", connection);
2714 while (link !=
NULL)
2720 _dbus_message_filter_unref (filter);
2737 free_outgoing_message,
2792 dbus_int32_t old_refcount;
2794 _dbus_return_if_fail (connection !=
NULL);
2799 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2802 if (old_refcount == 1)
2804 #ifndef DBUS_DISABLE_CHECKS
2807 _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",
2809 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2810 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2814 _dbus_connection_last_unref (connection);
2828 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2832 HAVE_LOCK_CHECK (connection);
2834 _dbus_verbose (
"Disconnecting %p\n", connection);
2853 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2856 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2907 _dbus_return_if_fail (connection !=
NULL);
2912 #ifndef DBUS_DISABLE_CHECKS
2917 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2922 _dbus_connection_close_possibly_shared_and_unlock (connection);
2926 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2928 HAVE_LOCK_CHECK (connection);
2950 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2953 res = _dbus_connection_get_is_connected_unlocked (connection);
2972 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3006 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3051 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3081 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3089 #ifdef HAVE_UNIX_FD_PASSING
3121 _dbus_return_if_fail (connection !=
NULL);
3142 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3147 _dbus_connection_preallocate_send_unlocked (connection);
3151 return preallocated;
3167 _dbus_return_if_fail (connection !=
NULL);
3168 _dbus_return_if_fail (preallocated !=
NULL);
3169 _dbus_return_if_fail (connection == preallocated->
connection);
3193 dbus_uint32_t *client_serial)
3195 _dbus_return_if_fail (connection !=
NULL);
3196 _dbus_return_if_fail (preallocated !=
NULL);
3197 _dbus_return_if_fail (message !=
NULL);
3198 _dbus_return_if_fail (preallocated->
connection == connection);
3207 #ifdef HAVE_UNIX_FD_PASSING
3210 message->n_unix_fds > 0)
3221 _dbus_connection_send_preallocated_and_unlock (connection,
3223 message, client_serial);
3227 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3229 dbus_uint32_t *client_serial)
3236 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3237 if (preallocated ==
NULL)
3240 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3277 dbus_uint32_t *serial)
3279 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3280 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3284 #ifdef HAVE_UNIX_FD_PASSING
3287 message->n_unix_fds > 0)
3304 reply_handler_timeout (
void *data)
3319 _dbus_verbose (
"middle\n");
3320 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3323 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3375 int timeout_milliseconds)
3378 dbus_int32_t serial = -1;
3381 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3382 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3383 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3386 *pending_return =
NULL;
3390 #ifdef HAVE_UNIX_FD_PASSING
3393 message->n_unix_fds > 0)
3405 if (!_dbus_connection_get_is_connected_unlocked (connection))
3413 timeout_milliseconds,
3414 reply_handler_timeout);
3416 if (pending ==
NULL)
3426 serial = _dbus_connection_get_next_client_serial (connection);
3437 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3441 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3443 _dbus_connection_detach_pending_call_and_unlock (connection,
3445 goto error_unlocked;
3449 *pending_return = pending;
3452 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3458 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3461 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3463 if (pending_return ==
NULL)
3510 int timeout_milliseconds,
3516 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3517 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3518 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3519 _dbus_return_val_if_error_is_set (error,
NULL);
3521 #ifdef HAVE_UNIX_FD_PASSING
3525 message->n_unix_fds > 0)
3536 &pending, timeout_milliseconds))
3538 _DBUS_SET_OOM (error);
3542 if (pending ==
NULL)
3585 HAVE_LOCK_CHECK (connection);
3588 _dbus_connection_get_is_connected_unlocked (connection))
3590 _dbus_verbose (
"doing iteration in\n");
3591 HAVE_LOCK_CHECK (connection);
3594 DBUS_ITERATION_DO_READING |
3595 DBUS_ITERATION_DO_WRITING |
3596 DBUS_ITERATION_BLOCK,
3600 HAVE_LOCK_CHECK (connection);
3601 _dbus_verbose (
"middle\n");
3602 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3604 HAVE_LOCK_CHECK (connection);
3623 _dbus_return_if_fail (connection !=
NULL);
3627 status = _dbus_connection_flush_unlocked (connection);
3629 HAVE_LOCK_CHECK (connection);
3631 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3633 _dbus_verbose (
"end\n");
3647 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3648 int timeout_milliseconds,
3663 _dbus_verbose (
"doing dispatch\n");
3669 _dbus_verbose (
"pausing for memory\n");
3670 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3676 if (_dbus_connection_get_is_connected_unlocked (connection))
3678 _dbus_verbose (
"doing iteration\n");
3681 DBUS_ITERATION_DO_READING |
3682 DBUS_ITERATION_DO_WRITING |
3683 DBUS_ITERATION_BLOCK,
3684 timeout_milliseconds);
3688 HAVE_LOCK_CHECK (connection);
3694 progress_possible = connection->
n_incoming != 0 ||
3697 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3703 return progress_possible;
3743 int timeout_milliseconds)
3745 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3746 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3747 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3775 int timeout_milliseconds)
3777 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3778 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3779 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3788 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3791 HAVE_LOCK_CHECK (connection);
3828 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3830 _dbus_verbose (
"start\n");
3841 _dbus_connection_acquire_dispatch (connection);
3850 check_disconnected_message_arrived_unlocked (connection, message);
3853 if (message ==
NULL)
3854 _dbus_connection_release_dispatch (connection);
3858 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3879 _dbus_return_if_fail (connection !=
NULL);
3880 _dbus_return_if_fail (message !=
NULL);
3890 _dbus_connection_release_dispatch (connection);
3892 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3893 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3895 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3914 _dbus_return_if_fail (connection !=
NULL);
3915 _dbus_return_if_fail (message !=
NULL);
3929 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3934 _dbus_connection_release_dispatch (connection);
3936 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3937 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3938 _dbus_message_trace_ref (message, -1, -1,
3939 "dbus_connection_steal_borrowed_message");
3946 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3948 HAVE_LOCK_CHECK (connection);
3959 _dbus_verbose (
"Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n",
3975 _dbus_message_trace_ref (link->
data, -1, -1,
3976 "_dbus_connection_pop_message_link_unlocked");
3978 check_disconnected_message_arrived_unlocked (connection, link->
data);
3990 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
3994 HAVE_LOCK_CHECK (connection);
3996 link = _dbus_connection_pop_message_link_unlocked (connection);
4002 message = link->
data;
4013 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4016 HAVE_LOCK_CHECK (connection);
4028 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4040 _dbus_message_trace_ref (message_link->
data, -1, -1,
4041 "_dbus_connection_putback_message_link_unlocked");
4069 _dbus_verbose (
"start\n");
4079 _dbus_connection_acquire_dispatch (connection);
4080 HAVE_LOCK_CHECK (connection);
4082 message = _dbus_connection_pop_message_unlocked (connection);
4084 _dbus_verbose (
"Returning popped message %p\n", message);
4086 _dbus_connection_release_dispatch (connection);
4088 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4089 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4104 HAVE_LOCK_CHECK (connection);
4109 _dbus_verbose (
"locking dispatch_mutex\n");
4114 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4123 _dbus_verbose (
"unlocking dispatch_mutex\n");
4140 HAVE_LOCK_CHECK (connection);
4142 _dbus_verbose (
"locking dispatch_mutex\n");
4150 _dbus_verbose (
"unlocking dispatch_mutex\n");
4167 HAVE_LOCK_CHECK (connection);
4185 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4197 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4199 HAVE_LOCK_CHECK (connection);
4203 _dbus_verbose (
"Sending disconnect message\n");
4208 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4224 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4226 HAVE_LOCK_CHECK (connection);
4240 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4241 DISPATCH_STATUS_NAME (status), is_connected);
4251 notify_disconnected_unlocked (connection);
4259 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4272 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4279 HAVE_LOCK_CHECK (connection);
4299 connection_forget_shared_unlocked (connection);
4305 _dbus_verbose (
"Exiting on Disconnected signal\n");
4314 if (changed &&
function)
4316 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4317 connection, new_status,
4318 DISPATCH_STATUS_NAME (new_status));
4319 (* function) (connection, new_status, data);
4357 _dbus_verbose (
"start\n");
4361 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4372 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4405 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4420 const char *v_STRING = _dbus_string_get_const_data (&uuid);
4425 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4438 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4442 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4453 expire_link->
data = ret;
4470 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4476 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4525 DBusList *link, *filter_list_copy, *message_link;
4528 dbus_int32_t reply_serial;
4534 _dbus_verbose (
"\n");
4537 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4541 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4550 _dbus_connection_acquire_dispatch (connection);
4551 HAVE_LOCK_CHECK (connection);
4553 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4554 if (message_link ==
NULL)
4558 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4560 _dbus_connection_release_dispatch (connection);
4562 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4564 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4571 message = message_link->
data;
4573 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4598 _dbus_verbose (
"Dispatching a pending reply\n");
4599 complete_pending_call_and_unlock (connection, pending, message);
4603 _dbus_verbose (
"pending call completed in dispatch\n");
4608 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4614 _dbus_connection_release_dispatch (connection);
4615 HAVE_LOCK_CHECK (connection);
4617 _dbus_connection_failed_pop (connection, message_link);
4620 _dbus_connection_update_dispatch_status_and_unlock (connection,
4637 while (link !=
NULL)
4644 _dbus_verbose (
" filter was removed in a callback function\n");
4649 _dbus_verbose (
" running filter on message %p\n", message);
4667 _dbus_verbose (
"No memory\n");
4672 _dbus_verbose (
"filter handled message in dispatch\n");
4679 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4690 HAVE_LOCK_CHECK (connection);
4699 _dbus_verbose (
"object tree handled message in dispatch\n");
4710 _dbus_verbose (
" sending error %s\n",
4716 _dbus_verbose (
"no memory for error string in dispatch\n");
4721 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4728 _dbus_verbose (
"no memory for error string in dispatch\n");
4734 _dbus_string_get_const_data (&str));
4740 _dbus_verbose (
"no memory for error reply in dispatch\n");
4746 if (expire_link ==
NULL)
4750 _dbus_verbose (
"no memory for error send in dispatch\n");
4754 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4756 if (preallocated ==
NULL)
4763 _dbus_verbose (
"no memory for error send in dispatch\n");
4767 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4775 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4789 _dbus_verbose (
"out of memory\n");
4795 _dbus_connection_putback_message_link_unlocked (connection,
4798 message_link =
NULL;
4803 _dbus_verbose (
" ... done dispatching\n");
4806 _dbus_connection_release_dispatch (connection);
4807 HAVE_LOCK_CHECK (connection);
4809 if (message !=
NULL)
4823 if (message_link !=
NULL)
4826 _dbus_verbose (
"before final status update\n");
4827 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4830 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4908 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4913 add_function, remove_function,
4915 data, free_data_function);
4971 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4976 add_function, remove_function,
4978 data, free_data_function);
5008 _dbus_return_if_fail (connection !=
NULL);
5022 (*old_free_data) (old_data);
5054 _dbus_return_if_fail (connection !=
NULL);
5068 (*old_free_data) (old_data);
5094 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5126 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5168 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5169 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5204 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5205 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5234 dbus_int32_t *data_size)
5238 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5239 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5240 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5283 void *old_data =
NULL;
5286 _dbus_return_if_fail (connection !=
NULL);
5290 function, data, free_data_function,
5291 &old_data, &old_free_function);
5294 if (old_free_function !=
NULL)
5295 (* old_free_function) (old_data);
5331 char **windows_sid_p)
5335 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5336 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5382 void *old_data =
NULL;
5385 _dbus_return_if_fail (connection !=
NULL);
5389 function, data, free_data_function,
5390 &old_data, &old_free_function);
5393 if (old_free_function !=
NULL)
5394 (* old_free_function) (old_data);
5427 _dbus_return_if_fail (connection !=
NULL);
5455 _dbus_return_if_fail (connection !=
NULL);
5491 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5492 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5505 _dbus_message_filter_unref (filter);
5543 _dbus_return_if_fail (connection !=
NULL);
5544 _dbus_return_if_fail (
function !=
NULL);
5551 while (link !=
NULL)
5553 filter = link->
data;
5555 if (filter->
function ==
function &&
5570 #ifndef DBUS_DISABLE_CHECKS
5573 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5574 function, user_data);
5586 _dbus_message_filter_unref (filter);
5605 _dbus_connection_register_object_path (
DBusConnection *connection,
5612 char **decomposed_path;
5622 (
const char **) decomposed_path, vtable,
5651 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5652 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5653 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5654 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5656 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5683 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5684 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5685 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5686 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5688 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5721 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5722 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5723 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5724 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5726 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5755 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5756 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5757 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5758 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5760 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5785 char **decomposed_path;
5787 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5788 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5789 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5818 char **decomposed_path;
5820 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5821 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5822 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5852 const char *parent_path,
5853 char ***child_entries)
5855 char **decomposed_path;
5857 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5858 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5859 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5860 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5868 (
const char **) decomposed_path,
5913 _dbus_return_if_fail (*slot_p >= 0);
5950 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5951 _dbus_return_val_if_fail (slot >= 0,
FALSE);
5953 SLOTS_LOCK (connection);
5957 slot, data, free_data_func,
5958 &old_free_func, &old_data);
5960 SLOTS_UNLOCK (connection);
5966 (* old_free_func) (old_data);
5995 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
5996 _dbus_return_val_if_fail (slot >= 0,
NULL);
5998 SLOTS_LOCK (connection);
6004 SLOTS_UNLOCK (connection);
6018 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6033 _dbus_return_if_fail (connection !=
NULL);
6052 _dbus_return_val_if_fail (connection !=
NULL, 0);
6072 _dbus_return_if_fail (connection !=
NULL);
6091 _dbus_return_val_if_fail (connection !=
NULL, 0);
6128 _dbus_return_if_fail (connection !=
NULL);
6147 _dbus_return_val_if_fail (connection !=
NULL, 0);
6170 _dbus_return_if_fail (connection !=
NULL);
6189 _dbus_return_val_if_fail (connection !=
NULL, 0);
6212 _dbus_return_val_if_fail (connection !=
NULL, 0);
6220 #ifdef DBUS_ENABLE_STATS
6223 dbus_uint32_t *in_messages,
6224 dbus_uint32_t *in_bytes,
6225 dbus_uint32_t *in_fds,
6226 dbus_uint32_t *in_peak_bytes,
6227 dbus_uint32_t *in_peak_fds,
6228 dbus_uint32_t *out_messages,
6229 dbus_uint32_t *out_bytes,
6230 dbus_uint32_t *out_fds,
6231 dbus_uint32_t *out_peak_bytes,
6232 dbus_uint32_t *out_peak_fds)
6236 if (in_messages !=
NULL)
6239 _dbus_transport_get_stats (connection->
transport,
6240 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6242 if (out_messages !=
NULL)
6245 if (out_bytes !=
NULL)
6248 if (out_fds !=
NULL)
6251 if (out_peak_bytes !=
NULL)
6252 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6254 if (out_peak_fds !=
NULL)
6255 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6273 _dbus_return_val_if_fail (connection !=
NULL, 0);
6281 #ifdef DBUS_ENABLE_EMBEDDED_TESTS