aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientSubscribe.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-19 18:48:38 +0200
committerMax Kellermann <max@duempel.org>2013-10-19 18:48:38 +0200
commitff626ac76357940b2f0ac5cb243a68ac13df0f8a (patch)
tree493888a28950f75f5e254c0ded9dc9703ee83dc3 /src/ClientSubscribe.cxx
parent59f8144c50765189594d5932fc25869f9ea6e265 (diff)
downloadmpd-ff626ac76357940b2f0ac5cb243a68ac13df0f8a.tar.gz
mpd-ff626ac76357940b2f0ac5cb243a68ac13df0f8a.tar.xz
mpd-ff626ac76357940b2f0ac5cb243a68ac13df0f8a.zip
*: use references instead of pointers
Diffstat (limited to 'src/ClientSubscribe.cxx')
-rw-r--r--src/ClientSubscribe.cxx45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/ClientSubscribe.cxx b/src/ClientSubscribe.cxx
index 6bdb3e021..4d5511b4f 100644
--- a/src/ClientSubscribe.cxx
+++ b/src/ClientSubscribe.cxx
@@ -26,22 +26,21 @@
#include <string.h>
enum client_subscribe_result
-client_subscribe(Client *client, const char *channel)
+client_subscribe(Client &client, const char *channel)
{
- assert(client != nullptr);
assert(channel != nullptr);
if (!client_message_valid_channel_name(channel))
return CLIENT_SUBSCRIBE_INVALID;
- if (client->num_subscriptions >= CLIENT_MAX_SUBSCRIPTIONS)
+ if (client.num_subscriptions >= CLIENT_MAX_SUBSCRIPTIONS)
return CLIENT_SUBSCRIBE_FULL;
- auto r = client->subscriptions.insert(channel);
+ auto r = client.subscriptions.insert(channel);
if (!r.second)
return CLIENT_SUBSCRIBE_ALREADY;
- ++client->num_subscriptions;
+ ++client.num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
@@ -49,44 +48,42 @@ client_subscribe(Client *client, const char *channel)
}
bool
-client_unsubscribe(Client *client, const char *channel)
+client_unsubscribe(Client &client, const char *channel)
{
- const auto i = client->subscriptions.find(channel);
- if (i == client->subscriptions.end())
+ const auto i = client.subscriptions.find(channel);
+ if (i == client.subscriptions.end())
return false;
- assert(client->num_subscriptions > 0);
+ assert(client.num_subscriptions > 0);
- client->subscriptions.erase(i);
- --client->num_subscriptions;
+ client.subscriptions.erase(i);
+ --client.num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
- assert((client->num_subscriptions == 0) ==
- client->subscriptions.empty());
+ assert((client.num_subscriptions == 0) ==
+ client.subscriptions.empty());
return true;
}
void
-client_unsubscribe_all(Client *client)
+client_unsubscribe_all(Client &client)
{
- client->subscriptions.clear();
- client->num_subscriptions = 0;
+ client.subscriptions.clear();
+ client.num_subscriptions = 0;
}
bool
-client_push_message(Client *client, const ClientMessage &msg)
+client_push_message(Client &client, const ClientMessage &msg)
{
- assert(client != nullptr);
-
- if (client->messages.size() >= CLIENT_MAX_MESSAGES ||
- !client->IsSubscribed(msg.GetChannel()))
+ if (client.messages.size() >= CLIENT_MAX_MESSAGES ||
+ !client.IsSubscribed(msg.GetChannel()))
return false;
- if (client->messages.empty())
- client->IdleAdd(IDLE_MESSAGE);
+ if (client.messages.empty())
+ client.IdleAdd(IDLE_MESSAGE);
- client->messages.push_back(msg);
+ client.messages.push_back(msg);
return true;
}