pulse-server: use invalid id for unused connect_tag

Because 0 happens to be the first tag and can cause confusion.
This commit is contained in:
Wim Taymans 2020-11-06 16:08:13 +01:00
parent a2549fc638
commit 96599f74e7

View file

@ -84,7 +84,7 @@ struct client {
struct impl *impl; struct impl *impl;
struct server *server; struct server *server;
struct spa_source *source; struct spa_source *source;
uint32_t version; uint32_t version;
@ -518,12 +518,26 @@ static void manager_sync(void *data)
{ {
struct client *client = data; struct client *client = data;
if (client->connect_tag) { pw_log_info(NAME" %p: manager sync", client);
if (client->connect_tag != SPA_ID_INVALID) {
reply_set_client_name(client, client->connect_tag); reply_set_client_name(client, client->connect_tag);
client->connect_tag = 0; client->connect_tag = SPA_ID_INVALID;
} }
} }
static struct stream *find_stream(struct client *client, uint32_t id)
{
union pw_map_item *item;
pw_array_for_each(item, &client->streams.items) {
struct stream *s = item->data;
if (!pw_map_item_is_free(item) &&
s->id == id)
return s;
}
return NULL;
}
static uint32_t get_event_and_id(struct client *client, struct pw_manager_object *o, uint32_t *id) static uint32_t get_event_and_id(struct client *client, struct pw_manager_object *o, uint32_t *id)
{ {
uint32_t event = 0, res_id = o->id; uint32_t event = 0, res_id = o->id;
@ -635,23 +649,11 @@ static const struct pw_manager_events manager_events = {
.metadata = manager_metadata, .metadata = manager_metadata,
}; };
static struct stream *find_stream(struct client *client, uint32_t id)
{
union pw_map_item *item;
pw_array_for_each(item, &client->streams.items) {
struct stream *s = item->data;
if (!pw_map_item_is_free(item) &&
s->id == id)
return s;
}
return NULL;
}
static int do_set_client_name(struct client *client, uint32_t command, uint32_t tag, struct message *m) static int do_set_client_name(struct client *client, uint32_t command, uint32_t tag, struct message *m)
{ {
struct impl *impl = client->impl; struct impl *impl = client->impl;
const char *name = NULL; const char *name = NULL;
int res, changed = 0; int res = 0, changed = 0;
if (client->version < 13) { if (client->version < 13) {
if (message_get(m, if (message_get(m,
@ -687,12 +689,12 @@ static int do_set_client_name(struct client *client, uint32_t command, uint32_t
client->connect_tag = tag; client->connect_tag = tag;
pw_manager_add_listener(client->manager, &client->manager_listener, pw_manager_add_listener(client->manager, &client->manager_listener,
&manager_events, client); &manager_events, client);
res = 0;
} else { } else {
if (changed) if (changed)
pw_core_update_properties(client->core, &client->props->dict); pw_core_update_properties(client->core, &client->props->dict);
res = reply_set_client_name(client, tag); if (client->connect_tag == SPA_ID_INVALID)
res = reply_set_client_name(client, tag);
} }
return res; return res;
error: error:
@ -4222,11 +4224,11 @@ error:
static void static void
on_connect(void *data, int fd, uint32_t mask) on_connect(void *data, int fd, uint32_t mask)
{ {
struct server *server = data; struct server *server = data;
struct impl *impl = server->impl; struct impl *impl = server->impl;
struct sockaddr_un name; struct sockaddr_un name;
socklen_t length; socklen_t length;
int client_fd; int client_fd;
struct client *client; struct client *client;
client = calloc(1, sizeof(struct client)); client = calloc(1, sizeof(struct client));
@ -4235,6 +4237,7 @@ on_connect(void *data, int fd, uint32_t mask)
client->impl = impl; client->impl = impl;
client->server = server; client->server = server;
client->connect_tag = SPA_ID_INVALID;
spa_list_append(&server->clients, &client->link); spa_list_append(&server->clients, &client->link);
pw_map_init(&client->streams, 16, 16); pw_map_init(&client->streams, 16, 16);
spa_list_init(&client->free_messages); spa_list_init(&client->free_messages);