mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 06:51:08 +01:00
ircd: Simplify system_category / posix errno code test.
This commit is contained in:
parent
af93d55927
commit
9e97ac0564
3 changed files with 13 additions and 17 deletions
|
@ -27,6 +27,9 @@ namespace ircd
|
||||||
struct exception; // Root exception
|
struct exception; // Root exception
|
||||||
|
|
||||||
// util
|
// 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 int &code = errno);
|
||||||
std::error_code make_error_code(const std::error_code &);
|
std::error_code make_error_code(const std::error_code &);
|
||||||
std::error_code make_error_code(const std::system_error &);
|
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> std::exception_ptr make_system_eptr(args&&...);
|
||||||
template<class... args> [[noreturn]] void throw_system_error(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::error_code &);
|
||||||
string_view string(const mutable_buffer &, const std::system_error &);
|
string_view string(const mutable_buffer &, const std::system_error &);
|
||||||
string_view string(const mutable_buffer &, const boost::system::error_code &);
|
string_view string(const mutable_buffer &, const boost::system::error_code &);
|
||||||
|
|
|
@ -88,25 +88,23 @@ ircd::string(const mutable_buffer &buf,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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());
|
return system_category(ec) && ec.value() == int(errc);
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::system_category(const boost::system::error_category &ec)
|
|
||||||
{
|
|
||||||
return ec == boost::system::system_category();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::system_category(const std::error_code &ec)
|
ircd::system_category(const std::error_code &ec)
|
||||||
|
noexcept
|
||||||
{
|
{
|
||||||
return system_category(ec.category());
|
return system_category(ec.category());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::system_category(const std::error_category &ec)
|
ircd::system_category(const std::error_category &ec)
|
||||||
|
noexcept
|
||||||
{
|
{
|
||||||
return ec == std::system_category() ||
|
return ec == std::system_category() ||
|
||||||
ec == std::generic_category() ||
|
ec == std::generic_category() ||
|
||||||
|
|
|
@ -2228,10 +2228,10 @@ noexcept try
|
||||||
// After life_guard is constructed it is safe to use *this in this frame.
|
// After life_guard is constructed it is safe to use *this in this frame.
|
||||||
const life_guard<socket> s{wp};
|
const life_guard<socket> s{wp};
|
||||||
|
|
||||||
if(!timedout && ec != errc::operation_canceled && !fini)
|
if(!timedout && !is(ec, errc::operation_canceled) && !fini)
|
||||||
cancel_timeout();
|
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);
|
ec = make_error_code(errc::timed_out);
|
||||||
|
|
||||||
if(unlikely(!ec && !sd.is_open()))
|
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.
|
// 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();
|
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);
|
ec = make_error_code(errc::timed_out);
|
||||||
|
|
||||||
// A connect error; abort here by calling the user back with error.
|
// A connect error; abort here by calling the user back with error.
|
||||||
|
|
Loading…
Reference in a new issue