0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 03:38:53 +02:00

ircd: Simplify system_category / posix errno code test.

This commit is contained in:
Jason Volk 2018-11-09 00:29:31 -08:00
parent af93d55927
commit 9e97ac0564
3 changed files with 13 additions and 17 deletions

View file

@ -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<class... args> std::exception_ptr make_system_eptr(args&&...);
template<class... args> [[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 &);

View file

@ -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() ||

View file

@ -2228,10 +2228,10 @@ noexcept try
// After life_guard is constructed it is safe to use *this in this frame.
const life_guard<socket> 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.