From 58d7804d666896600d0af1de067f21c14414bf46 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Apr 2019 10:37:38 +0200 Subject: [PATCH] Client: eliminate SetExpired(), call Close() directly --- src/client/Client.hxx | 12 +----------- src/client/Event.cxx | 4 ++-- src/client/Expire.cxx | 17 +++-------------- src/client/Idle.cxx | 3 --- src/client/New.cxx | 2 +- src/client/Process.cxx | 19 +++++++++---------- src/client/Read.cxx | 5 ----- src/client/Write.cxx | 7 ------- 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 @@ -21,23 +21,12 @@ #include "Domain.hxx" #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 @@ -21,13 +21,6 @@ #include -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 {