protocol: destroy clients

Destroy clients before destroying the protocol
This commit is contained in:
Wim Taymans 2017-08-23 10:19:19 +02:00
parent cc95f975ce
commit 61e7218006
2 changed files with 39 additions and 36 deletions

View file

@ -413,7 +413,7 @@ get_name(const struct pw_properties *properties)
return name;
}
static int impl_connect(struct pw_protocol_client *conn)
static int impl_connect(struct pw_protocol_client *client)
{
struct sockaddr_un addr;
socklen_t size;
@ -442,11 +442,10 @@ static int impl_connect(struct pw_protocol_client *conn)
size = offsetof(struct sockaddr_un, sun_path) + name_size;
if (connect(fd, (struct sockaddr *) &addr, size) < 0) {
if (connect(fd, (struct sockaddr *) &addr, size) < 0)
goto error_close;
}
return conn->connect_fd(conn, fd);
return pw_protocol_client_connect_fd(client, fd);
error_close:
close(fd);
@ -548,10 +547,10 @@ static const struct pw_protocol_native_connection_events conn_events = {
.need_flush = on_need_flush,
};
static int impl_connect_fd(struct pw_protocol_client *conn, int fd)
static int impl_connect_fd(struct pw_protocol_client *client, int fd)
{
struct client *impl = SPA_CONTAINER_OF(conn, struct client, this);
struct pw_remote *remote = conn->remote;
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
struct pw_remote *remote = client->remote;
impl->connection = pw_protocol_native_connection_new(fd);
if (impl->connection == NULL)
@ -575,10 +574,10 @@ static int impl_connect_fd(struct pw_protocol_client *conn, int fd)
return -1;
}
static void impl_disconnect(struct pw_protocol_client *conn)
static void impl_disconnect(struct pw_protocol_client *client)
{
struct client *impl = SPA_CONTAINER_OF(conn, struct client, this);
struct pw_remote *remote = conn->remote;
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
struct pw_remote *remote = client->remote;
impl->disconnecting = true;
@ -595,14 +594,14 @@ static void impl_disconnect(struct pw_protocol_client *conn)
impl->fd = -1;
}
static void impl_destroy(struct pw_protocol_client *conn)
static void impl_destroy(struct pw_protocol_client *client)
{
struct client *impl = SPA_CONTAINER_OF(conn, struct client, this);
struct pw_remote *remote = conn->remote;
struct client *impl = SPA_CONTAINER_OF(client, struct client, this);
struct pw_remote *remote = client->remote;
pw_loop_destroy_source(remote->core->main_loop, impl->flush_event);
spa_list_remove(&conn->link);
spa_list_remove(&client->link);
free(impl);
}
@ -636,9 +635,13 @@ impl_new_client(struct pw_protocol *protocol,
static void destroy_server(struct pw_protocol_server *server)
{
struct server *s = SPA_CONTAINER_OF(server, struct server, this);
struct pw_client *client, *tmp;
spa_list_remove(&server->link);
spa_list_for_each_safe(client, tmp, &server->client_list, protocol_link)
pw_client_destroy(client);
if (s->source)
pw_loop_destroy_source(s->loop, s->source);
if (s->addr.sun_path[0])

View file

@ -84,15 +84,15 @@ void pw_protocol_destroy(struct pw_protocol *protocol)
spa_list_remove(&protocol->link);
spa_list_for_each_safe(marshal, t1, &protocol->marshal_list, link)
free(marshal);
spa_list_for_each_safe(server, t2, &protocol->server_list, link)
pw_protocol_server_destroy(server);
spa_list_for_each_safe(client, t3, &protocol->client_list, link)
pw_protocol_client_destroy(client);
spa_list_for_each_safe(marshal, t1, &protocol->marshal_list, link)
free(marshal);
free(protocol->name);
free(impl);