diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index bd161a06c..bec01cf22 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,7 @@ struct client { int ref; + unsigned int connected:1; unsigned int disconnecting:1; unsigned int need_flush:1; unsigned int paused:1; @@ -826,6 +828,21 @@ on_remote_data(void *data, int fd, uint32_t mask) goto error; } if (mask & SPA_IO_OUT || impl->need_flush) { + if (!impl->connected) { + socklen_t len = sizeof res; + + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &res, &len) < 0) { + res = -errno; + pw_log_error(NAME" getsockopt: %m"); + goto error; + } + if (res != 0) { + res = -res; + goto error; + } + impl->connected = true; + pw_log_debug(NAME" %p: connected, fd %d", impl, fd); + } impl->need_flush = false; res = pw_protocol_native_connection_flush(conn); if (res >= 0) { @@ -881,6 +898,7 @@ static int impl_connect_fd(struct pw_protocol_client *client, int fd, bool do_cl struct client *impl = SPA_CONTAINER_OF(client, struct client, this); int res; + impl->connected = false; impl->disconnecting = false; pw_protocol_native_connection_set_fd(impl->connection, fd); diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c index ac0475e3a..6cffcdea3 100644 --- a/src/modules/module-protocol-native/local-socket.c +++ b/src/modules/module-protocol-native/local-socket.c @@ -124,8 +124,12 @@ static int try_connect(struct pw_protocol_client *client, pw_log_debug("connect to '%s' failed: %m", name); if (errno == ENOENT) errno = EHOSTDOWN; - res = -errno; - goto error_close; + if (errno == EAGAIN) { + pw_log_info("client %p: connect pending, fd %d", client, fd); + } else { + res = -errno; + goto error_close; + } } res = pw_protocol_client_connect_fd(client, fd, true);