aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientList.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-16 22:55:33 +0100
committerMax Kellermann <max@duempel.org>2013-01-16 23:00:13 +0100
commit601495fa0f3d3793d4ee761d1b86f8435417266c (patch)
tree1284f0f0ac48668391063e5f45eba08d0b59c2ed /src/ClientList.cxx
parent1998633739b027b97ff89f92825512db91dca8f9 (diff)
downloadmpd-601495fa0f3d3793d4ee761d1b86f8435417266c.tar.gz
mpd-601495fa0f3d3793d4ee761d1b86f8435417266c.tar.xz
mpd-601495fa0f3d3793d4ee761d1b86f8435417266c.zip
ClientList: convert to a class
Diffstat (limited to 'src/ClientList.cxx')
-rw-r--r--src/ClientList.cxx45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/ClientList.cxx b/src/ClientList.cxx
index bfa04fea1..37e6f1289 100644
--- a/src/ClientList.cxx
+++ b/src/ClientList.cxx
@@ -21,51 +21,36 @@
#include "ClientList.hxx"
#include "ClientInternal.hxx"
-#include <list>
#include <algorithm>
#include <assert.h>
-static std::list<Client *> clients;
-static unsigned num_clients;
-
-bool
-client_list_is_full(void)
-{
- return num_clients >= client_max_connections;
-}
-
void
-client_list_add(Client *client)
+ClientList::Remove(Client &client)
{
- clients.push_front(client);
- ++num_clients;
-}
+ assert(size > 0);
+ assert(!list.empty());
-void
-client_list_foreach(void (*callback)(Client *client, void *ctx), void *ctx)
-{
- for (Client *client : clients)
- callback(client, ctx);
+ auto i = std::find(list.begin(), list.end(), &client);
+ assert(i != list.end());
+ list.erase(i);
+ --size;
}
void
-client_list_remove(Client *client)
+ClientList::CloseAll()
{
- assert(num_clients > 0);
- assert(!clients.empty());
+ while (!list.empty())
+ list.front()->Close();
- auto i = std::find(clients.begin(), clients.end(), client);
- assert(i != clients.end());
- clients.erase(i);
- --num_clients;
+ assert(size == 0);
}
void
-client_list_close_all()
+ClientList::IdleAdd(unsigned flags)
{
- while (!clients.empty())
- clients.front()->Close();
+ assert(flags != 0);
- assert(num_clients == 0);
+ for (const auto &client : list)
+ client->IdleAdd(flags);
}