Client: eliminate SetExpired(), call Close() directly
This commit is contained in:
parent
ea5e6d8f33
commit
58d7804d66
@ -112,19 +112,9 @@ public:
|
|||||||
|
|
||||||
using FullyBufferedSocket::GetEventLoop;
|
using FullyBufferedSocket::GetEventLoop;
|
||||||
|
|
||||||
bool IsConnected() const noexcept {
|
|
||||||
return FullyBufferedSocket::IsDefined();
|
|
||||||
}
|
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
bool IsExpired() const noexcept {
|
|
||||||
return !FullyBufferedSocket::IsDefined();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Close() noexcept;
|
void Close() noexcept;
|
||||||
void SetExpired() noexcept;
|
|
||||||
|
|
||||||
bool Write(const void *data, size_t length) noexcept;
|
using FullyBufferedSocket::Write;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a null-terminated string.
|
* Write a null-terminated string.
|
||||||
|
@ -25,11 +25,11 @@ Client::OnSocketError(std::exception_ptr ep) noexcept
|
|||||||
{
|
{
|
||||||
FormatError(ep, "error on client %d", num);
|
FormatError(ep, "error on client %d", num);
|
||||||
|
|
||||||
SetExpired();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Client::OnSocketClosed() noexcept
|
Client::OnSocketClosed() noexcept
|
||||||
{
|
{
|
||||||
SetExpired();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -21,23 +21,12 @@
|
|||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
void
|
|
||||||
Client::SetExpired() noexcept
|
|
||||||
{
|
|
||||||
if (IsExpired())
|
|
||||||
return;
|
|
||||||
|
|
||||||
FullyBufferedSocket::Close();
|
|
||||||
timeout_event.Schedule(std::chrono::steady_clock::duration::zero());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Client::OnTimeout() noexcept
|
Client::OnTimeout() noexcept
|
||||||
{
|
{
|
||||||
if (!IsExpired()) {
|
assert(!idle_waiting);
|
||||||
assert(!idle_waiting);
|
|
||||||
FormatDebug(client_domain, "[%u] timeout", num);
|
FormatDebug(client_domain, "[%u] timeout", num);
|
||||||
}
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,6 @@ Client::IdleNotify() noexcept
|
|||||||
void
|
void
|
||||||
Client::IdleAdd(unsigned flags) noexcept
|
Client::IdleAdd(unsigned flags) noexcept
|
||||||
{
|
{
|
||||||
if (IsExpired())
|
|
||||||
return;
|
|
||||||
|
|
||||||
idle_flags |= flags;
|
idle_flags |= flags;
|
||||||
if (idle_waiting && (idle_flags & idle_subscriptions))
|
if (idle_waiting && (idle_flags & idle_subscriptions))
|
||||||
IdleNotify();
|
IdleNotify();
|
||||||
|
@ -81,7 +81,7 @@ Client::Close() noexcept
|
|||||||
{
|
{
|
||||||
partition->instance.client_list->Remove(*this);
|
partition->instance.client_list->Remove(*this);
|
||||||
|
|
||||||
SetExpired();
|
FullyBufferedSocket::Close();
|
||||||
|
|
||||||
FormatInfo(client_domain, "[%u] closed", num);
|
FormatInfo(client_domain, "[%u] closed", num);
|
||||||
delete this;
|
delete this;
|
||||||
|
@ -42,9 +42,7 @@ Client::ProcessCommandList(bool list_ok,
|
|||||||
FormatDebug(client_domain, "process command \"%s\"", cmd);
|
FormatDebug(client_domain, "process command \"%s\"", cmd);
|
||||||
auto ret = command_process(*this, n++, cmd);
|
auto ret = command_process(*this, n++, cmd);
|
||||||
FormatDebug(client_domain, "command returned %i", int(ret));
|
FormatDebug(client_domain, "command returned %i", int(ret));
|
||||||
if (IsExpired())
|
if (ret != CommandResult::OK)
|
||||||
return CommandResult::CLOSE;
|
|
||||||
else if (ret != CommandResult::OK)
|
|
||||||
return ret;
|
return ret;
|
||||||
else if (list_ok)
|
else if (list_ok)
|
||||||
Write("list_OK\n");
|
Write("list_OK\n");
|
||||||
@ -89,9 +87,11 @@ Client::ProcessLine(char *line) noexcept
|
|||||||
|
|
||||||
if (cmd_list.IsActive()) {
|
if (cmd_list.IsActive()) {
|
||||||
if (StringIsEqual(line, CLIENT_LIST_MODE_END)) {
|
if (StringIsEqual(line, CLIENT_LIST_MODE_END)) {
|
||||||
|
const unsigned id = num;
|
||||||
|
|
||||||
FormatDebug(client_domain,
|
FormatDebug(client_domain,
|
||||||
"[%u] process command list",
|
"[%u] process command list",
|
||||||
num);
|
id);
|
||||||
|
|
||||||
const bool ok_mode = cmd_list.IsOKMode();
|
const bool ok_mode = cmd_list.IsOKMode();
|
||||||
auto list = cmd_list.Commit();
|
auto list = cmd_list.Commit();
|
||||||
@ -101,7 +101,7 @@ Client::ProcessLine(char *line) noexcept
|
|||||||
std::move(list));
|
std::move(list));
|
||||||
FormatDebug(client_domain,
|
FormatDebug(client_domain,
|
||||||
"[%u] process command "
|
"[%u] process command "
|
||||||
"list returned %i", num, int(ret));
|
"list returned %i", id, int(ret));
|
||||||
|
|
||||||
if (ret == CommandResult::OK)
|
if (ret == CommandResult::OK)
|
||||||
command_success(*this);
|
command_success(*this);
|
||||||
@ -127,16 +127,15 @@ Client::ProcessLine(char *line) noexcept
|
|||||||
cmd_list.Begin(true);
|
cmd_list.Begin(true);
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
} else {
|
} else {
|
||||||
|
const unsigned id = num;
|
||||||
|
|
||||||
FormatDebug(client_domain,
|
FormatDebug(client_domain,
|
||||||
"[%u] process command \"%s\"",
|
"[%u] process command \"%s\"",
|
||||||
num, line);
|
id, line);
|
||||||
auto ret = command_process(*this, 0, line);
|
auto ret = command_process(*this, 0, line);
|
||||||
FormatDebug(client_domain,
|
FormatDebug(client_domain,
|
||||||
"[%u] command returned %i",
|
"[%u] command returned %i",
|
||||||
num, int(ret));
|
id, int(ret));
|
||||||
|
|
||||||
if (IsExpired())
|
|
||||||
return CommandResult::CLOSE;
|
|
||||||
|
|
||||||
if (ret == CommandResult::OK)
|
if (ret == CommandResult::OK)
|
||||||
command_success(*this);
|
command_success(*this);
|
||||||
|
@ -66,10 +66,5 @@ Client::OnSocketInput(void *data, size_t length) noexcept
|
|||||||
return InputResult::CLOSED;
|
return InputResult::CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsExpired()) {
|
|
||||||
Close();
|
|
||||||
return InputResult::CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InputResult::AGAIN;
|
return InputResult::AGAIN;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#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
|
bool
|
||||||
Client::Write(const char *data) noexcept
|
Client::Write(const char *data) noexcept
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user