From 3cd0b90ff6a9b264c9d3e122b7420412192726ba Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Dec 2008 14:30:03 +0100 Subject: client: run client_manager_expire() in an idle event With the GLib main loop, the client manager can install its own event in case a client is expired. No need for main.c to call client_manager_expire() manually. --- src/client.c | 23 ++++++++++++++++++++++- src/client.h | 1 - src/main.c | 1 - 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/client.c b/src/client.c index 117155bd9..9a251d3db 100644 --- a/src/client.c +++ b/src/client.c @@ -110,6 +110,7 @@ struct client { static LIST_HEAD(clients); static unsigned num_clients; +static guint expire_source_id; static void client_write_deferred(struct client *client); @@ -135,8 +136,27 @@ void client_set_permission(struct client *client, unsigned permission) client->permission = permission; } +static void +client_manager_expire(void); + +/** + * An idle event which calls client_manager_expire(). + */ +static gboolean +client_manager_expire_event(G_GNUC_UNUSED gpointer data) +{ + expire_source_id = 0; + client_manager_expire(); + return false; +} + static inline void client_set_expired(struct client *client) { + if (expire_source_id == 0 && client->fd >= 0) + /* delayed deletion */ + expire_source_id = g_idle_add(client_manager_expire_event, + NULL); + if (client->source_id != 0) { g_source_remove(client->source_id); client->source_id = 0; @@ -601,7 +621,8 @@ void client_manager_deinit(void) client_max_connections = 0; } -void client_manager_expire(void) +static void +client_manager_expire(void) { struct client *client, *n; diff --git a/src/client.h b/src/client.h index dabd1c576..d2e3301dc 100644 --- a/src/client.h +++ b/src/client.h @@ -29,7 +29,6 @@ struct sockaddr; void client_manager_init(void); void client_manager_deinit(void); -void client_manager_expire(void); void client_new(int fd, const struct sockaddr *addr, int uid); diff --git a/src/main.c b/src/main.c index 28cce4b71..23bff7c8a 100644 --- a/src/main.c +++ b/src/main.c @@ -196,7 +196,6 @@ main_notify_triggered(void) unsigned flags; syncPlayerAndPlaylist(); - client_manager_expire(); reap_update_task(); /* send "idle" notificaions to all subscribed -- cgit v1.2.3