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.
21 #include "client_internal.h"
23 static guint expire_source_id
;
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
;
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
);
50 } else if (!client
->idle_waiting
&& /* idle clients
52 (int)g_timer_elapsed(client
->last_activity
, NULL
) >
54 g_debug("[%u] timeout", client
->num
);
60 client_manager_expire(void)
62 client_list_foreach(client_check_expired_callback
, NULL
);
66 * An idle event which calls client_manager_expire().
69 client_manager_expire_event(G_GNUC_UNUSED gpointer data
)
72 client_manager_expire();
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
,
86 client_deinit_expire(void)
88 if (expire_source_id
!= 0)
89 g_source_remove(expire_source_id
);