Commit fa503e31 authored by Max Kellermann's avatar Max Kellermann

client: use GList instead of dlist.h

Get rid of the non-portable Linux list library, part I.
parent 91dfeff4
......@@ -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,11 +624,10 @@ 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;
struct client *client = data;
list_for_each_entry_safe(client, n, &clients, siblings) {
if (client_is_expired(client)) {
g_debug("client %i: expired", client->num);
client_close(client);
......@@ -638,7 +638,12 @@ client_manager_expire(void)
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)
......@@ -847,15 +852,14 @@ 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;
return;
client->idle_flags |= flags;
if (client->idle_waiting
......@@ -863,7 +867,13 @@ void client_manager_idle_add(unsigned flags)
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment