-
-
- out:
- /* We need to install the write watch only if we did not
- * successfully write everything. Note we need to be careful that we
- * don't call check_write_watch *before* do_writing, since it's
- * inefficient to add the write watch, and we can avoid it most of
- * the time since we can write immediately.
- *
- * However, we MUST always call check_write_watch(); DBusConnection code
- * relies on the fact that running an iteration will notice that
- * messages are pending.
- */
- check_write_watch (transport);
-
- _dbus_verbose (" ... leaving do_iteration()\n");
-}
-
-static void
-unix_live_messages_changed (DBusTransport *transport)
-{
- /* See if we should look for incoming messages again */
- check_read_watch (transport);
-}
-
-
-static dbus_bool_t
-unix_get_unix_fd (DBusTransport *transport,
- int *fd_p)
-{
- DBusTransportUnix *unix_transport = (DBusTransportUnix*) transport;
-
- *fd_p = unix_transport->fd;
-
- return TRUE;
-}
-
-static const DBusTransportVTable unix_vtable = {
- unix_finalize,
- unix_handle_watch,
- unix_disconnect,
- unix_connection_set,
- unix_do_iteration,
- unix_live_messages_changed,
- unix_get_unix_fd
-};
-
-/**
- * Creates a new transport for the given file descriptor. The file
- * descriptor must be nonblocking (use _dbus_set_fd_nonblocking() to
- * make it so). This function is shared by various transports that
- * boil down to a full duplex file descriptor.
- *
- * @param fd the file descriptor.
- * @param server_guid non-#NULL if this transport is on the server side of a connection
- * @param address the transport's address
- * @returns the new transport, or #NULL if no memory.
- */
-DBusTransport*
-_dbus_transport_new_for_fd (int fd,
- const DBusString *server_guid,
- const DBusString *address)
-{
- DBusTransportUnix *unix_transport;
-
- unix_transport = dbus_new0 (DBusTransportUnix, 1);
- if (unix_transport == NULL)
- return NULL;
-
- if (!_dbus_string_init (&unix_transport->encoded_outgoing))
- goto failed_0;
-
- if (!_dbus_string_init (&unix_transport->encoded_incoming))
- goto failed_1;
-
- unix_transport->write_watch = _dbus_watch_new (fd,
- DBUS_WATCH_WRITABLE,
- FALSE,
- NULL, NULL, NULL);
- if (unix_transport->write_watch == NULL)
- goto failed_2;
-
- unix_transport->read_watch = _dbus_watch_new (fd,
- DBUS_WATCH_READABLE,
- FALSE,
- NULL, NULL, NULL);
- if (unix_transport->read_watch == NULL)
- goto failed_3;
-
- if (!_dbus_transport_init_base (&unix_transport->base,
- &unix_vtable,
- server_guid, address))
- goto failed_4;
-
- unix_transport->fd = fd;
- unix_transport->message_bytes_written = 0;
-
- /* These values should probably be tunable or something. */
- unix_transport->max_bytes_read_per_iteration = 2048;
- unix_transport->max_bytes_written_per_iteration = 2048;
-
- return (DBusTransport*) unix_transport;
-
- failed_4:
- _dbus_watch_unref (unix_transport->read_watch);
- failed_3:
- _dbus_watch_unref (unix_transport->write_watch);
- failed_2:
- _dbus_string_free (&unix_transport->encoded_incoming);
- failed_1:
- _dbus_string_free (&unix_transport->encoded_outgoing);
- failed_0:
- dbus_free (unix_transport);
- return NULL;
-}
-
-/**
- * Creates a new transport for the given Unix domain socket
- * path. This creates a client-side of a transport.
- *
- * @todo once we add a way to escape paths in a dbus
- * address, this function needs to do escaping.
- *
- * @param path the path to the domain socket.
- * @param abstract #TRUE to use abstract socket namespace
- * @param error address where an error can be returned.
- * @returns a new transport, or #NULL on failure.
- */
-DBusTransport*
-_dbus_transport_new_for_domain_socket (const char *path,
- dbus_bool_t abstract,
- DBusError *error)
-{
- int fd;
- DBusTransport *transport;
- DBusString address;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- if (!_dbus_string_init (&address))
- {
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return NULL;
- }
-
- fd = -1;
-
- if ((abstract &&
- !_dbus_string_append (&address, "unix:abstract=")) ||
- (!abstract &&
- !_dbus_string_append (&address, "unix:path=")) ||
- !_dbus_string_append (&address, path))