aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Client.cxx5
-rw-r--r--src/Client.hxx3
-rw-r--r--src/ClientEvent.cxx20
-rw-r--r--src/ClientExpire.cxx22
-rw-r--r--src/ClientGlobal.cxx2
-rw-r--r--src/ClientIdle.cxx2
-rw-r--r--src/ClientInternal.hxx15
-rw-r--r--src/ClientNew.cxx11
-rw-r--r--src/ClientProcess.cxx6
-rw-r--r--src/ClientRead.cxx2
-rw-r--r--src/ClientWrite.cxx18
11 files changed, 50 insertions, 56 deletions
diff --git a/src/Client.cxx b/src/Client.cxx
index efb4125ac..be121dfe8 100644
--- a/src/Client.cxx
+++ b/src/Client.cxx
@@ -20,11 +20,6 @@
#include "config.h"
#include "ClientInternal.hxx"
-bool client_is_expired(const Client *client)
-{
- return client->channel == NULL;
-}
-
int client_get_uid(const Client *client)
{
return client->uid;
diff --git a/src/Client.hxx b/src/Client.hxx
index 37bf69409..3ce323d80 100644
--- a/src/Client.hxx
+++ b/src/Client.hxx
@@ -37,9 +37,6 @@ void
client_new(Partition &partition,
int fd, const struct sockaddr *sa, size_t sa_length, int uid);
-gcc_pure
-bool client_is_expired(const Client *client);
-
/**
* returns the uid of the client process, or a negative value if the
* uid is unknown
diff --git a/src/ClientEvent.cxx b/src/ClientEvent.cxx
index fe967f93b..1e06ad48a 100644
--- a/src/ClientEvent.cxx
+++ b/src/ClientEvent.cxx
@@ -30,17 +30,17 @@ client_out_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
{
Client *client = (Client *)data;
- assert(!client_is_expired(client));
+ assert(!client->IsExpired());
if (condition != G_IO_OUT) {
- client_set_expired(client);
+ client->SetExpired();
return false;
}
client_write_deferred(client);
- if (client_is_expired(client)) {
- client_close(client);
+ if (client->IsExpired()) {
+ client->Close();
return false;
}
@@ -66,10 +66,10 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
Client *client = (Client *)data;
enum command_return ret;
- assert(!client_is_expired(client));
+ assert(!client->IsExpired());
if (condition != G_IO_IN) {
- client_set_expired(client);
+ client->SetExpired();
return false;
}
@@ -83,17 +83,17 @@ client_in_event(G_GNUC_UNUSED GIOChannel *source, GIOCondition condition,
break;
case COMMAND_RETURN_KILL:
- client_close(client);
+ client->Close();
main_loop->Break();
return false;
case COMMAND_RETURN_CLOSE:
- client_close(client);
+ client->Close();
return false;
}
- if (client_is_expired(client)) {
- client_close(client);
+ if (client->IsExpired()) {
+ client->Close();
return false;
}
diff --git a/src/ClientExpire.cxx b/src/ClientExpire.cxx
index 1e271c052..f599e472d 100644
--- a/src/ClientExpire.cxx
+++ b/src/ClientExpire.cxx
@@ -24,34 +24,34 @@
static guint expire_source_id;
void
-client_set_expired(Client *client)
+Client::SetExpired()
{
- if (!client_is_expired(client))
+ if (!IsExpired())
client_schedule_expire();
- if (client->source_id != 0) {
- g_source_remove(client->source_id);
- client->source_id = 0;
+ if (source_id != 0) {
+ g_source_remove(source_id);
+ source_id = 0;
}
- if (client->channel != NULL) {
- g_io_channel_unref(client->channel);
- client->channel = NULL;
+ if (channel != NULL) {
+ g_io_channel_unref(channel);
+ channel = nullptr;
}
}
static void
client_check_expired_callback(Client *client, G_GNUC_UNUSED gpointer user_data)
{
- if (client_is_expired(client)) {
+ if (client->IsExpired()) {
g_debug("[%u] expired", client->num);
- client_close(client);
+ client->Close();
} else if (!client->idle_waiting && /* idle clients
never expire */
(int)g_timer_elapsed(client->last_activity, NULL) >
client_timeout) {
g_debug("[%u] timeout", client->num);
- client_close(client);
+ client->Close();
}
}
diff --git a/src/ClientGlobal.cxx b/src/ClientGlobal.cxx
index c3940f0a8..1aa82b435 100644
--- a/src/ClientGlobal.cxx
+++ b/src/ClientGlobal.cxx
@@ -58,7 +58,7 @@ static void client_close_all(void)
while (!client_list_is_empty()) {
Client *client = client_list_get_first();
- client_close(client);
+ client->Close();
}
assert(client_list_is_empty());
diff --git a/src/ClientIdle.cxx b/src/ClientIdle.cxx
index c68bee839..98778f52c 100644
--- a/src/ClientIdle.cxx
+++ b/src/ClientIdle.cxx
@@ -55,7 +55,7 @@ client_idle_notify(Client *client)
void
client_idle_add(Client *client, unsigned flags)
{
- if (client_is_expired(client))
+ if (client->IsExpired())
return;
client->idle_flags |= flags;
diff --git a/src/ClientInternal.hxx b/src/ClientInternal.hxx
index 788d90d7b..7d2edf046 100644
--- a/src/ClientInternal.hxx
+++ b/src/ClientInternal.hxx
@@ -112,6 +112,15 @@ public:
bool IsSubscribed(const char *channel_name) const {
return subscriptions.find(channel_name) != subscriptions.end();
}
+
+
+ gcc_pure
+ bool IsExpired() const {
+ return channel == nullptr;
+ }
+
+ void Close();
+ void SetExpired();
};
extern unsigned int client_max_connections;
@@ -119,12 +128,6 @@ extern int client_timeout;
extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;
-void
-client_close(Client *client);
-
-void
-client_set_expired(Client *client);
-
/**
* Schedule an "expired" check for all clients: permanently delete
* clients which have been set "expired" with client_set_expired().
diff --git a/src/ClientNew.cxx b/src/ClientNew.cxx
index 77eb33c8e..4a22ca368 100644
--- a/src/ClientNew.cxx
+++ b/src/ClientNew.cxx
@@ -149,13 +149,12 @@ client_new(Partition &partition,
}
void
-client_close(Client *client)
+Client::Close()
{
- client_list_remove(client);
+ client_list_remove(this);
- client_set_expired(client);
+ SetExpired();
- g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE,
- "[%u] closed", client->num);
- delete client;
+ g_log(G_LOG_DOMAIN, LOG_LEVEL_SECURE, "[%u] closed", num);
+ delete this;
}
diff --git a/src/ClientProcess.cxx b/src/ClientProcess.cxx
index 69b23e868..e1e8395e7 100644
--- a/src/ClientProcess.cxx
+++ b/src/ClientProcess.cxx
@@ -42,7 +42,7 @@ client_process_command_list(Client *client, bool list_ok,
cmd);
ret = command_process(client, num++, cmd);
g_debug("command_process_list: command returned %i", ret);
- if (ret != COMMAND_RETURN_OK || client_is_expired(client))
+ if (ret != COMMAND_RETURN_OK || client->IsExpired())
break;
else if (list_ok)
client_puts(client, "list_OK\n");
@@ -91,7 +91,7 @@ client_process_line(Client *client, char *line)
"list returned %i", client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
- client_is_expired(client))
+ client->IsExpired())
return COMMAND_RETURN_CLOSE;
if (ret == COMMAND_RETURN_OK)
@@ -125,7 +125,7 @@ client_process_line(Client *client, char *line)
client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
- client_is_expired(client))
+ client->IsExpired())
return COMMAND_RETURN_CLOSE;
if (ret == COMMAND_RETURN_OK)
diff --git a/src/ClientRead.cxx b/src/ClientRead.cxx
index 7e85c3a99..e58c73dea 100644
--- a/src/ClientRead.cxx
+++ b/src/ClientRead.cxx
@@ -58,7 +58,7 @@ client_input_received(Client *client, size_t bytesRead)
if (ret == COMMAND_RETURN_KILL ||
ret == COMMAND_RETURN_CLOSE)
return ret;
- if (client_is_expired(client))
+ if (client->IsExpired())
return COMMAND_RETURN_CLOSE;
}
diff --git a/src/ClientWrite.cxx b/src/ClientWrite.cxx
index 825029fb9..1fe0e7bbd 100644
--- a/src/ClientWrite.cxx
+++ b/src/ClientWrite.cxx
@@ -49,13 +49,13 @@ client_write_deferred_buffer(Client *client,
case G_IO_STATUS_EOF:
/* client has disconnected */
- client_set_expired(client);
+ client->SetExpired();
return 0;
case G_IO_STATUS_ERROR:
/* I/O error */
- client_set_expired(client);
+ client->SetExpired();
g_warning("failed to flush buffer for %i: %s",
client->num, error->message);
g_error_free(error);
@@ -126,7 +126,7 @@ client_defer_output(Client *client, const void *data, size_t length)
(unsigned long)client->deferred_bytes,
(unsigned long)client_max_output_buffer_size);
/* cause client to close */
- client_set_expired(client);
+ client->SetExpired();
return;
}
@@ -160,13 +160,13 @@ client_write_direct(Client *client, const char *data, size_t length)
case G_IO_STATUS_EOF:
/* client has disconnected */
- client_set_expired(client);
+ client->SetExpired();
return;
case G_IO_STATUS_ERROR:
/* I/O error */
- client_set_expired(client);
+ client->SetExpired();
g_warning("failed to write to %i: %s",
client->num, error->message);
g_error_free(error);
@@ -184,14 +184,14 @@ client_write_direct(Client *client, const char *data, size_t length)
void
client_write_output(Client *client)
{
- if (client_is_expired(client) || !client->send_buf_used)
+ if (client->IsExpired() || !client->send_buf_used)
return;
if (!g_queue_is_empty(client->deferred_send)) {
client_defer_output(client, client->send_buf,
client->send_buf_used);
- if (client_is_expired(client))
+ if (client->IsExpired())
return;
/* try to flush the deferred buffers now; the current
@@ -216,10 +216,10 @@ static void
client_write(Client *client, const char *buffer, size_t buflen)
{
/* if the client is going to be closed, do nothing */
- if (client_is_expired(client))
+ if (client->IsExpired())
return;
- while (buflen > 0 && !client_is_expired(client)) {
+ while (buflen > 0 && !client->IsExpired()) {
size_t copylen;
assert(client->send_buf_used < sizeof(client->send_buf));