mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd: Move boost system error related out of ios.h to exception.h et al.
This commit is contained in:
parent
f1fb3d8b49
commit
eafa9fd5b2
4 changed files with 63 additions and 63 deletions
|
@ -11,6 +11,14 @@
|
|||
#pragma once
|
||||
#define HAVE_IRCD_EXCEPTION_H
|
||||
|
||||
/// Forward declarations for boost::system because it is not included here.
|
||||
namespace boost::system
|
||||
{
|
||||
struct error_code;
|
||||
struct system_error;
|
||||
namespace errc {}
|
||||
}
|
||||
|
||||
namespace ircd
|
||||
{
|
||||
// Root exception
|
||||
|
@ -30,6 +38,13 @@ namespace ircd
|
|||
std::exception_ptr make_system_error(const int &code = errno);
|
||||
[[noreturn]] void throw_system_error(const int &code = errno);
|
||||
|
||||
// Forward utilities for boost errors
|
||||
std::exception_ptr make_eptr(const boost::system::error_code &);
|
||||
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 boost::system::error_code &);
|
||||
std::string string(const boost::system::system_error &);
|
||||
|
||||
// Can be used to clobber the std::terminate_handler
|
||||
void aborting() noexcept;
|
||||
}
|
||||
|
|
|
@ -15,14 +15,6 @@
|
|||
// definition file. Other libircd headers may extend this namespace with more
|
||||
// forward declarations.
|
||||
|
||||
/// Forward declarations for boost::system because it is not included here.
|
||||
namespace boost::system
|
||||
{
|
||||
struct error_code;
|
||||
struct system_error;
|
||||
namespace errc {}
|
||||
}
|
||||
|
||||
/// Forward declarations for boost::asio because it is not included here.
|
||||
namespace boost::asio
|
||||
{
|
||||
|
@ -53,13 +45,6 @@ namespace ircd
|
|||
|
||||
void post(std::function<void ()>);
|
||||
void dispatch(std::function<void ()>);
|
||||
|
||||
// Forward utilities for boost errors
|
||||
std::exception_ptr make_eptr(const boost::system::error_code &ec);
|
||||
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 boost::system::error_code &);
|
||||
std::string string(const boost::system::system_error &);
|
||||
}
|
||||
|
||||
inline void
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include <boost/system/system_error.hpp>
|
||||
|
||||
[[noreturn]] static void
|
||||
ircd_terminate_handler()
|
||||
noexcept
|
||||
|
@ -22,6 +24,52 @@ noexcept
|
|||
std::set_terminate(&ircd_terminate_handler);
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::string(const boost::system::system_error &e)
|
||||
{
|
||||
return string(e.code());
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::string(const boost::system::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)
|
||||
{
|
||||
return string(buf, e.code());
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::string(const mutable_buffer &buf,
|
||||
const boost::system::error_code &ec)
|
||||
{
|
||||
const auto len
|
||||
{
|
||||
fmt::sprintf
|
||||
{
|
||||
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)
|
||||
{
|
||||
return bool(ec)?
|
||||
std::make_exception_ptr(boost::system::system_error(ec)):
|
||||
std::exception_ptr{};
|
||||
}
|
||||
|
||||
void
|
||||
ircd::throw_system_error(const int &code)
|
||||
{
|
||||
|
|
48
ircd/net.cc
48
ircd/net.cc
|
@ -3163,54 +3163,6 @@ ircd::net::port(const ip::tcp::endpoint &ep)
|
|||
return ep.port();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// asio.h
|
||||
//
|
||||
|
||||
std::exception_ptr
|
||||
ircd::make_eptr(const boost::system::error_code &ec)
|
||||
{
|
||||
return bool(ec)? std::make_exception_ptr(boost::system::system_error(ec)):
|
||||
std::exception_ptr{};
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::string(const boost::system::system_error &e)
|
||||
{
|
||||
return string(e.code());
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::string(const boost::system::error_code &ec)
|
||||
{
|
||||
std::string ret(128, char{});
|
||||
ret.resize(string(mutable_buffer{ret}, ec).size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::string(const mutable_buffer &buf,
|
||||
const boost::system::system_error &e)
|
||||
{
|
||||
return string(buf, e.code());
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::string(const mutable_buffer &buf,
|
||||
const boost::system::error_code &ec)
|
||||
{
|
||||
const auto len
|
||||
{
|
||||
fmt::sprintf
|
||||
{
|
||||
buf, "%s: %s", ec.category().name(), ec.message()
|
||||
}
|
||||
};
|
||||
|
||||
return { data(buf), size_t(len) };
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// buffer.h - provide definition for the null buffers and asio conversion
|
||||
|
|
Loading…
Add table
Reference in a new issue