From 9e97ac0564851f226093ed8edae41a1d2b782fb6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 9 Nov 2018 00:29:31 -0800 Subject: [PATCH] ircd: Simplify system_category / posix errno code test. --- include/ircd/exception.h | 8 +++----- ircd/exception.cc | 14 ++++++-------- ircd/net.cc | 8 ++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/ircd/exception.h b/include/ircd/exception.h index 5f86c05c0..bb2e3ca4b 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -27,6 +27,9 @@ namespace ircd struct exception; // Root exception // util + bool system_category(const std::error_category &) noexcept; + bool system_category(const std::error_code &) noexcept; + bool is(const std::error_code &, const std::errc &) noexcept; std::error_code make_error_code(const int &code = errno); std::error_code make_error_code(const std::error_code &); std::error_code make_error_code(const std::system_error &); @@ -40,11 +43,6 @@ namespace ircd template std::exception_ptr make_system_eptr(args&&...); template [[noreturn]] void throw_system_error(args&&...); - bool system_category(const std::error_category &); - bool system_category(const std::error_code &); - bool system_category(const boost::system::error_category &); - bool system_category(const boost::system::error_code &); - string_view string(const mutable_buffer &, const std::error_code &); string_view string(const mutable_buffer &, const std::system_error &); string_view string(const mutable_buffer &, const boost::system::error_code &); diff --git a/ircd/exception.cc b/ircd/exception.cc index 79fef2d8d..fe7b30ee5 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -88,25 +88,23 @@ ircd::string(const mutable_buffer &buf, } bool -ircd::system_category(const boost::system::error_code &ec) +ircd::is(const std::error_code &ec, + const std::errc &errc) +noexcept { - return system_category(ec.category()); -} - -bool -ircd::system_category(const boost::system::error_category &ec) -{ - return ec == boost::system::system_category(); + return system_category(ec) && ec.value() == int(errc); } bool ircd::system_category(const std::error_code &ec) +noexcept { return system_category(ec.category()); } bool ircd::system_category(const std::error_category &ec) +noexcept { return ec == std::system_category() || ec == std::generic_category() || diff --git a/ircd/net.cc b/ircd/net.cc index e9dcc973d..41bda9042 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -2228,10 +2228,10 @@ noexcept try // After life_guard is constructed it is safe to use *this in this frame. const life_guard s{wp}; - if(!timedout && ec != errc::operation_canceled && !fini) + if(!timedout && !is(ec, errc::operation_canceled) && !fini) cancel_timeout(); - if(timedout && system_category(ec) && ec == errc::operation_canceled) + if(timedout && is(ec, errc::operation_canceled)) ec = make_error_code(errc::timed_out); if(unlikely(!ec && !sd.is_open())) @@ -2393,10 +2393,10 @@ noexcept try }; // The timer was set by socket::connect() and may need to be canceled. - if(!timedout && ec != errc::operation_canceled && !fini) + if(!timedout && !is(ec, errc::operation_canceled) && !fini) cancel_timeout(); - if(timedout && ec == errc::operation_canceled && system_category(ec)) + if(timedout && is(ec, errc::operation_canceled)) ec = make_error_code(errc::timed_out); // A connect error; abort here by calling the user back with error.