0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

ircd: Add integration utils for system and boost error related.

This commit is contained in:
Jason Volk 2018-03-08 09:21:16 -08:00
parent eafa9fd5b2
commit f10c61e046
2 changed files with 115 additions and 21 deletions

View file

@ -35,13 +35,22 @@ namespace ircd
[[noreturn]] void assertion() noexcept(RB_DEBUG_LEVEL);
// util
std::exception_ptr make_system_error(const int &code = errno);
[[noreturn]] void throw_system_error(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 boost::system::error_code &);
std::error_code make_error_code(const boost::system::system_error &);
std::system_error make_system_error(const int &code = errno);
std::system_error make_system_error(const boost::system::error_code &);
std::system_error make_system_error(const boost::system::system_error &);
template<class... args> std::exception_ptr make_system_eptr(args&&...);
template<class... args> [[noreturn]] void throw_system_error(args&&...);
// Forward utilities for boost errors
std::exception_ptr make_eptr(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 &);
string_view string(const mutable_buffer &, const boost::system::system_error &);
std::string string(const std::error_code &);
std::string string(const std::system_error &);
std::string string(const boost::system::error_code &);
std::string string(const boost::system::system_error &);
@ -197,3 +206,20 @@ namespace ircd
IRCD_ASSERTION(exception, assertive)
IRCD_ASSERTION(assertive, not_implemented)
}
template<class... args>
void
ircd::throw_system_error(args&&... a)
{
throw std::system_error
{
make_error_code(std::forward<args>(a)...)
};
}
template<class... args>
std::exception_ptr
ircd::make_system_eptr(args&&... a)
{
return std::make_exception_ptr(make_system_error(std::forward<args>(a)...));
}

View file

@ -40,6 +40,22 @@ ircd::string(const boost::system::error_code &ec)
});
}
std::string
ircd::string(const std::system_error &e)
{
return string(e.code());
}
std::string
ircd::string(const std::error_code &ec)
{
return ircd::string(128, [&ec]
(const mutable_buffer &buf)
{
return string(buf, ec);
});
}
ircd::string_view
ircd::string(const mutable_buffer &buf,
const boost::system::system_error &e)
@ -51,35 +67,87 @@ ircd::string_view
ircd::string(const mutable_buffer &buf,
const boost::system::error_code &ec)
{
const auto len
return fmt::sprintf
{
fmt::sprintf
{
buf, "%s: %s", ec.category().name(), ec.message()
}
buf, "%s: %s", ec.category().name(), ec.message()
};
return { data(buf), size_t(len) };
}
std::exception_ptr
ircd::make_eptr(const boost::system::error_code &ec)
ircd::string_view
ircd::string(const mutable_buffer &buf,
const std::system_error &e)
{
return bool(ec)?
std::make_exception_ptr(boost::system::system_error(ec)):
std::exception_ptr{};
return string(buf, e.code());
}
void
ircd::throw_system_error(const int &code)
ircd::string_view
ircd::string(const mutable_buffer &buf,
const std::error_code &ec)
{
throw std::system_error(code, std::system_category());
return fmt::sprintf
{
buf, "%s: %s", ec.category().name(), ec.message()
};
}
std::exception_ptr
std::system_error
ircd::make_system_error(const boost::system::system_error &e)
{
return std::system_error
{
make_error_code(e.code()), e.what()
};
}
std::system_error
ircd::make_system_error(const boost::system::error_code &ec)
{
return std::system_error
{
make_error_code(ec)
};
}
std::system_error
ircd::make_system_error(const int &code)
{
return std::make_exception_ptr(std::system_error(code, std::system_category()));
return std::system_error
{
make_error_code(code)
};
}
std::error_code
ircd::make_error_code(const boost::system::system_error &e)
{
return std::error_code
{
e.code().value(), e.code().category()
};
}
std::error_code
ircd::make_error_code(const boost::system::error_code &ec)
{
return std::error_code
{
ec.value(), ec.category()
};
}
std::error_code
ircd::make_error_code(const int &code)
{
return std::error_code
{
code, std::system_category()
};
}
std::error_code
ircd::make_error_code(const std::error_code &ec)
{
return ec;
}
ssize_t