static void check_read_watch (DBusTransport *transport) { DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport; dbus_bool_t need_read_watch; _dbus_verbose ("fd = %" DBUS_SOCKET_FORMAT "\n", _dbus_socket_printable (socket_transport->fd)); if (transport->connection == NULL) return; if (transport->disconnected) { _dbus_assert (socket_transport->read_watch == NULL); return; } _dbus_transport_ref (transport); if (_dbus_transport_try_to_authenticate (transport)) need_read_watch = (_dbus_counter_get_size_value (transport->live_messages) < transport->max_live_messages_size) && (_dbus_counter_get_unix_fd_value (transport->live_messages) < transport->max_live_messages_unix_fds); else { if (transport->receive_credentials_pending) need_read_watch = TRUE; else { /* The reason to disable need_read_watch when not WAITING_FOR_INPUT * is to avoid spinning on the file descriptor when we're waiting * to write or for some other part of the auth process */ DBusAuthState auth_state; auth_state = _dbus_auth_do_work (transport->auth); /* If we need memory we install the read watch just in case, * if there's no need for it, it will get de-installed * next time we try reading. If we're authenticated we * install it since we normally have it installed while * authenticated. */ if (auth_state == DBUS_AUTH_STATE_WAITING_FOR_INPUT || auth_state == DBUS_AUTH_STATE_WAITING_FOR_MEMORY || auth_state == DBUS_AUTH_STATE_AUTHENTICATED) need_read_watch = TRUE; else need_read_watch = FALSE; } } _dbus_verbose (" setting read watch enabled = %d\n", need_read_watch); _dbus_connection_toggle_watch_unlocked (transport->connection, socket_transport->read_watch, need_read_watch); _dbus_transport_unref (transport); }
static void live_messages_notify (DBusCounter *counter, void *user_data) { DBusTransport *transport = user_data; _dbus_transport_ref (transport); #if 0 _dbus_verbose ("Size counter value is now %d\n", (int) _dbus_counter_get_size_value (counter)); _dbus_verbose ("Unix FD counter value is now %d\n", (int) _dbus_counter_get_unix_fd_value (counter)); #endif /* disable or re-enable the read watch for the transport if * required. */ if (transport->vtable->live_messages_changed) { _dbus_connection_lock (transport->connection); (* transport->vtable->live_messages_changed) (transport); _dbus_connection_unlock (transport->connection); } _dbus_transport_unref (transport); }
/** * Reports our current dispatch status (whether there's buffered * data to be queued as messages, or not, or we need memory). * * @param transport the transport * @returns current status */ DBusDispatchStatus _dbus_transport_get_dispatch_status (DBusTransport *transport) { if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size || _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds) return DBUS_DISPATCH_COMPLETE; /* complete for now */ if (!_dbus_transport_get_is_authenticated (transport)) { if (_dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_WAITING_FOR_MEMORY) return DBUS_DISPATCH_NEED_MEMORY; else if (!_dbus_transport_get_is_authenticated (transport)) return DBUS_DISPATCH_COMPLETE; } if (!transport->unused_bytes_recovered && !recover_unused_bytes (transport)) return DBUS_DISPATCH_NEED_MEMORY; transport->unused_bytes_recovered = TRUE; if (!_dbus_message_loader_queue_messages (transport->loader)) return DBUS_DISPATCH_NEED_MEMORY; if (_dbus_message_loader_peek_message (transport->loader) != NULL) return DBUS_DISPATCH_DATA_REMAINS; else return DBUS_DISPATCH_COMPLETE; }
void _dbus_transport_get_stats (DBusTransport *transport, dbus_uint32_t *queue_bytes, dbus_uint32_t *queue_fds, dbus_uint32_t *peak_queue_bytes, dbus_uint32_t *peak_queue_fds) { if (queue_bytes != NULL) *queue_bytes = _dbus_counter_get_size_value (transport->live_messages); if (queue_fds != NULL) *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages); if (peak_queue_bytes != NULL) *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages); if (peak_queue_fds != NULL) *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages); }