aboutsummaryrefslogtreecommitdiffstats
path: root/src/ClientNew.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ClientNew.cxx (renamed from src/client_new.c)103
1 files changed, 34 insertions, 69 deletions
diff --git a/src/client_new.c b/src/ClientNew.cxx
index cf28c43c5..42cc3470d 100644
--- a/src/client_new.c
+++ b/src/ClientNew.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,11 +18,14 @@
*/
#include "config.h"
-#include "client_internal.h"
+#include "ClientInternal.hxx"
+#include "ClientList.hxx"
+#include "Partition.hxx"
#include "fd_util.h"
-#include "fifo_buffer.h"
+extern "C" {
#include "resolver.h"
-#include "permission.h"
+}
+#include "Permission.hxx"
#include "glib_socket.h"
#include <assert.h>
@@ -43,15 +46,32 @@
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
+Client::Client(EventLoop &_loop, Partition &_partition,
+ int _fd, int _uid, int _num)
+ :BufferedSocket(_fd, _loop, 16384, client_max_output_buffer_size),
+ partition(_partition),
+ playlist(partition.playlist), player_control(&partition.pc),
+ permission(getDefaultPermissions()),
+ uid(_uid),
+ last_activity(g_timer_new()),
+ num(_num),
+ idle_waiting(false), idle_flags(0),
+ num_subscriptions(0)
+{
+}
+
+Client::~Client()
+{
+ g_timer_destroy(last_activity);
+}
+
void
-client_new(struct player_control *player_control,
+client_new(EventLoop &loop, Partition &partition,
int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{
static unsigned int next_client_num;
- struct client *client;
char *remote;
- assert(player_control != NULL);
assert(fd >= 0);
#ifdef HAVE_LIBWRAP
@@ -85,43 +105,8 @@ client_new(struct player_control *player_control,
return;
}
- client = g_new0(struct client, 1);
- client->player_control = player_control;
-
- client->channel = g_io_channel_new_socket(fd);
- /* GLib is responsible for closing the file descriptor */
- g_io_channel_set_close_on_unref(client->channel, true);
- /* NULL encoding means the stream is binary safe; the MPD
- protocol is UTF-8 only, but we are doing this call anyway
- to prevent GLib from messing around with the stream */
- g_io_channel_set_encoding(client->channel, NULL, NULL);
- /* we prefer to do buffering */
- g_io_channel_set_buffered(client->channel, false);
-
- client->source_id = g_io_add_watch(client->channel,
- G_IO_IN|G_IO_ERR|G_IO_HUP,
- client_in_event, client);
-
- client->input = fifo_buffer_new(4096);
-
- client->permission = getDefaultPermissions();
- client->uid = uid;
-
- client->last_activity = g_timer_new();
-
- client->cmd_list = NULL;
- client->cmd_list_OK = -1;
- client->cmd_list_size = 0;
-
- client->deferred_send = g_queue_new();
- client->deferred_bytes = 0;
- client->num = next_client_num++;
-
- client->send_buf_used = 0;
-
- client->subscriptions = NULL;
- client->messages = NULL;
- client->num_messages = 0;
+ Client *client = new Client(loop, partition, fd, uid,
+ next_client_num++);
(void)send(fd, GREETING, sizeof(GREETING) - 1, 0);
@@ -133,33 +118,13 @@ client_new(struct player_control *player_control,
g_free(remote);
}
-static void
-deferred_buffer_free(gpointer data, G_GNUC_UNUSED gpointer user_data)
-{
- struct deferred_buffer *buffer = data;
- g_free(buffer);
-}
-
void
-client_close(struct client *client)
+Client::Close()
{
- client_list_remove(client);
+ client_list_remove(this);
- client_set_expired(client);
+ SetExpired();
- g_timer_destroy(client->last_activity);
-
- if (client->cmd_list) {
- free_cmd_list(client->cmd_list);
- client->cmd_list = NULL;
- }
-
- g_queue_foreach(client->deferred_send, deferred_buffer_free, NULL);
- g_queue_free(client->deferred_send);
-
- fifo_buffer_free(client->input);
-
- g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
- "[%u] closed", client->num);
- g_free(client);
+ g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, "[%u] closed", num);
+ delete this;
}