- /* See if we still need the write watch */
- check_write_watch (transport);
- }
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- else
- {
- if (watch == unix_transport->read_watch)
- _dbus_verbose ("asked to handle read watch with non-read condition 0x%x\n",
- flags);
- else if (watch == unix_transport->write_watch)
- _dbus_verbose ("asked to handle write watch with non-write condition 0x%x\n",
- flags);
- else
- _dbus_verbose ("asked to handle watch %p on fd %d that we don't recognize\n",
- watch, dbus_watch_get_fd (watch));
- }
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
-
- return TRUE;
-}
-
-static void
-unix_disconnect (DBusTransport *transport)
-{
- DBusTransportUnix *unix_transport = (DBusTransportUnix*) transport;
-
- _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
-
- free_watches (transport);
-
- _dbus_close (unix_transport->fd, NULL);
- unix_transport->fd = -1;
-}
-
-static dbus_bool_t
-unix_connection_set (DBusTransport *transport)
-{
- DBusTransportUnix *unix_transport = (DBusTransportUnix*) transport;
-
- _dbus_watch_set_handler (unix_transport->write_watch,
- _dbus_connection_handle_watch,
- transport->connection, NULL);
-
- _dbus_watch_set_handler (unix_transport->read_watch,
- _dbus_connection_handle_watch,
- transport->connection, NULL);
-
- if (!_dbus_connection_add_watch (transport->connection,
- unix_transport->write_watch))
- return FALSE;
-
- if (!_dbus_connection_add_watch (transport->connection,
- unix_transport->read_watch))
- {
- _dbus_connection_remove_watch (transport->connection,
- unix_transport->write_watch);
- return FALSE;
- }
-
- check_read_watch (transport);
- check_write_watch (transport);
-
- return TRUE;
-}
-
-/**
- * @todo We need to have a way to wake up the select sleep if
- * a new iteration request comes in with a flag (read/write) that
- * we're not currently serving. Otherwise a call that just reads
- * could block a write call forever (if there are no incoming
- * messages).
- */
-static void
-unix_do_iteration (DBusTransport *transport,
- unsigned int flags,
- int timeout_milliseconds)
-{
- DBusTransportUnix *unix_transport = (DBusTransportUnix*) transport;
- DBusPollFD poll_fd;
- int poll_res;
- int poll_timeout;
-
- _dbus_verbose (" iteration flags = %s%s timeout = %d read_watch = %p write_watch = %p fd = %d\n",
- flags & DBUS_ITERATION_DO_READING ? "read" : "",
- flags & DBUS_ITERATION_DO_WRITING ? "write" : "",
- timeout_milliseconds,
- unix_transport->read_watch,
- unix_transport->write_watch,
- unix_transport->fd);
-
- /* the passed in DO_READING/DO_WRITING flags indicate whether to
- * read/write messages, but regardless of those we may need to block
- * for reading/writing to do auth. But if we do reading for auth,
- * we don't want to read any messages yet if not given DO_READING.
- */
-
- poll_fd.fd = unix_transport->fd;
- poll_fd.events = 0;
-
- if (_dbus_transport_get_is_authenticated (transport))
- {
- /* This is kind of a hack; if we have stuff to write, then try
- * to avoid the poll. This is probably about a 5% speedup on an
- * echo client/server.
- *
- * If both reading and writing were requested, we want to avoid this
- * since it could have funky effects:
- * - both ends spinning waiting for the other one to read
- * data so they can finish writing
- * - prioritizing all writing ahead of reading
- */
- if ((flags & DBUS_ITERATION_DO_WRITING) &&
- !(flags & (DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK)) &&
- !transport->disconnected &&
- _dbus_connection_has_messages_to_send_unlocked (transport->connection))