mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
connection: add do_close flag to connect_fd
Make pw_remote_connect_fd() not automatically close the provided fd but let the caller take care of that. This allows us to reuse the fd in pipewiresrc. Fixes #155
This commit is contained in:
parent
5850044599
commit
216b641ebb
5 changed files with 13 additions and 11 deletions
|
|
@ -570,7 +570,7 @@ static const struct pw_protocol_native_connection_events conn_events = {
|
||||||
.need_flush = on_need_flush,
|
.need_flush = on_need_flush,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int impl_connect_fd(struct pw_protocol_client *client, int fd)
|
static int impl_connect_fd(struct pw_protocol_client *client, int fd, bool do_close)
|
||||||
{
|
{
|
||||||
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
|
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
|
||||||
struct pw_remote *remote = client->remote;
|
struct pw_remote *remote = client->remote;
|
||||||
|
|
@ -589,13 +589,14 @@ static int impl_connect_fd(struct pw_protocol_client *client, int fd)
|
||||||
impl->source = pw_loop_add_io(remote->core->main_loop,
|
impl->source = pw_loop_add_io(remote->core->main_loop,
|
||||||
fd,
|
fd,
|
||||||
SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR,
|
SPA_IO_IN | SPA_IO_HUP | SPA_IO_ERR,
|
||||||
true, on_remote_data, impl);
|
do_close, on_remote_data, impl);
|
||||||
if (impl->source == NULL)
|
if (impl->source == NULL)
|
||||||
goto error_close;
|
goto error_close;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_close:
|
error_close:
|
||||||
|
if (do_close)
|
||||||
close(fd);
|
close(fd);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
|
||||||
goto error_close;
|
goto error_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = pw_protocol_client_connect_fd(client, fd);
|
res = pw_protocol_client_connect_fd(client, fd, true);
|
||||||
|
|
||||||
done_callback(data, res);
|
done_callback(data, res);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ struct pw_protocol_client {
|
||||||
int (*connect) (struct pw_protocol_client *client,
|
int (*connect) (struct pw_protocol_client *client,
|
||||||
void (*done_callback) (void *data, int result),
|
void (*done_callback) (void *data, int result),
|
||||||
void *data);
|
void *data);
|
||||||
int (*connect_fd) (struct pw_protocol_client *client, int fd);
|
int (*connect_fd) (struct pw_protocol_client *client, int fd, bool close);
|
||||||
int (*steal_fd) (struct pw_protocol_client *client);
|
int (*steal_fd) (struct pw_protocol_client *client);
|
||||||
void (*disconnect) (struct pw_protocol_client *client);
|
void (*disconnect) (struct pw_protocol_client *client);
|
||||||
void (*destroy) (struct pw_protocol_client *client);
|
void (*destroy) (struct pw_protocol_client *client);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define pw_protocol_client_connect(c,cb,d) ((c)->connect(c,cb,d))
|
#define pw_protocol_client_connect(c,cb,d) ((c)->connect(c,cb,d))
|
||||||
#define pw_protocol_client_connect_fd(c,fd) ((c)->connect_fd(c,fd))
|
#define pw_protocol_client_connect_fd(c,fd,cl) ((c)->connect_fd(c,fd,cl))
|
||||||
#define pw_protocol_client_steal_fd(c) ((c)->steal_fd(c))
|
#define pw_protocol_client_steal_fd(c) ((c)->steal_fd(c))
|
||||||
#define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
|
#define pw_protocol_client_disconnect(c) ((c)->disconnect(c))
|
||||||
#define pw_protocol_client_destroy(c) ((c)->destroy(c))
|
#define pw_protocol_client_destroy(c) ((c)->destroy(c))
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ void pw_remote_destroy(struct pw_remote *remote)
|
||||||
spa_list_consume(stream, &remote->stream_list, link)
|
spa_list_consume(stream, &remote->stream_list, link)
|
||||||
pw_stream_destroy(stream);
|
pw_stream_destroy(stream);
|
||||||
|
|
||||||
pw_protocol_client_destroy (remote->conn);
|
pw_protocol_client_destroy(remote->conn);
|
||||||
|
|
||||||
spa_list_remove(&remote->link);
|
spa_list_remove(&remote->link);
|
||||||
|
|
||||||
|
|
@ -391,7 +391,7 @@ int pw_remote_connect(struct pw_remote *remote)
|
||||||
|
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL);
|
pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL);
|
||||||
|
|
||||||
if ((res = pw_protocol_client_connect (remote->conn, done_connect, remote)) < 0) {
|
if ((res = pw_protocol_client_connect(remote->conn, done_connect, remote)) < 0) {
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR,
|
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR,
|
||||||
"connect failed %s", spa_strerror(res));
|
"connect failed %s", spa_strerror(res));
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -406,7 +406,7 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd)
|
||||||
|
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL);
|
pw_remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL);
|
||||||
|
|
||||||
if ((res = pw_protocol_client_connect_fd (remote->conn, fd)) < 0) {
|
if ((res = pw_protocol_client_connect_fd(remote->conn, fd, false)) < 0) {
|
||||||
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR,
|
pw_remote_update_state(remote, PW_REMOTE_STATE_ERROR,
|
||||||
"connect_fd failed %s", spa_strerror(res));
|
"connect_fd failed %s", spa_strerror(res));
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -436,7 +436,7 @@ int pw_remote_disconnect(struct pw_remote *remote)
|
||||||
spa_list_for_each_safe(stream, s2, &remote->stream_list, link)
|
spa_list_for_each_safe(stream, s2, &remote->stream_list, link)
|
||||||
pw_stream_disconnect(stream);
|
pw_stream_disconnect(stream);
|
||||||
|
|
||||||
pw_protocol_client_disconnect (remote->conn);
|
pw_protocol_client_disconnect(remote->conn);
|
||||||
|
|
||||||
remote->core_proxy = NULL;
|
remote->core_proxy = NULL;
|
||||||
remote->client_proxy = NULL;
|
remote->client_proxy = NULL;
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,8 @@ void pw_remote_add_listener(struct pw_remote *remote,
|
||||||
int pw_remote_connect(struct pw_remote *remote);
|
int pw_remote_connect(struct pw_remote *remote);
|
||||||
|
|
||||||
/** Connect to a remote PipeWire on the given socket \memberof pw_remote
|
/** Connect to a remote PipeWire on the given socket \memberof pw_remote
|
||||||
* \param fd the connected socket to use
|
* \param fd the connected socket to use, the socket will not be closed
|
||||||
|
* automatically on disconnect or error.
|
||||||
* \return 0 on success, < 0 on error */
|
* \return 0 on success, < 0 on error */
|
||||||
int pw_remote_connect_fd(struct pw_remote *remote, int fd);
|
int pw_remote_connect_fd(struct pw_remote *remote, int fd);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue