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-pending-call.h"
42 #include "dbus-object-tree.h"
43 #include "dbus-threads-internal.h"
45 #include "dbus-marshal-basic.h"
47 #ifdef DBUS_DISABLE_CHECKS
48 #define TOOK_LOCK_CHECK(connection)
49 #define RELEASING_LOCK_CHECK(connection)
50 #define HAVE_LOCK_CHECK(connection)
52 #define TOOK_LOCK_CHECK(connection) do { \
53 _dbus_assert (!(connection)->have_connection_lock); \
54 (connection)->have_connection_lock = TRUE; \
56 #define RELEASING_LOCK_CHECK(connection) do { \
57 _dbus_assert ((connection)->have_connection_lock); \
58 (connection)->have_connection_lock = FALSE; \
60 #define HAVE_LOCK_CHECK(connection) _dbus_assert ((connection)->have_connection_lock)
66 #define CONNECTION_LOCK(connection) do { \
67 if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
68 _dbus_mutex_lock ((connection)->mutex); \
69 TOOK_LOCK_CHECK (connection); \
72 #define CONNECTION_UNLOCK(connection) do { \
73 if (TRACE_LOCKS) { _dbus_verbose ("UNLOCK\n"); } \
74 RELEASING_LOCK_CHECK (connection); \
75 _dbus_mutex_unlock ((connection)->mutex); \
78 #define SLOTS_LOCK(connection) do { \
79 _dbus_mutex_lock ((connection)->slot_mutex); \
82 #define SLOTS_UNLOCK(connection) do { \
83 _dbus_mutex_unlock ((connection)->slot_mutex); \
86 #define DISPATCH_STATUS_NAME(s) \
87 ((s) == DBUS_DISPATCH_COMPLETE ? "complete" : \
88 (s) == DBUS_DISPATCH_DATA_REMAINS ? "data remains" : \
89 (s) == DBUS_DISPATCH_NEED_MEMORY ? "need memory" : \
236 #if HAVE_DECL_MSG_NOSIGNAL
320 #ifndef DBUS_DISABLE_CHECKS
324 #ifndef DBUS_DISABLE_CHECKS
330 static void _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
332 static void _dbus_connection_last_unref (
DBusConnection *connection);
333 static void _dbus_connection_acquire_dispatch (
DBusConnection *connection);
334 static void _dbus_connection_release_dispatch (
DBusConnection *connection);
336 static void _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection);
400 #ifdef DBUS_BUILD_TESTS
412 _dbus_connection_queue_received_message (
DBusConnection *connection,
447 *mutex_loc = connection->
mutex;
475 message = link->
data;
479 if (reply_serial != 0)
497 _dbus_connection_wakeup_mainloop (connection);
499 _dbus_verbose (
"Message %p (%s %s %s %s '%s' reply to %u) added to incoming queue %p, %d incoming\n",
528 HAVE_LOCK_CHECK (connection);
534 _dbus_connection_wakeup_mainloop (connection);
536 _dbus_verbose (
"Synthesized message %p added to incoming queue %p, %d incoming\n",
551 HAVE_LOCK_CHECK (connection);
569 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
588 HAVE_LOCK_CHECK (connection);
607 HAVE_LOCK_CHECK (connection);
625 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from outgoing queue %p, %d left to send\n",
669 HAVE_LOCK_CHECK (connection);
692 retval = (* add_function) (connection->
watches, watch);
693 else if (remove_function)
696 (* remove_function) (connection->
watches, watch);
701 (* toggle_function) (connection->
watches, watch, enabled);
725 return protected_change_watch (connection, watch,
743 protected_change_watch (connection, watch,
766 protected_change_watch (connection, watch,
793 HAVE_LOCK_CHECK (connection);
816 retval = (* add_function) (connection->
timeouts, timeout);
817 else if (remove_function)
820 (* remove_function) (connection->
timeouts, timeout);
825 (* toggle_function) (connection->
timeouts, timeout, enabled);
849 return protected_change_timeout (connection, timeout,
867 protected_change_timeout (connection, timeout,
888 protected_change_timeout (connection, timeout,
895 _dbus_connection_attach_pending_call_unlocked (
DBusConnection *connection,
901 HAVE_LOCK_CHECK (connection);
921 HAVE_LOCK_CHECK (connection);
933 HAVE_LOCK_CHECK (connection);
940 HAVE_LOCK_CHECK (connection);
946 free_pending_call_on_hash_removal (
void *data)
958 HAVE_LOCK_CHECK (connection);
980 _dbus_connection_detach_pending_call_unlocked (
DBusConnection *connection,
991 _dbus_connection_detach_pending_call_and_unlock (
DBusConnection *connection,
1027 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
1041 int timeout_milliseconds)
1045 HAVE_LOCK_CHECK (connection);
1053 _dbus_verbose (
"locking io_path_mutex\n");
1056 _dbus_verbose (
"start connection->io_path_acquired = %d timeout = %d\n",
1059 we_acquired =
FALSE;
1063 if (timeout_milliseconds != -1)
1065 _dbus_verbose (
"waiting %d for IO path to be acquirable\n",
1066 timeout_milliseconds);
1070 timeout_milliseconds))
1086 _dbus_verbose (
"waiting for IO path to be acquirable\n");
1099 _dbus_verbose (
"end connection->io_path_acquired = %d we_acquired = %d\n",
1102 _dbus_verbose (
"unlocking io_path_mutex\n");
1107 HAVE_LOCK_CHECK (connection);
1124 HAVE_LOCK_CHECK (connection);
1126 _dbus_verbose (
"locking io_path_mutex\n");
1131 _dbus_verbose (
"start connection->io_path_acquired = %d\n",
1137 _dbus_verbose (
"unlocking io_path_mutex\n");
1180 int timeout_milliseconds)
1182 _dbus_verbose (
"start\n");
1184 HAVE_LOCK_CHECK (connection);
1187 flags &= ~DBUS_ITERATION_DO_WRITING;
1189 if (_dbus_connection_acquire_io_path (connection,
1190 (flags & DBUS_ITERATION_BLOCK) ? timeout_milliseconds : 0))
1192 HAVE_LOCK_CHECK (connection);
1196 _dbus_verbose (
"pending call completed while acquiring I/O path");
1198 else if ( (pending !=
NULL) &&
1199 _dbus_connection_peek_for_reply_unlocked (connection,
1202 _dbus_verbose (
"pending call completed while acquiring I/O path (reply found in queue)");
1207 flags, timeout_milliseconds);
1210 _dbus_connection_release_io_path (connection);
1213 HAVE_LOCK_CHECK (connection);
1215 _dbus_verbose (
"end\n");
1241 pending_replies =
NULL;
1242 timeout_list =
NULL;
1243 disconnect_link =
NULL;
1244 disconnect_message =
NULL;
1245 outgoing_counter =
NULL;
1249 if (watch_list ==
NULL)
1253 if (timeout_list ==
NULL)
1260 if (pending_replies ==
NULL)
1264 if (connection ==
NULL)
1295 if (disconnect_message ==
NULL)
1299 if (disconnect_link ==
NULL)
1303 if (outgoing_counter ==
NULL)
1307 if (objects ==
NULL)
1310 if (_dbus_modify_sigpipe)
1315 connection->
watches = watch_list;
1316 connection->
timeouts = timeout_list;
1321 connection->
objects = objects;
1328 #ifndef DBUS_DISABLE_CHECKS
1354 if (disconnect_message !=
NULL)
1357 if (disconnect_link !=
NULL)
1360 if (connection !=
NULL)
1370 if (pending_replies)
1379 if (outgoing_counter)
1401 HAVE_LOCK_CHECK (connection);
1403 #ifdef DBUS_HAVE_ATOMIC_INT
1424 HAVE_LOCK_CHECK (connection);
1432 #ifdef DBUS_HAVE_ATOMIC_INT
1440 printf (
"unref_unlocked() connection %p count = %d\n", connection, connection->
refcount.
value);
1445 _dbus_connection_last_unref (connection);
1449 _dbus_connection_get_next_client_serial (
DBusConnection *connection)
1476 unsigned int condition,
1485 _dbus_verbose (
"start\n");
1489 if (!_dbus_connection_acquire_io_path (connection, 1))
1496 HAVE_LOCK_CHECK (connection);
1500 _dbus_connection_release_io_path (connection);
1502 HAVE_LOCK_CHECK (connection);
1504 _dbus_verbose (
"middle\n");
1506 status = _dbus_connection_get_dispatch_status_unlocked (connection);
1509 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
1511 _dbus_verbose (
"end\n");
1537 shared_connections_shutdown (
void *data)
1555 close_connection_on_shutdown (connection);
1565 shared_connections =
NULL;
1567 if (shared_connections_no_guid !=
NULL)
1571 while (connection !=
NULL)
1574 close_connection_on_shutdown (connection);
1580 shared_connections_no_guid =
NULL;
1589 _dbus_verbose (
"checking for existing connection\n");
1595 if (shared_connections ==
NULL)
1597 _dbus_verbose (
"creating shared_connections hash table\n");
1602 if (shared_connections ==
NULL)
1611 shared_connections =
NULL;
1616 _dbus_verbose (
" successfully created shared_connections\n");
1651 if (_dbus_connection_get_is_connected_unlocked (connection))
1654 *result = connection;
1655 _dbus_verbose (
"looked up existing connection to server guid %s\n",
1660 _dbus_verbose (
"looked up existing connection to server guid %s but it was disconnected so ignoring it\n",
1677 char *guid_in_connection;
1679 HAVE_LOCK_CHECK (connection);
1709 if (guid_key ==
NULL)
1713 if (guid_in_connection ==
NULL)
1723 guid_key, connection))
1733 _dbus_verbose (
"stored connection to %s to be shared\n",
1746 HAVE_LOCK_CHECK (connection);
1755 _dbus_verbose (
"dropping connection to %s out of the shared table\n",
1785 if (transport ==
NULL)
1787 _DBUS_ASSERT_ERROR_IS_SET (error);
1795 if (connection ==
NULL)
1797 _DBUS_SET_OOM (error);
1801 #ifndef DBUS_DISABLE_CHECKS
1820 _dbus_connection_open_internal (
const char *address,
1830 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1832 _dbus_verbose (
"opening %s connection to: %s\n",
1833 shared ?
"shared" :
"private", address);
1838 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1842 for (i = 0; i < len; i++)
1846 if (!connection_lookup_shared (entries[i], &connection))
1847 _DBUS_SET_OOM (&tmp_error);
1850 if (connection ==
NULL)
1852 connection = connection_try_from_address_entry (entries[i],
1855 if (connection !=
NULL && shared)
1866 if (!connection_record_shared_unlocked (connection, guid))
1868 _DBUS_SET_OOM (&tmp_error);
1869 _dbus_connection_close_possibly_shared_and_unlock (connection);
1881 _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
1889 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
1890 _DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
1892 if (connection ==
NULL)
1894 _DBUS_ASSERT_ERROR_IS_SET (&first_error);
1919 _dbus_connection_close_possibly_shared_and_unlock (connection);
1923 _dbus_connection_preallocate_send_unlocked (
DBusConnection *connection)
1927 HAVE_LOCK_CHECK (connection);
1932 if (preallocated ==
NULL)
1965 return preallocated;
1977 _dbus_connection_send_preallocated_unlocked_no_update (
DBusConnection *connection,
1992 preallocated =
NULL;
1998 _dbus_verbose (
"Message %p (%s %s %s %s '%s') for %s added to outgoing queue %p, %d pending to send\n",
2019 serial = _dbus_connection_get_next_client_serial (connection);
2022 *client_serial = serial;
2030 _dbus_verbose (
"Message %p serial is %u\n",
2040 DBUS_ITERATION_DO_WRITING,
2045 _dbus_connection_wakeup_mainloop (connection);
2049 _dbus_connection_send_preallocated_and_unlock (
DBusConnection *connection,
2056 HAVE_LOCK_CHECK (connection);
2058 _dbus_connection_send_preallocated_unlocked_no_update (connection,
2060 message, client_serial);
2062 _dbus_verbose (
"middle\n");
2063 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2066 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2088 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
2089 if (preallocated ==
NULL)
2095 _dbus_connection_send_preallocated_and_unlock (connection,
2134 _dbus_connection_close_possibly_shared_and_unlock (connection);
2150 _dbus_memory_pause_based_on_timeout (
int timeout_milliseconds)
2152 if (timeout_milliseconds == -1)
2154 else if (timeout_milliseconds < 100)
2156 else if (timeout_milliseconds <= 1000)
2189 if (error_msg !=
NULL)
2212 _dbus_connection_peek_for_reply_unlocked (
DBusConnection *connection,
2216 HAVE_LOCK_CHECK (connection);
2220 while (link !=
NULL)
2226 _dbus_verbose (
"%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial);
2244 HAVE_LOCK_CHECK (connection);
2248 while (link !=
NULL)
2265 connection_timeout_and_complete_all_pending_calls_unlocked (
DBusConnection *connection)
2295 HAVE_LOCK_CHECK (connection);
2305 _dbus_connection_detach_pending_call_and_unlock (connection, pending);
2313 check_for_reply_and_update_dispatch_unlocked (
DBusConnection *connection,
2319 reply = check_for_reply_unlocked (connection,
2323 _dbus_verbose (
"checked for reply\n");
2325 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): got reply\n");
2327 complete_pending_call_and_unlock (connection, pending, reply);
2331 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2332 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2358 long start_tv_sec, start_tv_usec;
2359 long tv_sec, tv_usec;
2364 int timeout_milliseconds, elapsed_milliseconds;
2376 _dbus_connection_flush_unlocked (connection);
2390 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block %d milliseconds for reply serial %u from %ld sec %ld usec\n",
2391 timeout_milliseconds,
2393 start_tv_sec, start_tv_usec);
2397 timeout_milliseconds = -1;
2399 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): will block for reply serial %u\n", client_serial);
2404 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2411 DBUS_ITERATION_DO_READING |
2412 DBUS_ITERATION_BLOCK,
2413 timeout_milliseconds);
2417 _dbus_verbose (
"top of recheck\n");
2419 HAVE_LOCK_CHECK (connection);
2423 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2430 _dbus_verbose (
"Pending call completed by dispatch\n");
2431 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2438 if (check_for_reply_and_update_dispatch_unlocked (connection, pending))
2443 elapsed_milliseconds = (tv_sec - start_tv_sec) * 1000 +
2444 (tv_usec - start_tv_usec) / 1000;
2446 if (!_dbus_connection_get_is_connected_unlocked (connection))
2450 error_msg = generate_local_error_message (client_serial,
2452 "Connection was disconnected before a reply was received");
2455 complete_pending_call_and_unlock (connection, pending, error_msg);
2460 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): disconnected\n");
2461 else if (timeout ==
NULL)
2469 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2471 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2478 DBUS_ITERATION_DO_READING |
2479 DBUS_ITERATION_BLOCK,
2480 timeout_milliseconds - elapsed_milliseconds);
2483 goto recheck_status;
2485 else if (tv_sec < start_tv_sec)
2486 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): clock set backward\n");
2487 else if (elapsed_milliseconds < timeout_milliseconds)
2489 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): %d milliseconds remain\n", timeout_milliseconds - elapsed_milliseconds);
2497 _dbus_verbose (
"dbus_connection_send_with_reply_and_block() waiting for more memory\n");
2499 _dbus_memory_pause_based_on_timeout (timeout_milliseconds - elapsed_milliseconds);
2506 DBUS_ITERATION_DO_READING |
2507 DBUS_ITERATION_BLOCK,
2508 timeout_milliseconds - elapsed_milliseconds);
2511 goto recheck_status;
2514 _dbus_verbose (
"dbus_connection_send_with_reply_and_block(): Waited %d milliseconds and got no reply\n",
2515 elapsed_milliseconds);
2520 complete_pending_call_and_unlock (connection, pending,
NULL);
2524 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2525 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2571 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2572 _dbus_return_val_if_error_is_set (error,
NULL);
2574 connection = _dbus_connection_open_internal (address,
2614 _dbus_return_val_if_fail (address !=
NULL,
NULL);
2615 _dbus_return_val_if_error_is_set (error,
NULL);
2617 connection = _dbus_connection_open_internal (address,
2633 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
2659 free_outgoing_message (
void *element,
2680 _dbus_verbose (
"Finalizing connection %p\n", connection);
2706 while (link !=
NULL)
2712 _dbus_message_filter_unref (filter);
2729 free_outgoing_message,
2788 _dbus_return_if_fail (connection !=
NULL);
2811 printf (
"unref() connection %p count = %d\n", connection, connection->
refcount.
value);
2819 #ifndef DBUS_DISABLE_CHECKS
2822 _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",
2824 "Most likely, the application called unref() too many times and removed a reference belonging to libdbus, since this is a shared connection.\n" :
2825 "Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.\n");
2829 _dbus_connection_last_unref (connection);
2843 _dbus_connection_close_possibly_shared_and_unlock (
DBusConnection *connection)
2847 HAVE_LOCK_CHECK (connection);
2849 _dbus_verbose (
"Disconnecting %p\n", connection);
2868 status = _dbus_connection_get_dispatch_status_unlocked (connection);
2871 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
2922 _dbus_return_if_fail (connection !=
NULL);
2927 #ifndef DBUS_DISABLE_CHECKS
2932 _dbus_warn_check_failed (
"Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.\n");
2937 _dbus_connection_close_possibly_shared_and_unlock (connection);
2941 _dbus_connection_get_is_connected_unlocked (
DBusConnection *connection)
2943 HAVE_LOCK_CHECK (connection);
2965 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
2968 res = _dbus_connection_get_is_connected_unlocked (connection);
2987 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3021 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3066 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3096 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3104 #ifdef HAVE_UNIX_FD_PASSING
3136 _dbus_return_if_fail (connection !=
NULL);
3157 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3162 _dbus_connection_preallocate_send_unlocked (connection);
3166 return preallocated;
3182 _dbus_return_if_fail (connection !=
NULL);
3183 _dbus_return_if_fail (preallocated !=
NULL);
3184 _dbus_return_if_fail (connection == preallocated->
connection);
3210 _dbus_return_if_fail (connection !=
NULL);
3211 _dbus_return_if_fail (preallocated !=
NULL);
3212 _dbus_return_if_fail (message !=
NULL);
3213 _dbus_return_if_fail (preallocated->
connection == connection);
3222 #ifdef HAVE_UNIX_FD_PASSING
3225 message->n_unix_fds > 0)
3236 _dbus_connection_send_preallocated_and_unlock (connection,
3238 message, client_serial);
3242 _dbus_connection_send_unlocked_no_update (
DBusConnection *connection,
3251 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
3252 if (preallocated ==
NULL)
3255 _dbus_connection_send_preallocated_unlocked_no_update (connection,
3294 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3295 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3299 #ifdef HAVE_UNIX_FD_PASSING
3302 message->n_unix_fds > 0)
3319 reply_handler_timeout (
void *data)
3333 _dbus_verbose (
"middle\n");
3334 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3337 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3385 int timeout_milliseconds)
3391 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3392 _dbus_return_val_if_fail (message !=
NULL,
FALSE);
3393 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3396 *pending_return =
NULL;
3400 #ifdef HAVE_UNIX_FD_PASSING
3403 message->n_unix_fds > 0)
3415 if (!_dbus_connection_get_is_connected_unlocked (connection))
3423 timeout_milliseconds,
3424 reply_handler_timeout);
3426 if (pending ==
NULL)
3436 serial = _dbus_connection_get_next_client_serial (connection);
3447 if (!_dbus_connection_attach_pending_call_unlocked (connection,
3451 if (!_dbus_connection_send_unlocked_no_update (connection, message,
NULL))
3453 _dbus_connection_detach_pending_call_and_unlock (connection,
3455 goto error_unlocked;
3459 *pending_return = pending;
3462 _dbus_connection_detach_pending_call_unlocked (connection, pending);
3468 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3471 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3473 if (pending_return ==
NULL)
3518 int timeout_milliseconds,
3524 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3525 _dbus_return_val_if_fail (message !=
NULL,
NULL);
3526 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
NULL);
3527 _dbus_return_val_if_error_is_set (error,
NULL);
3529 #ifdef HAVE_UNIX_FD_PASSING
3533 message->n_unix_fds > 0)
3544 &pending, timeout_milliseconds))
3546 _DBUS_SET_OOM (error);
3550 if (pending ==
NULL)
3593 HAVE_LOCK_CHECK (connection);
3596 _dbus_connection_get_is_connected_unlocked (connection))
3598 _dbus_verbose (
"doing iteration in\n");
3599 HAVE_LOCK_CHECK (connection);
3602 DBUS_ITERATION_DO_READING |
3603 DBUS_ITERATION_DO_WRITING |
3604 DBUS_ITERATION_BLOCK,
3608 HAVE_LOCK_CHECK (connection);
3609 _dbus_verbose (
"middle\n");
3610 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3612 HAVE_LOCK_CHECK (connection);
3631 _dbus_return_if_fail (connection !=
NULL);
3635 status = _dbus_connection_flush_unlocked (connection);
3637 HAVE_LOCK_CHECK (connection);
3639 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3641 _dbus_verbose (
"end\n");
3655 _dbus_connection_read_write_dispatch (
DBusConnection *connection,
3656 int timeout_milliseconds,
3671 _dbus_verbose (
"doing dispatch\n");
3677 _dbus_verbose (
"pausing for memory\n");
3678 _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
3684 if (_dbus_connection_get_is_connected_unlocked (connection))
3686 _dbus_verbose (
"doing iteration\n");
3689 DBUS_ITERATION_DO_READING |
3690 DBUS_ITERATION_DO_WRITING |
3691 DBUS_ITERATION_BLOCK,
3692 timeout_milliseconds);
3696 HAVE_LOCK_CHECK (connection);
3702 progress_possible = connection->
n_incoming != 0 ||
3705 progress_possible = _dbus_connection_get_is_connected_unlocked (connection);
3711 return progress_possible;
3751 int timeout_milliseconds)
3753 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3754 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3755 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
TRUE);
3783 int timeout_milliseconds)
3785 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
3786 _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1,
FALSE);
3787 return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds,
FALSE);
3796 check_disconnected_message_arrived_unlocked (
DBusConnection *connection,
3799 HAVE_LOCK_CHECK (connection);
3836 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
3838 _dbus_verbose (
"start\n");
3849 _dbus_connection_acquire_dispatch (connection);
3858 check_disconnected_message_arrived_unlocked (connection, message);
3861 if (message ==
NULL)
3862 _dbus_connection_release_dispatch (connection);
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);
3918 _dbus_return_if_fail (connection !=
NULL);
3919 _dbus_return_if_fail (message !=
NULL);
3932 _dbus_verbose (
"Incoming message %p stolen from queue, %d incoming\n",
3937 _dbus_connection_release_dispatch (connection);
3939 status = _dbus_connection_get_dispatch_status_unlocked (connection);
3940 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
3947 _dbus_connection_pop_message_link_unlocked (
DBusConnection *connection)
3949 HAVE_LOCK_CHECK (connection);
3960 _dbus_verbose (
"Message %p (%s %s %s %s '%s') removed from incoming queue %p, %d incoming\n",
3975 check_disconnected_message_arrived_unlocked (connection, link->
data);
3987 _dbus_connection_pop_message_unlocked (
DBusConnection *connection)
3991 HAVE_LOCK_CHECK (connection);
3993 link = _dbus_connection_pop_message_link_unlocked (connection);
3999 message = link->
data;
4010 _dbus_connection_putback_message_link_unlocked (
DBusConnection *connection,
4013 HAVE_LOCK_CHECK (connection);
4025 _dbus_verbose (
"Message %p (%s %s %s '%s') put back into queue %p, %d incoming\n",
4063 _dbus_verbose (
"start\n");
4073 _dbus_connection_acquire_dispatch (connection);
4074 HAVE_LOCK_CHECK (connection);
4076 message = _dbus_connection_pop_message_unlocked (connection);
4078 _dbus_verbose (
"Returning popped message %p\n", message);
4080 _dbus_connection_release_dispatch (connection);
4082 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4083 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4098 HAVE_LOCK_CHECK (connection);
4103 _dbus_verbose (
"locking dispatch_mutex\n");
4108 _dbus_verbose (
"waiting for dispatch to be acquirable\n");
4117 _dbus_verbose (
"unlocking dispatch_mutex\n");
4134 HAVE_LOCK_CHECK (connection);
4136 _dbus_verbose (
"locking dispatch_mutex\n");
4144 _dbus_verbose (
"unlocking dispatch_mutex\n");
4161 HAVE_LOCK_CHECK (connection);
4179 _dbus_verbose (
"Dropping %d outgoing messages since we're disconnected\n",
4191 notify_disconnected_and_dispatch_complete_unlocked (
DBusConnection *connection)
4193 HAVE_LOCK_CHECK (connection);
4197 _dbus_verbose (
"Sending disconnect message\n");
4202 connection_timeout_and_complete_all_pending_calls_unlocked (connection);
4218 _dbus_connection_get_dispatch_status_unlocked (
DBusConnection *connection)
4220 HAVE_LOCK_CHECK (connection);
4234 _dbus_verbose (
"dispatch status = %s is_connected = %d\n",
4235 DISPATCH_STATUS_NAME (status), is_connected);
4245 notify_disconnected_unlocked (connection);
4253 status = notify_disconnected_and_dispatch_complete_unlocked (connection);
4266 _dbus_connection_update_dispatch_status_and_unlock (
DBusConnection *connection,
4273 HAVE_LOCK_CHECK (connection);
4293 connection_forget_shared_unlocked (connection);
4299 _dbus_verbose (
"Exiting on Disconnected signal\n");
4308 if (changed &&
function)
4310 _dbus_verbose (
"Notifying of change to dispatch status of %p now %d (%s)\n",
4311 connection, new_status,
4312 DISPATCH_STATUS_NAME (new_status));
4313 (* function) (connection, new_status, data);
4351 _dbus_verbose (
"start\n");
4355 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4366 _dbus_connection_peer_filter_unlocked_no_update (
DBusConnection *connection,
4385 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4415 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4439 "Unknown method invoked on org.freedesktop.DBus.Peer interface");
4443 sent = _dbus_connection_send_unlocked_no_update (connection, ret,
NULL);
4465 _dbus_connection_run_builtin_filters_unlocked_no_update (
DBusConnection *connection,
4471 return _dbus_connection_peer_filter_unlocked_no_update (connection, message);
4520 DBusList *link, *filter_list_copy, *message_link;
4528 _dbus_verbose (
"\n");
4531 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4535 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4544 _dbus_connection_acquire_dispatch (connection);
4545 HAVE_LOCK_CHECK (connection);
4547 message_link = _dbus_connection_pop_message_link_unlocked (connection);
4548 if (message_link ==
NULL)
4552 _dbus_verbose (
"another thread dispatched message (during acquire_dispatch above)\n");
4554 _dbus_connection_release_dispatch (connection);
4556 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4558 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4565 message = message_link->
data;
4567 _dbus_verbose (
" dispatching message %p (%s %s %s '%s')\n",
4592 _dbus_verbose (
"Dispatching a pending reply\n");
4593 complete_pending_call_and_unlock (connection, pending, message);
4597 _dbus_verbose (
"pending call completed in dispatch\n");
4602 result = _dbus_connection_run_builtin_filters_unlocked_no_update (connection, message);
4608 _dbus_connection_release_dispatch (connection);
4609 HAVE_LOCK_CHECK (connection);
4611 _dbus_connection_failed_pop (connection, message_link);
4614 _dbus_connection_update_dispatch_status_and_unlock (connection,
4631 while (link !=
NULL)
4638 _dbus_verbose (
" filter was removed in a callback function\n");
4643 _dbus_verbose (
" running filter on message %p\n", message);
4661 _dbus_verbose (
"No memory\n");
4666 _dbus_verbose (
"filter handled message in dispatch\n");
4673 _dbus_verbose (
" running object path dispatch on message %p (%s %s %s '%s')\n",
4684 HAVE_LOCK_CHECK (connection);
4692 _dbus_verbose (
"object tree handled message in dispatch\n");
4702 _dbus_verbose (
" sending error %s\n",
4708 _dbus_verbose (
"no memory for error string in dispatch\n");
4713 "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
4720 _dbus_verbose (
"no memory for error string in dispatch\n");
4732 _dbus_verbose (
"no memory for error reply in dispatch\n");
4736 preallocated = _dbus_connection_preallocate_send_unlocked (connection);
4738 if (preallocated ==
NULL)
4742 _dbus_verbose (
"no memory for error send in dispatch\n");
4746 _dbus_connection_send_preallocated_unlocked_no_update (connection, preallocated,
4754 _dbus_verbose (
" done dispatching %p (%s %s %s '%s') on connection %p\n", message,
4768 _dbus_verbose (
"out of memory\n");
4774 _dbus_connection_putback_message_link_unlocked (connection,
4779 _dbus_verbose (
" ... done dispatching\n");
4787 _dbus_connection_release_dispatch (connection);
4788 HAVE_LOCK_CHECK (connection);
4790 _dbus_verbose (
"before final status update\n");
4791 status = _dbus_connection_get_dispatch_status_unlocked (connection);
4794 _dbus_connection_update_dispatch_status_and_unlock (connection, status);
4872 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4877 add_function, remove_function,
4879 data, free_data_function);
4935 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
4940 add_function, remove_function,
4942 data, free_data_function);
4972 _dbus_return_if_fail (connection !=
NULL);
4986 (*old_free_data) (old_data);
5018 _dbus_return_if_fail (connection !=
NULL);
5032 (*old_free_data) (old_data);
5058 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5090 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5132 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5133 _dbus_return_val_if_fail (uid !=
NULL,
FALSE);
5168 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5169 _dbus_return_val_if_fail (pid !=
NULL,
FALSE);
5201 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5202 _dbus_return_val_if_fail (data !=
NULL,
FALSE);
5203 _dbus_return_val_if_fail (data_size !=
NULL,
FALSE);
5246 void *old_data =
NULL;
5249 _dbus_return_if_fail (connection !=
NULL);
5253 function, data, free_data_function,
5254 &old_data, &old_free_function);
5257 if (old_free_function !=
NULL)
5258 (* old_free_function) (old_data);
5294 char **windows_sid_p)
5298 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5299 _dbus_return_val_if_fail (windows_sid_p !=
NULL,
FALSE);
5345 void *old_data =
NULL;
5348 _dbus_return_if_fail (connection !=
NULL);
5352 function, data, free_data_function,
5353 &old_data, &old_free_function);
5356 if (old_free_function !=
NULL)
5357 (* old_free_function) (old_data);
5390 _dbus_return_if_fail (connection !=
NULL);
5418 _dbus_return_if_fail (connection !=
NULL);
5454 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5455 _dbus_return_val_if_fail (
function !=
NULL,
FALSE);
5468 _dbus_message_filter_unref (filter);
5506 _dbus_return_if_fail (connection !=
NULL);
5507 _dbus_return_if_fail (
function !=
NULL);
5514 while (link !=
NULL)
5516 filter = link->
data;
5518 if (filter->
function ==
function &&
5533 #ifndef DBUS_DISABLE_CHECKS
5536 _dbus_warn_check_failed (
"Attempt to remove filter function %p user data %p, but no such filter has been added\n",
5537 function, user_data);
5549 _dbus_message_filter_unref (filter);
5571 char **decomposed_path;
5574 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5575 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5576 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5577 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5586 (
const char **) decomposed_path, vtable,
5616 char **decomposed_path;
5620 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5621 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5622 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5623 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5632 (
const char **) decomposed_path, vtable,
5670 char **decomposed_path;
5673 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5674 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5675 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5676 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5685 (
const char **) decomposed_path, vtable,
5717 char **decomposed_path;
5721 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5722 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5723 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5724 _dbus_return_val_if_fail (vtable !=
NULL,
FALSE);
5733 (
const char **) decomposed_path, vtable,
5763 char **decomposed_path;
5765 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5766 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5767 _dbus_return_val_if_fail (path[0] ==
'/',
FALSE);
5796 char **decomposed_path;
5798 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5799 _dbus_return_val_if_fail (path !=
NULL,
FALSE);
5800 _dbus_return_val_if_fail (data_p !=
NULL,
FALSE);
5830 const char *parent_path,
5831 char ***child_entries)
5833 char **decomposed_path;
5835 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5836 _dbus_return_val_if_fail (parent_path !=
NULL,
FALSE);
5837 _dbus_return_val_if_fail (parent_path[0] ==
'/',
FALSE);
5838 _dbus_return_val_if_fail (child_entries !=
NULL,
FALSE);
5846 (
const char **) decomposed_path,
5892 _dbus_return_if_fail (*slot_p >= 0);
5929 _dbus_return_val_if_fail (connection !=
NULL,
FALSE);
5930 _dbus_return_val_if_fail (slot >= 0,
FALSE);
5932 SLOTS_LOCK (connection);
5936 slot, data, free_data_func,
5937 &old_free_func, &old_data);
5939 SLOTS_UNLOCK (connection);
5945 (* old_free_func) (old_data);
5974 _dbus_return_val_if_fail (connection !=
NULL,
NULL);
5976 SLOTS_LOCK (connection);
5982 SLOTS_UNLOCK (connection);
5996 _dbus_modify_sigpipe = will_modify_sigpipe !=
FALSE;
6011 _dbus_return_if_fail (connection !=
NULL);
6030 _dbus_return_val_if_fail (connection !=
NULL, 0);
6050 _dbus_return_if_fail (connection !=
NULL);
6069 _dbus_return_val_if_fail (connection !=
NULL, 0);
6106 _dbus_return_if_fail (connection !=
NULL);
6125 _dbus_return_val_if_fail (connection !=
NULL, 0);
6148 _dbus_return_if_fail (connection !=
NULL);
6167 _dbus_return_val_if_fail (connection !=
NULL, 0);
6190 _dbus_return_val_if_fail (connection !=
NULL, 0);
6210 _dbus_return_val_if_fail (connection !=
NULL, 0);