From 0b2e4a18ffee2ed641f2865de87ea201867db725 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 5 Dec 2019 11:43:05 +0100 Subject: [PATCH] protocol-native: make the connection earlier Make the connection as soon as we create the client. We create it without file descriptor and then set it when we connect. This makes it possible to use the connection to queue messages before we connect. --- src/modules/module-protocol-native.c | 19 +++++++++++++------ .../module-protocol-native/connection.c | 6 ++++++ .../module-protocol-native/connection.h | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 62e9f94d5..e930007a0 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -703,12 +703,7 @@ static int impl_connect_fd(struct pw_protocol_client *client, int fd, bool do_cl impl->disconnecting = false; - impl->connection = pw_protocol_native_connection_new(remote->core, fd); - if (impl->connection == NULL) { - res = -errno; - goto error_cleanup; - } - + pw_protocol_native_connection_set_fd(impl->connection, fd); impl->source = pw_loop_add_io(remote->core->main_loop, fd, SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR, @@ -766,6 +761,7 @@ impl_new_client(struct pw_protocol *protocol, struct client *impl; struct pw_protocol_client *this; const char *str = NULL; + int res; if ((impl = calloc(1, sizeof(struct client))) == NULL) return NULL; @@ -774,6 +770,12 @@ impl_new_client(struct pw_protocol *protocol, this->protocol = protocol; this->remote = remote; + impl->connection = pw_protocol_native_connection_new(remote->core, -1); + if (impl->connection == NULL) { + res = -errno; + goto error_free; + } + if (properties) str = pw_properties_get(properties, PW_KEY_REMOTE_INTENTION); if (str == NULL) @@ -792,6 +794,11 @@ impl_new_client(struct pw_protocol *protocol, spa_list_append(&protocol->client_list, &this->link); return this; + +error_free: + free(impl); + errno = -res; + return NULL; } static void destroy_server(struct pw_protocol_server *server) diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c index c3260fd5d..2b26dbfc9 100644 --- a/src/modules/module-protocol-native/connection.c +++ b/src/modules/module-protocol-native/connection.c @@ -266,6 +266,12 @@ no_mem: return NULL; } +int pw_protocol_native_connection_set_fd(struct pw_protocol_native_connection *conn, int fd) +{ + conn->fd = fd; + return 0; +} + /** Destroy a connection * * \param conn the connection to destroy diff --git a/src/modules/module-protocol-native/connection.h b/src/modules/module-protocol-native/connection.h index c4eb476b0..4e37af4dd 100644 --- a/src/modules/module-protocol-native/connection.h +++ b/src/modules/module-protocol-native/connection.h @@ -72,6 +72,8 @@ pw_protocol_native_connection_add_listener(struct pw_protocol_native_connection struct pw_protocol_native_connection * pw_protocol_native_connection_new(struct pw_core *core, int fd); +int pw_protocol_native_connection_set_fd(struct pw_protocol_native_connection *conn, int fd); + void pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn);