aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-07 16:30:40 +0100
committerMax Kellermann <max@duempel.org>2009-01-07 16:30:40 +0100
commitfa503e31e754b58c8edf9dad26246307ae8127a4 (patch)
tree92027ecf340be9f2511f9880051d172abc96f97a /src/client.c
parent91dfeff4b978b541a726a6215fe8397f9740b8d7 (diff)
downloadmpd-fa503e31e754b58c8edf9dad26246307ae8127a4.tar.gz
mpd-fa503e31e754b58c8edf9dad26246307ae8127a4.tar.xz
mpd-fa503e31e754b58c8edf9dad26246307ae8127a4.zip
client: use GList instead of dlist.h
Get rid of the non-portable Linux list library, part I.
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/client.c b/src/client.c
index 48a035e11..852e838b6 100644
--- a/src/client.c
+++ b/src/client.c
@@ -22,7 +22,6 @@
#include "listen.h"
#include "permission.h"
#include "event_pipe.h"
-#include "dlist.h"
#include "idle.h"
#include "main.h"
@@ -73,8 +72,6 @@ struct deferred_buffer {
};
struct client {
- struct list_head siblings;
-
char buffer[4096];
size_t bufferLength;
size_t bufferPos;
@@ -110,7 +107,7 @@ struct client {
unsigned idle_subscriptions;
};
-static LIST_HEAD(clients);
+static GList *clients;
static unsigned num_clients;
static guint expire_source_id;
@@ -229,8 +226,9 @@ deferred_buffer_free(gpointer data, G_GNUC_UNUSED gpointer user_data)
static void client_close(struct client *client)
{
assert(num_clients > 0);
- assert(!list_empty(&clients));
- list_del(&client->siblings);
+ assert(clients != NULL);
+
+ clients = g_list_remove(clients, client);
--num_clients;
client_set_expired(client);
@@ -301,8 +299,9 @@ void client_new(int fd, const struct sockaddr *addr, int uid)
}
client = g_new0(struct client, 1);
- list_add(&client->siblings, &clients);
+ clients = g_list_prepend(clients, client);
++num_clients;
+
client_init(client, fd);
client->uid = uid;
g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
@@ -608,11 +607,13 @@ void client_manager_init(void)
static void client_close_all(void)
{
- struct client *client, *n;
+ while (clients != NULL) {
+ struct client *client = clients->data;
- list_for_each_entry_safe(client, n, &clients, siblings)
client_close(client);
- num_clients = 0;
+ }
+
+ assert(num_clients == 0);
}
void client_manager_deinit(void)
@@ -623,24 +624,28 @@ void client_manager_deinit(void)
}
static void
-client_manager_expire(void)
+client_check_expired_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
{
- struct client *client, *n;
-
- list_for_each_entry_safe(client, n, &clients, siblings) {
- if (client_is_expired(client)) {
- g_debug("client %i: expired", client->num);
- client_close(client);
- } else if (!client->idle_waiting && /* idle clients
- never expire */
- time(NULL) - client->lastTime >
- client_timeout) {
- g_debug("client %i: timeout", client->num);
- client_close(client);
- }
+ struct client *client = data;
+
+ if (client_is_expired(client)) {
+ g_debug("client %i: expired", client->num);
+ client_close(client);
+ } else if (!client->idle_waiting && /* idle clients
+ never expire */
+ time(NULL) - client->lastTime >
+ client_timeout) {
+ g_debug("client %i: timeout", client->num);
+ client_close(client);
}
}
+static void
+client_manager_expire(void)
+{
+ g_list_foreach(clients, client_check_expired_callback, NULL);
+}
+
static void client_write_deferred(struct client *client)
{
ssize_t ret = 0;
@@ -847,25 +852,30 @@ client_idle_notify(struct client *client)
client->lastTime = time(NULL);
}
-void client_manager_idle_add(unsigned flags)
+static void
+client_idle_callback(gpointer data, gpointer user_data)
{
- struct client *client;
-
- assert(flags != 0);
+ struct client *client = data;
+ unsigned flags = GPOINTER_TO_UINT(user_data);
- list_for_each_entry(client, &clients, siblings) {
- if (client_is_expired(client))
- continue;
+ if (client_is_expired(client))
+ return;
- client->idle_flags |= flags;
- if (client->idle_waiting
- && (client->idle_flags & client->idle_subscriptions)) {
- client_idle_notify(client);
- client_write_output(client);
- }
+ client->idle_flags |= flags;
+ if (client->idle_waiting
+ && (client->idle_flags & client->idle_subscriptions)) {
+ client_idle_notify(client);
+ client_write_output(client);
}
}
+void client_manager_idle_add(unsigned flags)
+{
+ assert(flags != 0);
+
+ g_list_foreach(clients, client_idle_callback, GUINT_TO_POINTER(flags));
+}
+
bool client_idle_wait(struct client *client, unsigned flags)
{
assert(!client->idle_waiting);