Commit 58d7804d authored by Max Kellermann's avatar Max Kellermann

Client: eliminate SetExpired(), call Close() directly

parent ea5e6d8f
......@@ -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.
......
......@@ -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();
}
......@@ -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();
}
......@@ -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();
......
......@@ -81,7 +81,7 @@ Client::Close() noexcept
{
partition->instance.client_list->Remove(*this);
SetExpired();
FullyBufferedSocket::Close();
FormatInfo(client_domain, "[%u] closed", num);
delete this;
......
......@@ -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);
......
......@@ -66,10 +66,5 @@ Client::OnSocketInput(void *data, size_t length) noexcept
return InputResult::CLOSED;
}
if (IsExpired()) {
Close();
return InputResult::CLOSED;
}
return InputResult::AGAIN;
}
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment