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" : \
206 #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);
219 #define _dbus_connection_trace_ref(c,o,n,w) \
254 #if HAVE_DECL_MSG_NOSIGNAL
336 #ifndef DBUS_DISABLE_CHECKS
340 #ifndef DBUS_DISABLE_CHECKS
346 static void _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
348 static void _dbus_connection_last_unref (
DBusConnection *connection);
349 static void _dbus_connection_acquire_dispatch (
DBusConnection *connection);
350 static void _dbus_connection_release_dispatch (
DBusConnection *connection);
352 static void _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection);
360 #ifdef DBUS_DISABLE_ASSERT
413 _dbus_verbose (
"UNLOCK\n");
421 RELEASING_LOCK_CHECK (connection);
449 #ifdef DBUS_BUILD_TESTS
498 message = link->
data;
502 if (reply_serial != 0)
520 _dbus_connection_wakeup_mainloop (connection);
522 _dbus_verbose (
"Message %p (%s %s %s %s '%s' reply to %u) added to incoming queue %p, %d incoming\n",
539 _dbus_message_trace_ref (message, -1, -1,
540 "_dbus_conection_queue_received_message_link");
555 HAVE_LOCK_CHECK (connection);
561 _dbus_connection_wakeup_mainloop (connection);
563 _dbus_message_trace_ref (link->
data, -1, -1,
564 "_dbus_connection_queue_synthesized_message_link");
566 _dbus_verbose (
"Synthesized message %p added to incoming queue %p, %d incoming\n",
581 HAVE_LOCK_CHECK (connection);
599 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
618 HAVE_LOCK_CHECK (connection);
637 HAVE_LOCK_CHECK (connection);
654 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from outgoing queue %p, %d left to send\n",
697 HAVE_LOCK_CHECK (connection);
720 retval = (* add_function) (connection->
watches, watch);
721 else if (remove_function)
724 (* remove_function) (connection->
watches, watch);
729 (* toggle_function) (connection->
watches, watch, enabled);
753 return protected_change_watch (connection, watch,
771 protected_change_watch (connection, watch,
794 protected_change_watch (connection, watch,
821 HAVE_LOCK_CHECK (connection);
844 retval = (* add_function) (connection->
timeouts, timeout);
845 else if (remove_function)
848 (* remove_function) (connection->
timeouts, timeout);
853 (* toggle_function) (connection->
timeouts, timeout, enabled);
877 return protected_change_timeout (connection, timeout,
895 protected_change_timeout (connection, timeout,
916 protected_change_timeout (connection, timeout,
923 _dbus_connection_attach_pending_call_unlocked (
DBusConnection *connection,
929 HAVE_LOCK_CHECK (connection);
949 HAVE_LOCK_CHECK (connection);
961 HAVE_LOCK_CHECK (connection);
968 HAVE_LOCK_CHECK (connection);
974 free_pending_call_on_hash_removal (
void *data)
986 HAVE_LOCK_CHECK (connection);
1008 _dbus_connection_detach_pending_call_unlocked (
DBusConnection *connection,
1019 _dbus_connection_detach_pending_call_and_unlock (
DBusConnection *connection,
1055 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
1069 int timeout_milliseconds)
1073 HAVE_LOCK_CHECK (connection);
1081 _dbus_verbose (
"locking io_path_mutex\n");
1084 _dbus_verbose (
"start connection->io_path_acquired = %d timeout = %d\n",
1087 we_acquired =
FALSE;
1091 if (timeout_milliseconds != -1)
1093 _dbus_verbose (
"waiting %d for IO path to be acquirable\n",
1094 timeout_milliseconds);
1098 timeout_milliseconds))
1114 _dbus_verbose (
"waiting for IO path to be acquirable\n");
1127 _dbus_verbose (
"end connection->io_path_acquired = %d we_acquired = %d\n",
1130 _dbus_verbose (
"unlocking io_path_mutex\n");
1135 HAVE_LOCK_CHECK (connection);
1152 HAVE_LOCK_CHECK (connection);
1154 _dbus_verbose (
"locking io_path_mutex\n");
1159 _dbus_verbose (
"start connection->io_path_acquired = %d\n",
1165 _dbus_verbose (
"unlocking io_path_mutex\n");
1208 int timeout_milliseconds)
1210 _dbus_verbose (
"start\n");
1212 HAVE_LOCK_CHECK (connection);
1215 flags &= ~DBUS_ITERATION_DO_WRITING;
1217 if (_dbus_connection_acquire_io_path (connection,
1218 (flags & DBUS_ITERATION_BLOCK) ? timeout_milliseconds : 0))
1220 HAVE_LOCK_CHECK (connection);
1224 _dbus_verbose (
"pending call completed while acquiring I/O path");
1226 else if ( (pending !=
NULL) &&
1227 _dbus_connection_peek_for_reply_unlocked (connection,
1230 _dbus_verbose (
"pending call completed while acquiring I/O path (reply found in queue)");
1235 flags, timeout_milliseconds);
1238 _dbus_connection_release_io_path (connection);
1241 HAVE_LOCK_CHECK (connection);
1243 _dbus_verbose (
"end\n");
1269 pending_replies =
NULL;
1270 timeout_list =
NULL;
1271 disconnect_link =
NULL;
1272 disconnect_message =
NULL;
1273 outgoing_counter =
NULL;
1277 if (watch_list ==
NULL)
1281 if (timeout_list ==
NULL)
1288 if (pending_replies ==
NULL)
1292 if (connection ==
NULL)
1323 if (disconnect_message ==
NULL)
1327 if (disconnect_link ==
NULL)
1331 if (outgoing_counter ==
NULL)
1335 if (objects ==
NULL)
1338 if (_dbus_modify_sigpipe)
1344 connection->
watches = watch_list;
1345 connection->
timeouts = timeout_list;
1350 connection->
objects = objects;
1357 #ifndef DBUS_DISABLE_CHECKS
1380 _dbus_connection_trace_ref (connection, 0, 1,
"new_for_transport");
1384 if (disconnect_message !=
NULL)
1387 if (disconnect_link !=
NULL)
1390 if (connection !=
NULL)
1400 if (pending_replies)
1409 if (outgoing_counter)
1433 HAVE_LOCK_CHECK (connection);
1436 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
1453 HAVE_LOCK_CHECK (connection);
1459 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
1462 if (old_refcount == 1)
1463 _dbus_connection_last_unref (connection);
1467 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1494 unsigned int condition,
1503 _dbus_verbose (
"start\n");
1507 if (!_dbus_connection_acquire_io_path (connection, 1))
1514 HAVE_LOCK_CHECK (connection);
1518 _dbus_connection_release_io_path (connection);
1520 HAVE_LOCK_CHECK (connection);
1522 _dbus_verbose (
"middle\n");
1524 status = _dbus_connection_get_dispatch_status_unlocked (connection);
1527 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
1529 _dbus_verbose (
"end\n");
1555 shared_connections_shutdown (
void *data)
1573 close_connection_on_shutdown (connection);
1583 shared_connections =
NULL;
1585 if (shared_connections_no_guid !=
NULL)
1589 while (connection !=
NULL)
1592 close_connection_on_shutdown (connection);
1598 shared_connections_no_guid =
NULL;
1607 _dbus_verbose (
"checking for existing connection\n");
1613 if (shared_connections ==
NULL)
1615 _dbus_verbose (
"creating shared_connections hash table\n");
1620 if (shared_connections ==
NULL)
1629 shared_connections =
NULL;
1634 _dbus_verbose (
" successfully created shared_connections\n");
1669 if (_dbus_connection_get_is_connected_unlocked (connection))
1672 *result = connection;
1673 _dbus_verbose (
"looked up existing connection to server guid %s\n",
1678 _dbus_verbose (
"looked up existing connection to server guid %s but it was disconnected so ignoring it\n",
1695 char *guid_in_connection;
1697 HAVE_LOCK_CHECK (connection);
1727 if (guid_key ==
NULL)
1731 if (guid_in_connection ==
NULL)
1741 guid_key, connection))
1751 _dbus_verbose (
"stored connection to %s to be shared\n",
1764 HAVE_LOCK_CHECK (connection);
1773 _dbus_verbose (
"dropping connection to %s out of the shared table\n",
1803 if (transport ==
NULL)
1805 _DBUS_ASSERT_ERROR_IS_SET (error);
1813 if (connection ==
NULL)
1815 _DBUS_SET_OOM (error);
1819 #ifndef DBUS_DISABLE_CHECKS
1838 _dbus_connection_open_internal (
const char *address,
1848 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1850 _dbus_verbose (
"opening %s connection to: %s\n",
1851 shared ?
"shared" :
"private", address);
1856 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1860 for (i = 0; i < len; i++)
1864 if (!connection_lookup_shared (entries[i], &connection))
1865 _DBUS_SET_OOM (&tmp_error);
1868 if (connection ==
NULL)
1870 connection = connection_try_from_address_entry (entries[i],
1873 if (connection !=
NULL && shared)
1884 if (!connection_record_shared_unlocked (connection, guid))
1886 _DBUS_SET_OOM (&tmp_error);
1887 _dbus_connection_close_possibly_shared_and_unlock (connection);
1899 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1907 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1908 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1910 if (connection ==
NULL)
1912 _DBUS_ASSERT_ERROR_IS_SET (&first_error);
1937 _dbus_connection_close_possibly_shared_and_unlock (connection);
1941 _dbus_connection_preallocate_send_unlocked (
DBusConnection *connection)
1945 HAVE_LOCK_CHECK (connection);
1950 if (preallocated ==
NULL)
1965 return preallocated;
1977 _dbus_connection_send_preallocated_unlocked_no_update (
DBusConnection *connection,
1994 preallocated =
NULL;
2000 _dbus_verbose (
"Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n",
2021 serial = _dbus_connection_get_next_client_serial (connection);
2024 *client_serial = serial;
2032 _dbus_verbose (
"Message %p serial is %u\n",
2042 DBUS_ITERATION_DO_WRITING,
2047 _dbus_connection_wakeup_mainloop (connection);
2051 _dbus_connection_send_preallocated_and_unlock (
DBusConnection *connection,
2058 HAVE_LOCK_CHECK (connection);
2060 _dbus_connection_send_preallocated_unlocked_no_update (connection,
2062 message, client_serial);
2064 _dbus_verbose (
"middle\n");
2065 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2068 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2090 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2091 if (preallocated ==
NULL)
2097 _dbus_connection_send_preallocated_and_unlock (connection,
2140 _dbus_connection_close_possibly_shared_and_unlock (connection);
2156 _dbus_memory_pause_based_on_timeout (
int timeout_milliseconds)
2158 if (timeout_milliseconds == -1)
2160 else if (timeout_milliseconds < 100)
2162 else if (timeout_milliseconds <= 1000)
2195 if (error_msg !=
NULL)
2218 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2222 HAVE_LOCK_CHECK (connection);
2226 while (link !=
NULL)
2232 _dbus_verbose (
"%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial);
2250 HAVE_LOCK_CHECK (connection);
2254 while (link !=
NULL)
2271 connection_timeout_and_complete_all_pending_calls_unlocked (
DBusConnection *connection)
2301 HAVE_LOCK_CHECK (connection);
2311 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2319 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2325 reply = check_for_reply_unlocked (connection,
2329 _dbus_verbose (
"checked for reply\n");
2331 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2333 complete_pending_call_and_unlock (connection, pending, reply);
2337 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2338 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2364 long start_tv_sec, start_tv_usec;
2365 long tv_sec, tv_usec;
2370 int timeout_milliseconds, elapsed_milliseconds;
2382 _dbus_connection_flush_unlocked (connection);
2396 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2397 timeout_milliseconds,
2399 start_tv_sec, start_tv_usec);
2403 timeout_milliseconds = -1;
2405 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2410 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2417 DBUS_ITERATION_DO_READING |
2418 DBUS_ITERATION_BLOCK,
2419 timeout_milliseconds);
2423 _dbus_verbose (
"top of recheck\n");
2425 HAVE_LOCK_CHECK (connection);
2429 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2436 _dbus_verbose (
"Pending call completed by dispatch\n");
2437 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2444 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2449 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2450 (tv_usec - start_tv_usec) / 1000;
2452 if (!_dbus_connection_get_is_connected_unlocked (connection))
2456 error_msg = generate_local_error_message (client_serial,
2458 "Connection was disconnected before a reply was received");
2461 complete_pending_call_and_unlock (connection, pending, error_msg);
2466 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2467 else if (timeout ==
NULL)
2475 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2477 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2484 DBUS_ITERATION_DO_READING |
2485 DBUS_ITERATION_BLOCK,
2486 timeout_milliseconds - elapsed_milliseconds);
2489 goto recheck_status;
2491 else if (tv_sec < start_tv_sec)
2492 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2493 else if (elapsed_milliseconds < timeout_milliseconds)
2495 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2503 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2505 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2512 DBUS_ITERATION_DO_READING |
2513 DBUS_ITERATION_BLOCK,
2514 timeout_milliseconds - elapsed_milliseconds);
2517 goto recheck_status;
2520 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2521 elapsed_milliseconds);
2526 complete_pending_call_and_unlock (connection, pending,
NULL);
2530 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2531 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2555 DBusPendingFdsChangeFunction callback,
2604 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2605 _dbus_return_val_if_error_is_set (error,
NULL);
2607 connection = _dbus_connection_open_internal (address,
2647 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2648 _dbus_return_val_if_error_is_set (error,
NULL);
2650 connection = _dbus_connection_open_internal (address,
2668 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2671 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2678 free_outgoing_message (
void *element,
2697 _dbus_verbose (
"Finalizing connection %p\n", connection);
2723 while (link !=
NULL)
2729 _dbus_message_filter_unref (filter);
2746 free_outgoing_message,
2803 _dbus_return_if_fail (connection !=
NULL);
2808 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2811 if (old_refcount == 1)
2813 #ifndef DBUS_DISABLE_CHECKS
2816 _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",
2818 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2819 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2823 _dbus_connection_last_unref (connection);
2837 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2841 HAVE_LOCK_CHECK (connection);
2843 _dbus_verbose (
"Disconnecting %p\n", connection);
2862 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2865 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2916 _dbus_return_if_fail (connection !=
NULL);
2921 #ifndef DBUS_DISABLE_CHECKS
2926 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2931 _dbus_connection_close_possibly_shared_and_unlock (connection);
2935 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2937 HAVE_LOCK_CHECK (connection);
2959 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2962 res = _dbus_connection_get_is_connected_unlocked (connection);
2981 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3015 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3060 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3090 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3098 #ifdef HAVE_UNIX_FD_PASSING
3130 _dbus_return_if_fail (connection !=
NULL);
3151 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3156 _dbus_connection_preallocate_send_unlocked (connection);
3160 return preallocated;
3176 _dbus_return_if_fail (connection !=
NULL);
3177 _dbus_return_if_fail (preallocated !=
NULL);
3178 _dbus_return_if_fail (connection == preallocated->
connection);
3204 _dbus_return_if_fail (connection !=
NULL);
3205 _dbus_return_if_fail (preallocated !=
NULL);
3206 _dbus_return_if_fail (message !=
NULL);
3207 _dbus_return_if_fail (preallocated->
connection == connection);
3216 #ifdef HAVE_UNIX_FD_PASSING
3219 message->n_unix_fds > 0)
3230 _dbus_connection_send_preallocated_and_unlock (connection,
3232 message, client_serial);
3236 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3245 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3246 if (preallocated ==
NULL)
3249 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3288 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3289 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3293 #ifdef HAVE_UNIX_FD_PASSING
3296 message->n_unix_fds > 0)
3313 reply_handler_timeout (
void *data)
3328 _dbus_verbose (
"middle\n");
3329 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3332 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3384 int timeout_milliseconds)
3390 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3391 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3392 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3395 *pending_return =
NULL;
3399 #ifdef HAVE_UNIX_FD_PASSING
3402 message->n_unix_fds > 0)
3414 if (!_dbus_connection_get_is_connected_unlocked (connection))
3422 timeout_milliseconds,
3423 reply_handler_timeout);
3425 if (pending ==
NULL)
3435 serial = _dbus_connection_get_next_client_serial (connection);
3446 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3450 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3452 _dbus_connection_detach_pending_call_and_unlock (connection,
3454 goto error_unlocked;
3458 *pending_return = pending;
3461 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3467 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3470 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3472 if (pending_return ==
NULL)
3519 int timeout_milliseconds,
3525 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3526 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3527 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3528 _dbus_return_val_if_error_is_set (error,
NULL);
3530 #ifdef HAVE_UNIX_FD_PASSING
3534 message->n_unix_fds > 0)
3545 &pending, timeout_milliseconds))
3547 _DBUS_SET_OOM (error);
3551 if (pending ==
NULL)
3594 HAVE_LOCK_CHECK (connection);
3597 _dbus_connection_get_is_connected_unlocked (connection))
3599 _dbus_verbose (
"doing iteration in\n");
3600 HAVE_LOCK_CHECK (connection);
3603 DBUS_ITERATION_DO_READING |
3604 DBUS_ITERATION_DO_WRITING |
3605 DBUS_ITERATION_BLOCK,
3609 HAVE_LOCK_CHECK (connection);
3610 _dbus_verbose (
"middle\n");
3611 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3613 HAVE_LOCK_CHECK (connection);
3632 _dbus_return_if_fail (connection !=
NULL);
3636 status = _dbus_connection_flush_unlocked (connection);
3638 HAVE_LOCK_CHECK (connection);
3640 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3642 _dbus_verbose (
"end\n");
3656 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3657 int timeout_milliseconds,
3672 _dbus_verbose (
"doing dispatch\n");
3678 _dbus_verbose (
"pausing for memory\n");
3679 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3685 if (_dbus_connection_get_is_connected_unlocked (connection))
3687 _dbus_verbose (
"doing iteration\n");
3690 DBUS_ITERATION_DO_READING |
3691 DBUS_ITERATION_DO_WRITING |
3692 DBUS_ITERATION_BLOCK,
3693 timeout_milliseconds);
3697 HAVE_LOCK_CHECK (connection);
3703 progress_possible = connection->
n_incoming != 0 ||
3706 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3712 return progress_possible;
3752 int timeout_milliseconds)
3754 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3755 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3756 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3784 int timeout_milliseconds)
3786 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3787 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3788 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3797 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3800 HAVE_LOCK_CHECK (connection);
3837 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3839 _dbus_verbose (
"start\n");
3850 _dbus_connection_acquire_dispatch (connection);
3859 check_disconnected_message_arrived_unlocked (connection, message);
3862 if (message ==
NULL)
3863 _dbus_connection_release_dispatch (connection);
3867 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3888 _dbus_return_if_fail (connection !=
NULL);
3889 _dbus_return_if_fail (message !=
NULL);
3899 _dbus_connection_release_dispatch (connection);
3901 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3902 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3904 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3923 _dbus_return_if_fail (connection !=
NULL);
3924 _dbus_return_if_fail (message !=
NULL);
3938 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3943 _dbus_connection_release_dispatch (connection);
3945 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3946 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3947 _dbus_message_trace_ref (message, -1, -1,
3948 "dbus_connection_steal_borrowed_message");
3955 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3957 HAVE_LOCK_CHECK (connection);
3968 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from incoming queue %p, %d incoming\n",
3983 _dbus_message_trace_ref (link->
data, -1, -1,
3984 "_dbus_connection_pop_message_link_unlocked");
3986 check_disconnected_message_arrived_unlocked (connection, link->
data);
3998 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
4002 HAVE_LOCK_CHECK (connection);
4004 link = _dbus_connection_pop_message_link_unlocked (connection);
4010 message = link->
data;
4021 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4024 HAVE_LOCK_CHECK (connection);
4036 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4048 _dbus_message_trace_ref (message_link->
data, -1, -1,
4049 "_dbus_connection_putback_message_link_unlocked");
4077 _dbus_verbose (
"start\n");
4087 _dbus_connection_acquire_dispatch (connection);
4088 HAVE_LOCK_CHECK (connection);
4090 message = _dbus_connection_pop_message_unlocked (connection);
4092 _dbus_verbose (
"Returning popped message %p\n", message);
4094 _dbus_connection_release_dispatch (connection);
4096 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4097 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4112 HAVE_LOCK_CHECK (connection);
4117 _dbus_verbose (
"locking dispatch_mutex\n");
4122 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4131 _dbus_verbose (
"unlocking dispatch_mutex\n");
4148 HAVE_LOCK_CHECK (connection);
4150 _dbus_verbose (
"locking dispatch_mutex\n");
4158 _dbus_verbose (
"unlocking dispatch_mutex\n");
4175 HAVE_LOCK_CHECK (connection);
4193 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4205 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4207 HAVE_LOCK_CHECK (connection);
4211 _dbus_verbose (
"Sending disconnect message\n");
4216 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4232 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4234 HAVE_LOCK_CHECK (connection);
4248 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4249 DISPATCH_STATUS_NAME (status), is_connected);
4259 notify_disconnected_unlocked (connection);
4267 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4280 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4287 HAVE_LOCK_CHECK (connection);
4307 connection_forget_shared_unlocked (connection);
4313 _dbus_verbose (
"Exiting on Disconnected signal\n");
4322 if (changed &&
function)
4324 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4325 connection, new_status,
4326 DISPATCH_STATUS_NAME (new_status));
4327 (* function) (connection, new_status, data);
4365 _dbus_verbose (
"start\n");
4369 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4380 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4413 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4433 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4446 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4450 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4461 expire_link->
data = ret;
4478 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4484 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4533 DBusList *link, *filter_list_copy, *message_link;
4542 _dbus_verbose (
"\n");
4545 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4549 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4558 _dbus_connection_acquire_dispatch (connection);
4559 HAVE_LOCK_CHECK (connection);
4561 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4562 if (message_link ==
NULL)
4566 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4568 _dbus_connection_release_dispatch (connection);
4570 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4572 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4579 message = message_link->
data;
4581 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4606 _dbus_verbose (
"Dispatching a pending reply\n");
4607 complete_pending_call_and_unlock (connection, pending, message);
4611 _dbus_verbose (
"pending call completed in dispatch\n");
4616 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4622 _dbus_connection_release_dispatch (connection);
4623 HAVE_LOCK_CHECK (connection);
4625 _dbus_connection_failed_pop (connection, message_link);
4628 _dbus_connection_update_dispatch_status_and_unlock (connection,
4645 while (link !=
NULL)
4652 _dbus_verbose (
" filter was removed in a callback function\n");
4657 _dbus_verbose (
" running filter on message %p\n", message);
4675 _dbus_verbose (
"No memory\n");
4680 _dbus_verbose (
"filter handled message in dispatch\n");
4687 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4698 HAVE_LOCK_CHECK (connection);
4707 _dbus_verbose (
"object tree handled message in dispatch\n");
4718 _dbus_verbose (
" sending error %s\n",
4724 _dbus_verbose (
"no memory for error string in dispatch\n");
4729 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4736 _dbus_verbose (
"no memory for error string in dispatch\n");
4748 _dbus_verbose (
"no memory for error reply in dispatch\n");
4754 if (expire_link ==
NULL)
4758 _dbus_verbose (
"no memory for error send in dispatch\n");
4762 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4764 if (preallocated ==
NULL)
4771 _dbus_verbose (
"no memory for error send in dispatch\n");
4775 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4783 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4797 _dbus_verbose (
"out of memory\n");
4803 _dbus_connection_putback_message_link_unlocked (connection,
4806 message_link =
NULL;
4811 _dbus_verbose (
" ... done dispatching\n");
4814 _dbus_connection_release_dispatch (connection);
4815 HAVE_LOCK_CHECK (connection);
4817 if (message !=
NULL)
4831 if (message_link !=
NULL)
4834 _dbus_verbose (
"before final status update\n");
4835 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4838 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4916 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4921 add_function, remove_function,
4923 data, free_data_function);
4979 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4984 add_function, remove_function,
4986 data, free_data_function);
5016 _dbus_return_if_fail (connection !=
NULL);
5030 (*old_free_data) (old_data);
5062 _dbus_return_if_fail (connection !=
NULL);
5076 (*old_free_data) (old_data);
5102 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5134 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5176 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5177 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5212 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5213 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5245 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5246 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5247 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5290 void *old_data =
NULL;
5293 _dbus_return_if_fail (connection !=
NULL);
5297 function, data, free_data_function,
5298 &old_data, &old_free_function);
5301 if (old_free_function !=
NULL)
5302 (* old_free_function) (old_data);
5338 char **windows_sid_p)
5342 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5343 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5389 void *old_data =
NULL;
5392 _dbus_return_if_fail (connection !=
NULL);
5396 function, data, free_data_function,
5397 &old_data, &old_free_function);
5400 if (old_free_function !=
NULL)
5401 (* old_free_function) (old_data);
5434 _dbus_return_if_fail (connection !=
NULL);
5462 _dbus_return_if_fail (connection !=
NULL);
5498 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5499 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5512 _dbus_message_filter_unref (filter);
5550 _dbus_return_if_fail (connection !=
NULL);
5551 _dbus_return_if_fail (
function !=
NULL);
5558 while (link !=
NULL)
5560 filter = link->
data;
5562 if (filter->
function ==
function &&
5577 #ifndef DBUS_DISABLE_CHECKS
5580 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5581 function, user_data);
5593 _dbus_message_filter_unref (filter);
5612 _dbus_connection_register_object_path (
DBusConnection *connection,
5619 char **decomposed_path;
5629 (
const char **) decomposed_path, vtable,
5658 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5659 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5660 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5661 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5663 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5690 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5691 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5692 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5693 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5695 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5728 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5729 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5730 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5731 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5733 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5762 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5763 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5764 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5765 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5767 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5792 char **decomposed_path;
5794 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5795 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5796 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5825 char **decomposed_path;
5827 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5828 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5829 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5859 const char *parent_path,
5860 char ***child_entries)
5862 char **decomposed_path;
5864 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5865 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5866 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5867 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5875 (
const char **) decomposed_path,
5921 _dbus_return_if_fail (*slot_p >= 0);
5958 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5959 _dbus_return_val_if_fail (slot >= 0,
FALSE);
5961 SLOTS_LOCK (connection);
5965 slot, data, free_data_func,
5966 &old_free_func, &old_data);
5968 SLOTS_UNLOCK (connection);
5974 (* old_free_func) (old_data);
6003 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
6005 SLOTS_LOCK (connection);
6011 SLOTS_UNLOCK (connection);
6025 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6040 _dbus_return_if_fail (connection !=
NULL);
6059 _dbus_return_val_if_fail (connection !=
NULL, 0);
6079 _dbus_return_if_fail (connection !=
NULL);
6098 _dbus_return_val_if_fail (connection !=
NULL, 0);
6135 _dbus_return_if_fail (connection !=
NULL);
6154 _dbus_return_val_if_fail (connection !=
NULL, 0);
6177 _dbus_return_if_fail (connection !=
NULL);
6196 _dbus_return_val_if_fail (connection !=
NULL, 0);
6219 _dbus_return_val_if_fail (connection !=
NULL, 0);
6227 #ifdef DBUS_ENABLE_STATS
6243 if (in_messages !=
NULL)
6246 _dbus_transport_get_stats (connection->
transport,
6247 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6249 if (out_messages !=
NULL)
6252 if (out_bytes !=
NULL)
6255 if (out_fds !=
NULL)
6258 if (out_peak_bytes !=
NULL)
6259 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6261 if (out_peak_fds !=
NULL)
6262 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6280 _dbus_return_val_if_fail (connection !=
NULL, 0);
6288 #ifdef DBUS_BUILD_TESTS