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);
355 dbus_uint32_t client_serial);
360 #ifdef DBUS_DISABLE_ASSERT
363 dbus_int32_t old_value;
375 dbus_int32_t old_value;
413 _dbus_verbose (
"UNLOCK\n");
421 RELEASING_LOCK_CHECK (connection);
449 #ifdef DBUS_BUILD_TESTS
491 dbus_uint32_t reply_serial;
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,
926 dbus_uint32_t reply_serial;
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)
1428 dbus_int32_t old_refcount;
1433 HAVE_LOCK_CHECK (connection);
1436 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
1451 dbus_int32_t old_refcount;
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);
1466 static dbus_uint32_t
1467 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1469 dbus_uint32_t serial;
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,
1980 dbus_uint32_t *client_serial)
1982 dbus_uint32_t serial;
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,
2054 dbus_uint32_t *client_serial)
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);
2083 dbus_uint32_t *client_serial)
2090 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2091 if (preallocated ==
NULL)
2097 _dbus_connection_send_preallocated_and_unlock (connection,
2131 dbus_int32_t refcount;
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)
2169 generate_local_error_message (dbus_uint32_t serial,
2195 if (error_msg !=
NULL)
2218 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2219 dbus_uint32_t client_serial)
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);
2246 dbus_uint32_t 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;
2368 dbus_uint32_t client_serial;
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);
2577 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2578 _dbus_return_val_if_error_is_set (error,
NULL);
2580 connection = _dbus_connection_open_internal (address,
2620 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2621 _dbus_return_val_if_error_is_set (error,
NULL);
2623 connection = _dbus_connection_open_internal (address,
2639 dbus_int32_t old_refcount;
2641 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2644 _dbus_connection_trace_ref (connection, old_refcount, old_refcount + 1,
2651 free_outgoing_message (
void *element,
2670 _dbus_verbose (
"Finalizing connection %p\n", connection);
2696 while (link !=
NULL)
2702 _dbus_message_filter_unref (filter);
2719 free_outgoing_message,
2774 dbus_int32_t old_refcount;
2776 _dbus_return_if_fail (connection !=
NULL);
2781 _dbus_connection_trace_ref (connection, old_refcount, old_refcount - 1,
2784 if (old_refcount == 1)
2786 #ifndef DBUS_DISABLE_CHECKS
2789 _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",
2791 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2792 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2796 _dbus_connection_last_unref (connection);
2810 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2814 HAVE_LOCK_CHECK (connection);
2816 _dbus_verbose (
"Disconnecting %p\n", connection);
2835 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2838 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2889 _dbus_return_if_fail (connection !=
NULL);
2894 #ifndef DBUS_DISABLE_CHECKS
2899 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2904 _dbus_connection_close_possibly_shared_and_unlock (connection);
2908 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2910 HAVE_LOCK_CHECK (connection);
2932 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2935 res = _dbus_connection_get_is_connected_unlocked (connection);
2954 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2988 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3033 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3063 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3071 #ifdef HAVE_UNIX_FD_PASSING
3103 _dbus_return_if_fail (connection !=
NULL);
3124 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3129 _dbus_connection_preallocate_send_unlocked (connection);
3133 return preallocated;
3149 _dbus_return_if_fail (connection !=
NULL);
3150 _dbus_return_if_fail (preallocated !=
NULL);
3151 _dbus_return_if_fail (connection == preallocated->
connection);
3175 dbus_uint32_t *client_serial)
3177 _dbus_return_if_fail (connection !=
NULL);
3178 _dbus_return_if_fail (preallocated !=
NULL);
3179 _dbus_return_if_fail (message !=
NULL);
3180 _dbus_return_if_fail (preallocated->
connection == connection);
3189 #ifdef HAVE_UNIX_FD_PASSING
3192 message->n_unix_fds > 0)
3203 _dbus_connection_send_preallocated_and_unlock (connection,
3205 message, client_serial);
3209 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3211 dbus_uint32_t *client_serial)
3218 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3219 if (preallocated ==
NULL)
3222 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3259 dbus_uint32_t *serial)
3261 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3262 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3266 #ifdef HAVE_UNIX_FD_PASSING
3269 message->n_unix_fds > 0)
3286 reply_handler_timeout (
void *data)
3301 _dbus_verbose (
"middle\n");
3302 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3305 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3357 int timeout_milliseconds)
3360 dbus_int32_t serial = -1;
3363 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3364 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3365 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3368 *pending_return =
NULL;
3372 #ifdef HAVE_UNIX_FD_PASSING
3375 message->n_unix_fds > 0)
3387 if (!_dbus_connection_get_is_connected_unlocked (connection))
3395 timeout_milliseconds,
3396 reply_handler_timeout);
3398 if (pending ==
NULL)
3408 serial = _dbus_connection_get_next_client_serial (connection);
3419 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3423 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3425 _dbus_connection_detach_pending_call_and_unlock (connection,
3427 goto error_unlocked;
3431 *pending_return = pending;
3434 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3440 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3443 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3445 if (pending_return ==
NULL)
3492 int timeout_milliseconds,
3498 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3499 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3500 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3501 _dbus_return_val_if_error_is_set (error,
NULL);
3503 #ifdef HAVE_UNIX_FD_PASSING
3507 message->n_unix_fds > 0)
3518 &pending, timeout_milliseconds))
3520 _DBUS_SET_OOM (error);
3524 if (pending ==
NULL)
3567 HAVE_LOCK_CHECK (connection);
3570 _dbus_connection_get_is_connected_unlocked (connection))
3572 _dbus_verbose (
"doing iteration in\n");
3573 HAVE_LOCK_CHECK (connection);
3576 DBUS_ITERATION_DO_READING |
3577 DBUS_ITERATION_DO_WRITING |
3578 DBUS_ITERATION_BLOCK,
3582 HAVE_LOCK_CHECK (connection);
3583 _dbus_verbose (
"middle\n");
3584 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3586 HAVE_LOCK_CHECK (connection);
3605 _dbus_return_if_fail (connection !=
NULL);
3609 status = _dbus_connection_flush_unlocked (connection);
3611 HAVE_LOCK_CHECK (connection);
3613 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3615 _dbus_verbose (
"end\n");
3629 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3630 int timeout_milliseconds,
3645 _dbus_verbose (
"doing dispatch\n");
3651 _dbus_verbose (
"pausing for memory\n");
3652 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3658 if (_dbus_connection_get_is_connected_unlocked (connection))
3660 _dbus_verbose (
"doing iteration\n");
3663 DBUS_ITERATION_DO_READING |
3664 DBUS_ITERATION_DO_WRITING |
3665 DBUS_ITERATION_BLOCK,
3666 timeout_milliseconds);
3670 HAVE_LOCK_CHECK (connection);
3676 progress_possible = connection->
n_incoming != 0 ||
3679 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3685 return progress_possible;
3725 int timeout_milliseconds)
3727 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3728 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3729 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3757 int timeout_milliseconds)
3759 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3760 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3761 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3770 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3773 HAVE_LOCK_CHECK (connection);
3810 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3812 _dbus_verbose (
"start\n");
3823 _dbus_connection_acquire_dispatch (connection);
3832 check_disconnected_message_arrived_unlocked (connection, message);
3835 if (message ==
NULL)
3836 _dbus_connection_release_dispatch (connection);
3840 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_borrow_message");
3861 _dbus_return_if_fail (connection !=
NULL);
3862 _dbus_return_if_fail (message !=
NULL);
3872 _dbus_connection_release_dispatch (connection);
3874 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3875 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3877 _dbus_message_trace_ref (message, -1, -1,
"dbus_connection_return_message");
3896 _dbus_return_if_fail (connection !=
NULL);
3897 _dbus_return_if_fail (message !=
NULL);
3911 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3916 _dbus_connection_release_dispatch (connection);
3918 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3919 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3920 _dbus_message_trace_ref (message, -1, -1,
3921 "dbus_connection_steal_borrowed_message");
3928 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3930 HAVE_LOCK_CHECK (connection);
3941 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from incoming queue %p, %d incoming\n",
3956 _dbus_message_trace_ref (link->
data, -1, -1,
3957 "_dbus_connection_pop_message_link_unlocked");
3959 check_disconnected_message_arrived_unlocked (connection, link->
data);
3971 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
3975 HAVE_LOCK_CHECK (connection);
3977 link = _dbus_connection_pop_message_link_unlocked (connection);
3983 message = link->
data;
3994 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
3997 HAVE_LOCK_CHECK (connection);
4009 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4021 _dbus_message_trace_ref (message_link->
data, -1, -1,
4022 "_dbus_connection_putback_message_link_unlocked");
4050 _dbus_verbose (
"start\n");
4060 _dbus_connection_acquire_dispatch (connection);
4061 HAVE_LOCK_CHECK (connection);
4063 message = _dbus_connection_pop_message_unlocked (connection);
4065 _dbus_verbose (
"Returning popped message %p\n", message);
4067 _dbus_connection_release_dispatch (connection);
4069 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4070 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4085 HAVE_LOCK_CHECK (connection);
4090 _dbus_verbose (
"locking dispatch_mutex\n");
4095 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4104 _dbus_verbose (
"unlocking dispatch_mutex\n");
4121 HAVE_LOCK_CHECK (connection);
4123 _dbus_verbose (
"locking dispatch_mutex\n");
4131 _dbus_verbose (
"unlocking dispatch_mutex\n");
4148 HAVE_LOCK_CHECK (connection);
4166 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4178 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4180 HAVE_LOCK_CHECK (connection);
4184 _dbus_verbose (
"Sending disconnect message\n");
4189 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4205 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4207 HAVE_LOCK_CHECK (connection);
4221 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4222 DISPATCH_STATUS_NAME (status), is_connected);
4232 notify_disconnected_unlocked (connection);
4240 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4253 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4260 HAVE_LOCK_CHECK (connection);
4280 connection_forget_shared_unlocked (connection);
4286 _dbus_verbose (
"Exiting on Disconnected signal\n");
4295 if (changed &&
function)
4297 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4298 connection, new_status,
4299 DISPATCH_STATUS_NAME (new_status));
4300 (* function) (connection, new_status, data);
4338 _dbus_verbose (
"start\n");
4342 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4353 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4386 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4401 const char *v_STRING = _dbus_string_get_const_data (&uuid);
4406 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4419 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4423 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4434 expire_link->
data = ret;
4451 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4457 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4506 DBusList *link, *filter_list_copy, *message_link;
4509 dbus_int32_t reply_serial;
4515 _dbus_verbose (
"\n");
4518 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4522 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4531 _dbus_connection_acquire_dispatch (connection);
4532 HAVE_LOCK_CHECK (connection);
4534 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4535 if (message_link ==
NULL)
4539 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4541 _dbus_connection_release_dispatch (connection);
4543 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4545 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4552 message = message_link->
data;
4554 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4579 _dbus_verbose (
"Dispatching a pending reply\n");
4580 complete_pending_call_and_unlock (connection, pending, message);
4584 _dbus_verbose (
"pending call completed in dispatch\n");
4589 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4595 _dbus_connection_release_dispatch (connection);
4596 HAVE_LOCK_CHECK (connection);
4598 _dbus_connection_failed_pop (connection, message_link);
4601 _dbus_connection_update_dispatch_status_and_unlock (connection,
4618 while (link !=
NULL)
4625 _dbus_verbose (
" filter was removed in a callback function\n");
4630 _dbus_verbose (
" running filter on message %p\n", message);
4648 _dbus_verbose (
"No memory\n");
4653 _dbus_verbose (
"filter handled message in dispatch\n");
4660 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4671 HAVE_LOCK_CHECK (connection);
4680 _dbus_verbose (
"object tree handled message in dispatch\n");
4691 _dbus_verbose (
" sending error %s\n",
4697 _dbus_verbose (
"no memory for error string in dispatch\n");
4702 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4709 _dbus_verbose (
"no memory for error string in dispatch\n");
4715 _dbus_string_get_const_data (&str));
4721 _dbus_verbose (
"no memory for error reply in dispatch\n");
4727 if (expire_link ==
NULL)
4731 _dbus_verbose (
"no memory for error send in dispatch\n");
4735 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4737 if (preallocated ==
NULL)
4744 _dbus_verbose (
"no memory for error send in dispatch\n");
4748 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4756 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4770 _dbus_verbose (
"out of memory\n");
4776 _dbus_connection_putback_message_link_unlocked (connection,
4779 message_link =
NULL;
4784 _dbus_verbose (
" ... done dispatching\n");
4787 _dbus_connection_release_dispatch (connection);
4788 HAVE_LOCK_CHECK (connection);
4790 if (message !=
NULL)
4804 if (message_link !=
NULL)
4807 _dbus_verbose (
"before final status update\n");
4808 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4811 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4889 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4894 add_function, remove_function,
4896 data, free_data_function);
4952 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4957 add_function, remove_function,
4959 data, free_data_function);
4989 _dbus_return_if_fail (connection !=
NULL);
5003 (*old_free_data) (old_data);
5035 _dbus_return_if_fail (connection !=
NULL);
5049 (*old_free_data) (old_data);
5075 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5107 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5149 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5150 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5185 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5186 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5214 dbus_int32_t *data_size)
5218 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5219 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5220 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5263 void *old_data =
NULL;
5266 _dbus_return_if_fail (connection !=
NULL);
5270 function, data, free_data_function,
5271 &old_data, &old_free_function);
5274 if (old_free_function !=
NULL)
5275 (* old_free_function) (old_data);
5311 char **windows_sid_p)
5315 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5316 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5362 void *old_data =
NULL;
5365 _dbus_return_if_fail (connection !=
NULL);
5369 function, data, free_data_function,
5370 &old_data, &old_free_function);
5373 if (old_free_function !=
NULL)
5374 (* old_free_function) (old_data);
5407 _dbus_return_if_fail (connection !=
NULL);
5435 _dbus_return_if_fail (connection !=
NULL);
5471 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5472 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5485 _dbus_message_filter_unref (filter);
5523 _dbus_return_if_fail (connection !=
NULL);
5524 _dbus_return_if_fail (
function !=
NULL);
5531 while (link !=
NULL)
5533 filter = link->
data;
5535 if (filter->
function ==
function &&
5550 #ifndef DBUS_DISABLE_CHECKS
5553 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5554 function, user_data);
5566 _dbus_message_filter_unref (filter);
5585 _dbus_connection_register_object_path (
DBusConnection *connection,
5592 char **decomposed_path;
5602 (
const char **) decomposed_path, vtable,
5631 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5632 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5633 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5634 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5636 return _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, error);
5663 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5664 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5665 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5666 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5668 retval = _dbus_connection_register_object_path (connection,
FALSE, path, vtable, user_data, &error);
5701 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5702 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5703 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5704 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5706 return _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, error);
5735 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5736 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5737 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5738 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5740 retval = _dbus_connection_register_object_path (connection,
TRUE, path, vtable, user_data, &error);
5765 char **decomposed_path;
5767 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5768 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5769 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5798 char **decomposed_path;
5800 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5801 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5802 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5832 const char *parent_path,
5833 char ***child_entries)
5835 char **decomposed_path;
5837 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5838 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5839 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5840 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5848 (
const char **) decomposed_path,
5894 _dbus_return_if_fail (*slot_p >= 0);
5931 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5932 _dbus_return_val_if_fail (slot >= 0,
FALSE);
5934 SLOTS_LOCK (connection);
5938 slot, data, free_data_func,
5939 &old_free_func, &old_data);
5941 SLOTS_UNLOCK (connection);
5947 (* old_free_func) (old_data);
5976 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
5978 SLOTS_LOCK (connection);
5984 SLOTS_UNLOCK (connection);
5998 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6013 _dbus_return_if_fail (connection !=
NULL);
6032 _dbus_return_val_if_fail (connection !=
NULL, 0);
6052 _dbus_return_if_fail (connection !=
NULL);
6071 _dbus_return_val_if_fail (connection !=
NULL, 0);
6108 _dbus_return_if_fail (connection !=
NULL);
6127 _dbus_return_val_if_fail (connection !=
NULL, 0);
6150 _dbus_return_if_fail (connection !=
NULL);
6169 _dbus_return_val_if_fail (connection !=
NULL, 0);
6192 _dbus_return_val_if_fail (connection !=
NULL, 0);
6200 #ifdef DBUS_ENABLE_STATS
6203 dbus_uint32_t *in_messages,
6204 dbus_uint32_t *in_bytes,
6205 dbus_uint32_t *in_fds,
6206 dbus_uint32_t *in_peak_bytes,
6207 dbus_uint32_t *in_peak_fds,
6208 dbus_uint32_t *out_messages,
6209 dbus_uint32_t *out_bytes,
6210 dbus_uint32_t *out_fds,
6211 dbus_uint32_t *out_peak_bytes,
6212 dbus_uint32_t *out_peak_fds)
6216 if (in_messages !=
NULL)
6219 _dbus_transport_get_stats (connection->
transport,
6220 in_bytes, in_fds, in_peak_bytes, in_peak_fds);
6222 if (out_messages !=
NULL)
6225 if (out_bytes !=
NULL)
6228 if (out_fds !=
NULL)
6231 if (out_peak_bytes !=
NULL)
6232 *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->
outgoing_counter);
6234 if (out_peak_fds !=
NULL)
6235 *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->
outgoing_counter);
6253 _dbus_return_val_if_fail (connection !=
NULL, 0);
6261 #ifdef DBUS_BUILD_TESTS