From b19ed6854b85441bfaf11c980361c0ea67b08062 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 13 Sep 2019 11:49:08 -0700 Subject: [PATCH] ircd::net: Consolidate all eof error_code related. --- include/ircd/net/net.h | 5 ++--- ircd/client.cc | 10 ++++------ ircd/net.cc | 34 ++++++++++++++++++++-------------- ircd/server.cc | 34 +++++++++++----------------------- 4 files changed, 37 insertions(+), 46 deletions(-) diff --git a/include/ircd/net/net.h b/include/ircd/net/net.h index eb7565e71..1acb0dd9b 100644 --- a/include/ircd/net/net.h +++ b/include/ircd/net/net.h @@ -29,10 +29,9 @@ namespace ircd::net IRCD_EXCEPTION(error, inauthentic) IRCD_EXCEPTION(error, not_found) - // SNOMASK 'N' "net" - extern log::log log; - + extern const std::error_code eof; extern conf::item enable_ipv6; + extern log::log log; } #include "hostport.h" diff --git a/ircd/client.cc b/ircd/client.cc index 2020cc3b5..a5a9633a9 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -498,11 +498,6 @@ ircd::handle_ec(client &client, case int(errc::timed_out): return handle_ec_timeout(client); default: return handle_ec_default(client, ec); } - else if(ec.category() == get_misc_category()) switch(ec.value()) - { - case asio::error::eof: return handle_ec_eof(client); - default: return handle_ec_default(client, ec); - } else if(ec.category() == get_ssl_category()) switch(uint8_t(ec.value())) { #ifdef SSL_R_SHORT_READ @@ -510,7 +505,10 @@ ircd::handle_ec(client &client, #endif default: return handle_ec_default(client, ec); } - else return handle_ec_default(client, ec); + else if(ec == net::eof) + return handle_ec_eof(client); + else + return handle_ec_default(client, ec); } /// The client indicated they will not be sending the data we have been diff --git a/ircd/net.cc b/ircd/net.cc index 3291ee049..30d987efe 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -91,11 +91,14 @@ noexcept // net/net.h // -/// Network subsystem log facility with dedicated SNOMASK. -struct ircd::log::log -ircd::net::log +decltype(ircd::net::eof) +ircd::net::eof { - "net", 'N' + make_error_code(boost::system::error_code + { + boost::asio::error::eof, + boost::asio::error::get_misc_category() + }) }; decltype(ircd::net::enable_ipv6) @@ -106,6 +109,13 @@ ircd::net::enable_ipv6 { "persist", false }, }; +/// Network subsystem log facility +decltype(ircd::net::log) +ircd::net::log +{ + "net", 'N' +}; + ircd::string_view ircd::net::peer_cert_der_sha256_b64(const mutable_buffer &buf, const socket &socket) @@ -3162,10 +3172,7 @@ noexcept static const ilist bufs{buf}; static const std::error_code eof { - make_error_code(boost::system::error_code - { - boost::asio::error::eof, boost::asio::error::get_misc_category() - }) + buf }; if(unlikely(!sd.is_open())) @@ -3223,7 +3230,7 @@ try if(!ret) throw std::system_error { - boost::asio::error::eof, boost::asio::error::get_misc_category() + eof }; ++in.calls; @@ -3261,7 +3268,7 @@ try if(!ret) throw std::system_error { - asio::error::eof, asio::error::get_misc_category() + eof }; ++in.calls; @@ -3478,7 +3485,7 @@ noexcept try ec = make_error_code(errc::bad_file_descriptor); if(type == ready::READ && !ec && bytes == 0) - ec = error_code{asio::error::eof, asio::error::get_misc_category()}; + ec = eof; #ifdef IRCD_DEBUG_NET_SOCKET_READY const auto has_pending @@ -3717,9 +3724,8 @@ noexcept try }; // This ignores EOF and turns it into a success to alleviate user concern. - if(ec.category() == asio::error::get_misc_category()) - if(ec.value() == asio::error::eof) - ec = error_code{}; + if(ec == eof) + ec = error_code{}; sd.close(); call_user(callback, ec); diff --git a/ircd/server.cc b/ircd/server.cc index 1388095d1..318edeba0 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -944,22 +944,18 @@ ircd::server::peer::handle_error(link &link, default: break; } - else if(ec.category() == get_misc_category()) switch(ec.value()) + else if(ec == net::eof) { - case asio::error::eof: - log::debug - { - log, "%s [%s]: %s", - loghead(link), - string(rembuf, remote), - e.what() - }; + log::debug + { + log, "%s [%s]: %s", + loghead(link), + string(rembuf, remote), + e.what() + }; - link.close(net::dc::RST); - return; - - default: - break; + link.close(net::dc::RST); + return; } log::derror @@ -2348,17 +2344,9 @@ ircd::server::link::discard_read() return; } - static const std::error_code end_of_file - { - make_error_code(boost::system::error_code - { - boost::asio::error::eof, boost::asio::error::get_misc_category() - }) - }; - throw std::system_error { - end_of_file + net::eof }; }