aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-31 14:30:03 +0100
committerMax Kellermann <max@duempel.org>2008-12-31 14:30:03 +0100
commit3cd0b90ff6a9b264c9d3e122b7420412192726ba (patch)
treee78ac533f914ba732ead4b4da85e96f986b17d34 /src/client.c
parenta12b57e1e938e92b906c22ee132ce9d4f90e0124 (diff)
downloadmpd-3cd0b90ff6a9b264c9d3e122b7420412192726ba.tar.gz
mpd-3cd0b90ff6a9b264c9d3e122b7420412192726ba.tar.xz
mpd-3cd0b90ff6a9b264c9d3e122b7420412192726ba.zip
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.
Diffstat (limited to '')
-rw-r--r--src/client.c23
1 files changed, 22 insertions, 1 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;