From 09923ff758e5751a6cc7713dfe74266d93f6d6b5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 12 Mar 2018 14:06:12 -0700 Subject: [PATCH] ircd::server: Add external interface to clear a peer error; w/ console command. --- include/ircd/server/peer.h | 2 +- include/ircd/server/server.h | 1 + ircd/server.cc | 19 ++++++++++++++++++- modules/console.cc | 21 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/ircd/server/peer.h b/include/ircd/server/peer.h index d82373ac2..9a5dc7cc5 100644 --- a/include/ircd/server/peer.h +++ b/include/ircd/server/peer.h @@ -88,7 +88,7 @@ struct ircd::server::peer bool err_has() const; string_view err_msg() const; template void err_set(A&&...); - void err_clear(); + bool err_clear(); bool err_check(); // control panel diff --git a/include/ircd/server/server.h b/include/ircd/server/server.h index 3fc517949..ac9912237 100644 --- a/include/ircd/server/server.h +++ b/include/ircd/server/server.h @@ -37,6 +37,7 @@ namespace ircd::server size_t peer_unfinished(); string_view errmsg(const net::hostport &); + bool errclear(const net::hostport &); bool exists(const net::hostport &); peer &find(const net::hostport &); peer &get(const net::hostport &); diff --git a/ircd/server.cc b/ircd/server.cc index 8b4dda641..262cb1f9f 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -124,6 +124,21 @@ ircd::server::exists(const net::hostport &hostport) return peers.find(host(hostport)) != end(peers); } +bool +ircd::server::errclear(const net::hostport &hostport) +{ + const auto it + { + peers.find(host(hostport)) + }; + + if(it == end(peers)) + return false; + + auto &peer(*it->second); + return peer.err_clear(); +} + ircd::string_view ircd::server::errmsg(const net::hostport &hostport) { @@ -368,10 +383,12 @@ ircd::server::peer::interrupt() })); } -void +bool ircd::server::peer::err_clear() { + const auto ret{bool(e)}; e.reset(nullptr); + return ret; } template diff --git a/modules/console.cc b/modules/console.cc index dd33babea..afdbc2351 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -382,6 +382,7 @@ console_cmd__net(const string_view &line) } } +static bool console_cmd__net_peer__clear(const string_view &line); static bool console_cmd__net_peer__default(); bool @@ -397,6 +398,9 @@ console_cmd__net_peer(const string_view &line) switch(hash(token(line, ' ', 0))) { + case hash("clear"): + return console_cmd__net_peer__clear(args); + default: throw bad_command{}; } @@ -404,6 +408,23 @@ console_cmd__net_peer(const string_view &line) return true; } +bool +console_cmd__net_peer__clear(const string_view &line) +{ + const net::hostport hp + { + token(line, ' ', 0) + }; + + const auto cleared + { + server::errclear(hp) + }; + + out << std::boolalpha << cleared << std::endl; + return true; +} + bool console_cmd__net_peer__default() {