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)
1578 close_connection_on_shutdown (connection);
1589 shared_connections =
NULL;
1591 if (shared_connections_no_guid !=
NULL)
1595 while (connection !=
NULL)
1598 close_connection_on_shutdown (connection);
1605 shared_connections_no_guid =
NULL;
1614 _dbus_verbose (
"checking for existing connection\n");
1625 if (shared_connections ==
NULL)
1627 _dbus_verbose (
"creating shared_connections hash table\n");
1632 if (shared_connections ==
NULL)
1641 shared_connections =
NULL;
1646 _dbus_verbose (
" successfully created shared_connections\n");
1681 if (_dbus_connection_get_is_connected_unlocked (connection))
1684 *result = connection;
1685 _dbus_verbose (
"looked up existing connection to server guid %s\n",
1690 _dbus_verbose (
"looked up existing connection to server guid %s but it was disconnected so ignoring it\n",
1707 char *guid_in_connection;
1709 HAVE_LOCK_CHECK (connection);
1740 if (guid_key ==
NULL)
1744 if (guid_in_connection ==
NULL)
1760 guid_key, connection))
1770 _dbus_verbose (
"stored connection to %s to be shared\n",
1783 HAVE_LOCK_CHECK (connection);
1797 _dbus_verbose (
"dropping connection to %s out of the shared table\n",
1827 if (transport ==
NULL)
1829 _DBUS_ASSERT_ERROR_IS_SET (error);
1837 if (connection ==
NULL)
1839 _DBUS_SET_OOM (error);
1843 #ifndef DBUS_DISABLE_CHECKS
1862 _dbus_connection_open_internal (
const char *address,
1872 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1874 _dbus_verbose (
"opening %s connection to: %s\n",
1875 shared ?
"shared" :
"private", address);
1880 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1884 for (i = 0; i < len; i++)
1888 if (!connection_lookup_shared (entries[i], &connection))
1889 _DBUS_SET_OOM (&tmp_error);
1892 if (connection ==
NULL)
1894 connection = connection_try_from_address_entry (entries[i],
1897 if (connection !=
NULL && shared)
1908 if (!connection_record_shared_unlocked (connection, guid))
1910 _DBUS_SET_OOM (&tmp_error);
1911 _dbus_connection_close_possibly_shared_and_unlock (connection);
1923 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1931 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1932 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1934 if (connection ==
NULL)
1936 _DBUS_ASSERT_ERROR_IS_SET (&first_error);
1961 _dbus_connection_close_possibly_shared_and_unlock (connection);
1965 _dbus_connection_preallocate_send_unlocked (
DBusConnection *connection)
1969 HAVE_LOCK_CHECK (connection);
1974 if (preallocated ==
NULL)
1989 return preallocated;
2001 _dbus_connection_send_preallocated_unlocked_no_update (
DBusConnection *connection,
2018 preallocated =
NULL;
2024 _dbus_verbose (
"Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n",
2045 serial = _dbus_connection_get_next_client_serial (connection);
2048 *client_serial = serial;
2056 _dbus_verbose (
"Message %p serial is %u\n",
2066 DBUS_ITERATION_DO_WRITING,
2071 _dbus_connection_wakeup_mainloop (connection);
2075 _dbus_connection_send_preallocated_and_unlock (
DBusConnection *connection,
2082 HAVE_LOCK_CHECK (connection);
2084 _dbus_connection_send_preallocated_unlocked_no_update (connection,
2086 message, client_serial);
2088 _dbus_verbose (
"middle\n");
2089 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2092 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2114 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2115 if (preallocated ==
NULL)
2121 _dbus_connection_send_preallocated_and_unlock (connection,
2164 _dbus_connection_close_possibly_shared_and_unlock (connection);
2180 _dbus_memory_pause_based_on_timeout (
int timeout_milliseconds)
2182 if (timeout_milliseconds == -1)
2184 else if (timeout_milliseconds < 100)
2186 else if (timeout_milliseconds <= 1000)
2219 if (error_msg !=
NULL)
2242 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2246 HAVE_LOCK_CHECK (connection);
2250 while (link !=
NULL)
2256 _dbus_verbose (
"%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial);
2274 HAVE_LOCK_CHECK (connection);
2278 while (link !=
NULL)
2295 connection_timeout_and_complete_all_pending_calls_unlocked (
DBusConnection *connection)
2325 HAVE_LOCK_CHECK (connection);
2335 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2343 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2349 reply = check_for_reply_unlocked (connection,
2353 _dbus_verbose (
"checked for reply\n");
2355 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2357 complete_pending_call_and_unlock (connection, pending, reply);
2361 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2362 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2388 long start_tv_sec, start_tv_usec;
2389 long tv_sec, tv_usec;
2394 int timeout_milliseconds, elapsed_milliseconds;
2406 _dbus_connection_flush_unlocked (connection);
2420 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2421 timeout_milliseconds,
2423 start_tv_sec, start_tv_usec);
2427 timeout_milliseconds = -1;
2429 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2434 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2441 DBUS_ITERATION_DO_READING |
2442 DBUS_ITERATION_BLOCK,
2443 timeout_milliseconds);
2447 _dbus_verbose (
"top of recheck\n");
2449 HAVE_LOCK_CHECK (connection);
2453 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2460 _dbus_verbose (
"Pending call completed by dispatch\n");
2461 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2468 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2473 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2474 (tv_usec - start_tv_usec) / 1000;
2476 if (!_dbus_connection_get_is_connected_unlocked (connection))
2480 error_msg = generate_local_error_message (client_serial,
2482 "Connection was disconnected before a reply was received");
2485 complete_pending_call_and_unlock (connection, pending, error_msg);
2490 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2491 else if (timeout ==
NULL)
2499 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2501 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2508 DBUS_ITERATION_DO_READING |
2509 DBUS_ITERATION_BLOCK,
2510 timeout_milliseconds - elapsed_milliseconds);
2513 goto recheck_status;
2515 else if (tv_sec < start_tv_sec)
2516 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2517 else if (elapsed_milliseconds < timeout_milliseconds)
2519 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2527 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2529 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2536 DBUS_ITERATION_DO_READING |
2537 DBUS_ITERATION_BLOCK,
2538 timeout_milliseconds - elapsed_milliseconds);
2541 goto recheck_status;
2544 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2545 elapsed_milliseconds);
2550 complete_pending_call_and_unlock (connection, pending,
NULL);
2554 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2555 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2601 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2602 _dbus_return_val_if_error_is_set (error,
NULL);
2604 connection = _dbus_connection_open_internal (address,
2644 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2645 _dbus_return_val_if_error_is_set (error,
NULL);
2647 connection = _dbus_connection_open_internal (address,
2665 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2668 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2675 free_outgoing_message (
void *element,
2694 _dbus_verbose (
"Finalizing connection %p\n", connection);
2720 while (link !=
NULL)
2726 _dbus_message_filter_unref (filter);
2743 free_outgoing_message,
2800 _dbus_return_if_fail (connection !=
NULL);
2805 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2808 if (old_refcount == 1)
2810 #ifndef DBUS_DISABLE_CHECKS
2813 _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",
2815 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2816 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2820 _dbus_connection_last_unref (connection);
2834 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2838 HAVE_LOCK_CHECK (connection);
2840 _dbus_verbose (
"Disconnecting %p\n", connection);
2859 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2862 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2913 _dbus_return_if_fail (connection !=
NULL);
2918 #ifndef DBUS_DISABLE_CHECKS
2923 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2928 _dbus_connection_close_possibly_shared_and_unlock (connection);
2932 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2934 HAVE_LOCK_CHECK (connection);
2956 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2959 res = _dbus_connection_get_is_connected_unlocked (connection);
2978 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3012 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3057 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3087 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3095 #ifdef HAVE_UNIX_FD_PASSING
3127 _dbus_return_if_fail (connection !=
NULL);
3148 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3153 _dbus_connection_preallocate_send_unlocked (connection);
3157 return preallocated;
3173 _dbus_return_if_fail (connection !=
NULL);
3174 _dbus_return_if_fail (preallocated !=
NULL);
3175 _dbus_return_if_fail (connection == preallocated->
connection);
3201 _dbus_return_if_fail (connection !=
NULL);
3202 _dbus_return_if_fail (preallocated !=
NULL);
3203 _dbus_return_if_fail (message !=
NULL);
3204 _dbus_return_if_fail (preallocated->
connection == connection);
3213 #ifdef HAVE_UNIX_FD_PASSING
3216 message->n_unix_fds > 0)
3227 _dbus_connection_send_preallocated_and_unlock (connection,
3229 message, client_serial);
3233 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3242 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3243 if (preallocated ==
NULL)
3246 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3285 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3286 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3290 #ifdef HAVE_UNIX_FD_PASSING
3293 message->n_unix_fds > 0)
3310 reply_handler_timeout (
void *data)
3325 _dbus_verbose (
"middle\n");
3326 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3329 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3381 int timeout_milliseconds)
3387 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3388 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3389 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3392 *pending_return =
NULL;
3396 #ifdef HAVE_UNIX_FD_PASSING
3399 message->n_unix_fds > 0)
3411 if (!_dbus_connection_get_is_connected_unlocked (connection))
3419 timeout_milliseconds,
3420 reply_handler_timeout);
3422 if (pending ==
NULL)
3432 serial = _dbus_connection_get_next_client_serial (connection);
3443 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3447 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3449 _dbus_connection_detach_pending_call_and_unlock (connection,
3451 goto error_unlocked;
3455 *pending_return = pending;
3458 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3464 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3467 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3469 if (pending_return ==
NULL)
3516 int timeout_milliseconds,
3522 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3523 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3524 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3525 _dbus_return_val_if_error_is_set (error,
NULL);
3527 #ifdef HAVE_UNIX_FD_PASSING
3531 message->n_unix_fds > 0)
3542 &pending, timeout_milliseconds))
3544 _DBUS_SET_OOM (error);
3548 if (pending ==
NULL)
3591 HAVE_LOCK_CHECK (connection);
3594 _dbus_connection_get_is_connected_unlocked (connection))
3596 _dbus_verbose (
"doing iteration in\n");
3597 HAVE_LOCK_CHECK (connection);
3600 DBUS_ITERATION_DO_READING |
3601 DBUS_ITERATION_DO_WRITING |
3602 DBUS_ITERATION_BLOCK,
3606 HAVE_LOCK_CHECK (connection);
3607 _dbus_verbose (
"middle\n");
3608 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3610 HAVE_LOCK_CHECK (connection);
3629 _dbus_return_if_fail (connection !=
NULL);
3633 status = _dbus_connection_flush_unlocked (connection);
3635 HAVE_LOCK_CHECK (connection);
3637 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3639 _dbus_verbose (
"end\n");
3653 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3654 int timeout_milliseconds,
3669 _dbus_verbose (
"doing dispatch\n");
3675 _dbus_verbose (
"pausing for memory\n");
3676 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3682 if (_dbus_connection_get_is_connected_unlocked (connection))
3684 _dbus_verbose (
"doing iteration\n");
3687 DBUS_ITERATION_DO_READING |
3688 DBUS_ITERATION_DO_WRITING |
3689 DBUS_ITERATION_BLOCK,
3690 timeout_milliseconds);
3694 HAVE_LOCK_CHECK (connection);
3700 progress_possible = connection->
n_incoming != 0 ||
3703 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3709 return progress_possible;
3749 int timeout_milliseconds)
3751 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3752 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3753 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3781 int timeout_milliseconds)
3783 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3784 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3785 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3794 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3797 HAVE_LOCK_CHECK (connection);
3834 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3836 _dbus_verbose (
"start\n");
3847 _dbus_connection_acquire_dispatch (connection);
3856 check_disconnected_message_arrived_unlocked (connection, message);
3859 if (message ==
NULL)
3860 _dbus_connection_release_dispatch (connection);
3864 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3885 _dbus_return_if_fail (connection !=
NULL);
3886 _dbus_return_if_fail (message !=
NULL);
3896 _dbus_connection_release_dispatch (connection);
3898 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3899 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3901 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3920 _dbus_return_if_fail (connection !=
NULL);
3921 _dbus_return_if_fail (message !=
NULL);
3935 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3940 _dbus_connection_release_dispatch (connection);
3942 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3943 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3944 _dbus_message_trace_ref (message, -1, -1,
3945 "dbus_connection_steal_borrowed_message");
3952 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3954 HAVE_LOCK_CHECK (connection);
3965 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from incoming queue %p, %d incoming\n",
3980 _dbus_message_trace_ref (link->
data, -1, -1,
3981 "_dbus_connection_pop_message_link_unlocked");
3983 check_disconnected_message_arrived_unlocked (connection, link->
data);
3995 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
3999 HAVE_LOCK_CHECK (connection);
4001 link = _dbus_connection_pop_message_link_unlocked (connection);
4007 message = link->
data;
4018 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4021 HAVE_LOCK_CHECK (connection);
4033 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4045 _dbus_message_trace_ref (message_link->
data, -1, -1,
4046 "_dbus_connection_putback_message_link_unlocked");
4074 _dbus_verbose (
"start\n");
4084 _dbus_connection_acquire_dispatch (connection);
4085 HAVE_LOCK_CHECK (connection);
4087 message = _dbus_connection_pop_message_unlocked (connection);
4089 _dbus_verbose (
"Returning popped message %p\n", message);
4091 _dbus_connection_release_dispatch (connection);
4093 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4094 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4109 HAVE_LOCK_CHECK (connection);
4114 _dbus_verbose (
"locking dispatch_mutex\n");
4119 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4128 _dbus_verbose (
"unlocking dispatch_mutex\n");
4145 HAVE_LOCK_CHECK (connection);
4147 _dbus_verbose (
"locking dispatch_mutex\n");
4155 _dbus_verbose (
"unlocking dispatch_mutex\n");
4172 HAVE_LOCK_CHECK (connection);
4190 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4202 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4204 HAVE_LOCK_CHECK (connection);
4208 _dbus_verbose (
"Sending disconnect message\n");
4213 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4229 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4231 HAVE_LOCK_CHECK (connection);
4245 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4246 DISPATCH_STATUS_NAME (status), is_connected);
4256 notify_disconnected_unlocked (connection);
4264 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4277 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4284 HAVE_LOCK_CHECK (connection);
4304 connection_forget_shared_unlocked (connection);
4310 _dbus_verbose (
"Exiting on Disconnected signal\n");
4319 if (changed &&
function)
4321 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4322 connection, new_status,
4323 DISPATCH_STATUS_NAME (new_status));
4324 (* function) (connection, new_status, data);
4362 _dbus_verbose (
"start\n");
4366 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4377 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4410 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4430 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4443 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4447 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4458 expire_link->
data = ret;
4475 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4481 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4530 DBusList *link, *filter_list_copy, *message_link;
4539 _dbus_verbose (
"\n");
4542 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4546 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4555 _dbus_connection_acquire_dispatch (connection);
4556 HAVE_LOCK_CHECK (connection);
4558 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4559 if (message_link ==
NULL)
4563 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4565 _dbus_connection_release_dispatch (connection);
4567 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4569 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4576 message = message_link->
data;
4578 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4603 _dbus_verbose (
"Dispatching a pending reply\n");
4604 complete_pending_call_and_unlock (connection, pending, message);
4608 _dbus_verbose (
"pending call completed in dispatch\n");
4613 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4619 _dbus_connection_release_dispatch (connection);
4620 HAVE_LOCK_CHECK (connection);
4622 _dbus_connection_failed_pop (connection, message_link);
4625 _dbus_connection_update_dispatch_status_and_unlock (connection,
4642 while (link !=
NULL)
4649 _dbus_verbose (
" filter was removed in a callback function\n");
4654 _dbus_verbose (
" running filter on message %p\n", message);
4672 _dbus_verbose (
"No memory\n");
4677 _dbus_verbose (
"filter handled message in dispatch\n");
4684 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4695 HAVE_LOCK_CHECK (connection);
4704 _dbus_verbose (
"object tree handled message in dispatch\n");
4715 _dbus_verbose (
" sending error %s\n",
4721 _dbus_verbose (
"no memory for error string in dispatch\n");
4726 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4733 _dbus_verbose (
"no memory for error string in dispatch\n");
4745 _dbus_verbose (
"no memory for error reply in dispatch\n");
4751 if (expire_link ==
NULL)
4755 _dbus_verbose (
"no memory for error send in dispatch\n");
4759 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4761 if (preallocated ==
NULL)
4768 _dbus_verbose (
"no memory for error send in dispatch\n");
4772 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4780 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4794 _dbus_verbose (
"out of memory\n");
4800 _dbus_connection_putback_message_link_unlocked (connection,
4803 message_link =
NULL;
4808 _dbus_verbose (
" ... done dispatching\n");
4811 _dbus_connection_release_dispatch (connection);
4812 HAVE_LOCK_CHECK (connection);
4814 if (message !=
NULL)
4828 if (message_link !=
NULL)
4831 _dbus_verbose (
"before final status update\n");
4832 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4835 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4913 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4918 add_function, remove_function,
4920 data, free_data_function);
4976 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4981 add_function, remove_function,
4983 data, free_data_function);
5013 _dbus_return_if_fail (connection !=
NULL);
5027 (*old_free_data) (old_data);
5059 _dbus_return_if_fail (connection !=
NULL);
5073 (*old_free_data) (old_data);
5099 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5131 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5173 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5174 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5209 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5210 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5242 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5243 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5244 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5287 void *old_data =
NULL;
5290 _dbus_return_if_fail (connection !=
NULL);
5294 function, data, free_data_function,
5295 &old_data, &old_free_function);
5298 if (old_free_function !=
NULL)
5299 (* old_free_function) (old_data);
5335 char **windows_sid_p)
5339 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5340 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5386 void *old_data =
NULL;
5389 _dbus_return_if_fail (connection !=
NULL);
5393 function, data, free_data_function,
5394 &old_data, &old_free_function);
5397 if (old_free_function !=
NULL)
5398 (* old_free_function) (old_data);
5431 _dbus_return_if_fail (connection !=
NULL);
5459 _dbus_return_if_fail (connection !=
NULL);
5495 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5496 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5509 _dbus_message_filter_unref (filter);
5547 _dbus_return_if_fail (connection !=
NULL);
5548 _dbus_return_if_fail (
function !=
NULL);
5555 while (link !=
NULL)
5557 filter = link->
data;
5559 if (filter->
function ==
function &&
5574 #ifndef DBUS_DISABLE_CHECKS
5577 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5578 function, user_data);
5590 _dbus_message_filter_unref (filter);
5609 _dbus_connection_register_object_path (
DBusConnection *connection,
5616 char **decomposed_path;
5626 (
const char **) decomposed_path, vtable,
5655 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5656 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5657 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5658 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5660 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5687 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5688 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5689 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5690 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5692 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5725 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5726 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5727 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5728 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5730 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5759 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5760 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5761 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5762 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5764 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5789 char **decomposed_path;
5791 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5792 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5793 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5822 char **decomposed_path;
5824 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5825 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5826 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5856 const char *parent_path,
5857 char ***child_entries)
5859 char **decomposed_path;
5861 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5862 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5863 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5864 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5872 (
const char **) decomposed_path,
5917 _dbus_return_if_fail (*slot_p >= 0);
5954 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5955 _dbus_return_val_if_fail (slot >= 0,
FALSE);
5957 SLOTS_LOCK (connection);
5961 slot, data, free_data_func,
5962 &old_free_func, &old_data);
5964 SLOTS_UNLOCK (connection);
5970 (* old_free_func) (old_data);
5999 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
6000 _dbus_return_val_if_fail (slot >= 0,
NULL);
6002 SLOTS_LOCK (connection);
6008 SLOTS_UNLOCK (connection);
6022 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6037 _dbus_return_if_fail (connection !=
NULL);
6056 _dbus_return_val_if_fail (connection !=
NULL, 0);
6076 _dbus_return_if_fail (connection !=
NULL);
6095 _dbus_return_val_if_fail (connection !=
NULL, 0);
6132 _dbus_return_if_fail (connection !=
NULL);
6151 _dbus_return_val_if_fail (connection !=
NULL, 0);
6174 _dbus_return_if_fail (connection !=
NULL);
6193 _dbus_return_val_if_fail (connection !=
NULL, 0);
6216 _dbus_return_val_if_fail (connection !=
NULL, 0);
6224 #ifdef DBUS_ENABLE_STATS
6240 if (in_messages !=
NULL)
6243 _dbus_transport_get_stats (connection->
transport,
6244 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6246 if (out_messages !=
NULL)
6249 if (out_bytes !=
NULL)
6252 if (out_fds !=
NULL)
6255 if (out_peak_bytes !=
NULL)
6256 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6258 if (out_peak_fds !=
NULL)
6259 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6277 _dbus_return_val_if_fail (connection !=
NULL, 0);
6285 #ifdef DBUS_BUILD_TESTS