configure.ac: Move OpenAL to Audio Output Plugins (nonstreaming), add header.
[mpd-mk.git] / src / client_expire.c
bloba5b0be04737827cc6369ec345f77813b10420bea
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "client_internal.h"
23 static guint expire_source_id;
25 void
26 client_set_expired(struct client *client)
28 if (!client_is_expired(client))
29 client_schedule_expire();
31 if (client->source_id != 0) {
32 g_source_remove(client->source_id);
33 client->source_id = 0;
36 if (client->channel != NULL) {
37 g_io_channel_unref(client->channel);
38 client->channel = NULL;
42 static void
43 client_check_expired_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
45 struct client *client = data;
47 if (client_is_expired(client)) {
48 g_debug("[%u] expired", client->num);
49 client_close(client);
50 } else if (!client->idle_waiting && /* idle clients
51 never expire */
52 (int)g_timer_elapsed(client->last_activity, NULL) >
53 client_timeout) {
54 g_debug("[%u] timeout", client->num);
55 client_close(client);
59 static void
60 client_manager_expire(void)
62 client_list_foreach(client_check_expired_callback, NULL);
65 /**
66 * An idle event which calls client_manager_expire().
68 static gboolean
69 client_manager_expire_event(G_GNUC_UNUSED gpointer data)
71 expire_source_id = 0;
72 client_manager_expire();
73 return false;
76 void
77 client_schedule_expire(void)
79 if (expire_source_id == 0)
80 /* delayed deletion */
81 expire_source_id = g_idle_add(client_manager_expire_event,
82 NULL);
85 void
86 client_deinit_expire(void)
88 if (expire_source_id != 0)
89 g_source_remove(expire_source_id);