summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-04-04 10:37:38 +0200
committerMax Kellermann <max@musicpd.org>2019-04-04 10:37:38 +0200
commit58d7804d666896600d0af1de067f21c14414bf46 (patch)
treeaff19695a6f9e8a7de94202acaa837d435cd9226 /src/client
parentea5e6d8f33d548d7d9d9b9bb49be33df79e6cac1 (diff)
Client: eliminate SetExpired(), call Close() directly
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.hxx12
-rw-r--r--src/client/Event.cxx4
-rw-r--r--src/client/Expire.cxx17
-rw-r--r--src/client/Idle.cxx3
-rw-r--r--src/client/New.cxx2
-rw-r--r--src/client/Process.cxx19
-rw-r--r--src/client/Read.cxx5
-rw-r--r--src/client/Write.cxx7
8 files changed, 16 insertions, 53 deletions
diff --git a/src/client/Client.hxx b/src/client/Client.hxx
index 8f55c43c4..753f0a04e 100644
--- a/src/client/Client.hxx
+++ b/src/client/Client.hxx
@@ -112,19 +112,9 @@ public:
using FullyBufferedSocket::GetEventLoop;
- bool IsConnected() const noexcept {
- return FullyBufferedSocket::IsDefined();
- }
-
- gcc_pure
- bool IsExpired() const noexcept {
- return !FullyBufferedSocket::IsDefined();
- }
-
void Close() noexcept;
- void SetExpired() noexcept;
- bool Write(const void *data, size_t length) noexcept;
+ using FullyBufferedSocket::Write;
/**
* Write a null-terminated string.
diff --git a/src/client/Event.cxx b/src/client/Event.cxx
index c2220e67e..54d080e70 100644
--- a/src/client/Event.cxx
+++ b/src/client/Event.cxx
@@ -25,11 +25,11 @@ Client::OnSocketError(std::exception_ptr ep) noexcept
{
FormatError(ep, "error on client %d", num);
- SetExpired();
+ Close();
}
void
Client::OnSocketClosed() noexcept
{
- SetExpired();
+ Close();
}
diff --git a/src/client/Expire.cxx b/src/client/Expire.cxx
index 3f6e57f6e..d6129bf5f 100644
--- a/src/client/Expire.cxx
+++ b/src/client/Expire.cxx
@@ -22,22 +22,11 @@
#include "Log.hxx"
void
-Client::SetExpired() noexcept
-{
- if (IsExpired())
- return;
-
- FullyBufferedSocket::Close();
- timeout_event.Schedule(std::chrono::steady_clock::duration::zero());
-}
-
-void
Client::OnTimeout() noexcept
{
- if (!IsExpired()) {
- assert(!idle_waiting);
- FormatDebug(client_domain, "[%u] timeout", num);
- }
+ assert(!idle_waiting);
+
+ FormatDebug(client_domain, "[%u] timeout", num);
Close();
}
diff --git a/src/client/Idle.cxx b/src/client/Idle.cxx
index abf3a38a6..555ff084e 100644
--- a/src/client/Idle.cxx
+++ b/src/client/Idle.cxx
@@ -54,9 +54,6 @@ Client::IdleNotify() noexcept
void
Client::IdleAdd(unsigned flags) noexcept
{
- if (IsExpired())
- return;
-
idle_flags |= flags;
if (idle_waiting && (idle_flags & idle_subscriptions))
IdleNotify();
diff --git a/src/client/New.cxx b/src/client/New.cxx
index d04d8133d..9ef1c5233 100644
--- a/src/client/New.cxx
+++ b/src/client/New.cxx
@@ -81,7 +81,7 @@ Client::Close() noexcept
{
partition->instance.client_list->Remove(*this);
- SetExpired();
+ FullyBufferedSocket::Close();
FormatInfo(client_domain, "[%u] closed", num);
delete this;
diff --git a/src/client/Process.cxx b/src/client/Process.cxx
index 7cd25348e..e138d2fa3 100644
--- a/src/client/Process.cxx
+++ b/src/client/Process.cxx
@@ -42,9 +42,7 @@ Client::ProcessCommandList(bool list_ok,
FormatDebug(client_domain, "process command \"%s\"", cmd);
auto ret = command_process(*this, n++, cmd);
FormatDebug(client_domain, "command returned %i", int(ret));
- if (IsExpired())
- return CommandResult::CLOSE;
- else if (ret != CommandResult::OK)
+ if (ret != CommandResult::OK)
return ret;
else if (list_ok)
Write("list_OK\n");
@@ -89,9 +87,11 @@ Client::ProcessLine(char *line) noexcept
if (cmd_list.IsActive()) {
if (StringIsEqual(line, CLIENT_LIST_MODE_END)) {
+ const unsigned id = num;
+
FormatDebug(client_domain,
"[%u] process command list",
- num);
+ id);
const bool ok_mode = cmd_list.IsOKMode();
auto list = cmd_list.Commit();
@@ -101,7 +101,7 @@ Client::ProcessLine(char *line) noexcept
std::move(list));
FormatDebug(client_domain,
"[%u] process command "
- "list returned %i", num, int(ret));
+ "list returned %i", id, int(ret));
if (ret == CommandResult::OK)
command_success(*this);
@@ -127,16 +127,15 @@ Client::ProcessLine(char *line) noexcept
cmd_list.Begin(true);
return CommandResult::OK;
} else {
+ const unsigned id = num;
+
FormatDebug(client_domain,
"[%u] process command \"%s\"",
- num, line);
+ id, line);
auto ret = command_process(*this, 0, line);
FormatDebug(client_domain,
"[%u] command returned %i",
- num, int(ret));
-
- if (IsExpired())
- return CommandResult::CLOSE;
+ id, int(ret));
if (ret == CommandResult::OK)
command_success(*this);
diff --git a/src/client/Read.cxx b/src/client/Read.cxx
index 5ca6770bb..d7ada1bc1 100644
--- a/src/client/Read.cxx
+++ b/src/client/Read.cxx
@@ -66,10 +66,5 @@ Client::OnSocketInput(void *data, size_t length) noexcept
return InputResult::CLOSED;
}
- if (IsExpired()) {
- Close();
- return InputResult::CLOSED;
- }
-
return InputResult::AGAIN;
}
diff --git a/src/client/Write.cxx b/src/client/Write.cxx
index 32ff0a240..08107c2ea 100644
--- a/src/client/Write.cxx
+++ b/src/client/Write.cxx
@@ -22,13 +22,6 @@
#include <string.h>
bool
-Client::Write(const void *data, size_t length) noexcept
-{
- /* if the client is going to be closed, do nothing */
- return !IsExpired() && FullyBufferedSocket::Write(data, length);
-}
-
-bool
Client::Write(const char *data) noexcept
{
return Write(data, strlen(data));