aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ClientInternal.hxx11
-rw-r--r--src/ClientNew.cxx3
-rw-r--r--src/ClientSubscribe.cxx20
-rw-r--r--src/ClientSubscribe.hxx4
-rw-r--r--src/MessageCommands.cxx13
5 files changed, 10 insertions, 41 deletions
diff --git a/src/ClientInternal.hxx b/src/ClientInternal.hxx
index be423bb24..5ad24068c 100644
--- a/src/ClientInternal.hxx
+++ b/src/ClientInternal.hxx
@@ -26,6 +26,7 @@
#include <set>
#include <string>
+#include <deque>
#include <glib.h>
@@ -94,15 +95,9 @@ public:
unsigned num_subscriptions;
/**
- * A list of messages this client has received in reverse
- * order (latest first).
+ * A list of messages this client has received.
*/
- GSList *messages;
-
- /**
- * The number of messages in #messages.
- */
- unsigned num_messages;
+ std::deque<ClientMessage> messages;
gcc_pure
bool IsSubscribed(const char *channel_name) const {
diff --git a/src/ClientNew.cxx b/src/ClientNew.cxx
index 7bb0c1b10..eab78c690 100644
--- a/src/ClientNew.cxx
+++ b/src/ClientNew.cxx
@@ -120,9 +120,6 @@ client_new(struct player_control *player_control,
client->send_buf_used = 0;
- client->messages = NULL;
- client->num_messages = 0;
-
(void)send(fd, GREETING, sizeof(GREETING) - 1, 0);
client_list_add(client);
diff --git a/src/ClientSubscribe.cxx b/src/ClientSubscribe.cxx
index 4f1471474..a1ad6e68e 100644
--- a/src/ClientSubscribe.cxx
+++ b/src/ClientSubscribe.cxx
@@ -83,27 +83,13 @@ client_push_message(Client *client, const ClientMessage &msg)
{
assert(client != NULL);
- if (client->num_messages >= CLIENT_MAX_MESSAGES ||
+ if (client->messages.size() >= CLIENT_MAX_MESSAGES ||
!client->IsSubscribed(msg.GetChannel()))
return false;
- if (client->messages == NULL)
+ if (client->messages.empty())
client_idle_add(client, IDLE_MESSAGE);
- client->messages = g_slist_prepend(client->messages,
- new ClientMessage(msg));
- ++client->num_messages;
-
+ client->messages.push_back(msg);
return true;
}
-
-GSList *
-client_read_messages(Client *client)
-{
- GSList *messages = g_slist_reverse(client->messages);
-
- client->messages = NULL;
- client->num_messages = 0;
-
- return messages;
-}
diff --git a/src/ClientSubscribe.hxx b/src/ClientSubscribe.hxx
index 42c8ed8fd..e9d3b8a68 100644
--- a/src/ClientSubscribe.hxx
+++ b/src/ClientSubscribe.hxx
@@ -52,8 +52,4 @@ client_unsubscribe_all(Client *client);
bool
client_push_message(Client *client, const ClientMessage &msg);
-gcc_malloc
-GSList *
-client_read_messages(Client *client);
-
#endif
diff --git a/src/MessageCommands.cxx b/src/MessageCommands.cxx
index 738c2eab9..c5f4d79b0 100644
--- a/src/MessageCommands.cxx
+++ b/src/MessageCommands.cxx
@@ -109,19 +109,14 @@ handle_read_messages(Client *client,
{
assert(argc == 1);
- GSList *messages = client_read_messages(client);
-
- for (GSList *i = messages; i != NULL; i = g_slist_next(i)) {
- ClientMessage *msg = (ClientMessage *)i->data;
+ while (!client->messages.empty()) {
+ const ClientMessage &msg = client->messages.front();
client_printf(client, "channel: %s\nmessage: %s\n",
- msg->GetChannel(),
- msg->GetMessage());
- delete msg;
+ msg.GetChannel(), msg.GetMessage());
+ client->messages.pop_front();
}
- g_slist_free(messages);
-
return COMMAND_RETURN_OK;
}