mirror of
https://github.com/matrix-construct/construct
synced 2024-12-30 17:34:04 +01:00
ircd::net: Move acceptors class from being nested in listeners.
This commit is contained in:
parent
f8652e2b46
commit
c6975804e7
3 changed files with 59 additions and 59 deletions
|
@ -16,21 +16,17 @@
|
||||||
// is part of the <ircd/asio.h> stack which can be included in your
|
// is part of the <ircd/asio.h> stack which can be included in your
|
||||||
// definition file if you need low level access to this acceptor API.
|
// definition file if you need low level access to this acceptor API.
|
||||||
|
|
||||||
namespace ircd::net
|
struct ircd::net::acceptor
|
||||||
{
|
:std::enable_shared_from_this<struct ircd::net::acceptor>
|
||||||
std::ostream &operator<<(std::ostream &s, const struct listener::acceptor &);
|
|
||||||
std::ostream &operator<<(std::ostream &s, const struct listener_udp::acceptor &);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ircd::net::listener::acceptor
|
|
||||||
:std::enable_shared_from_this<struct ircd::net::listener::acceptor>
|
|
||||||
{
|
{
|
||||||
using error_code = boost::system::error_code;
|
using error_code = boost::system::error_code;
|
||||||
|
using callback = listener::callback;
|
||||||
|
using proffer = listener::proffer;
|
||||||
|
|
||||||
static log::log log;
|
static log::log log;
|
||||||
static conf::item<milliseconds> timeout;
|
static conf::item<milliseconds> timeout;
|
||||||
|
|
||||||
net::listener *listener;
|
net::listener *listener_;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string opts;
|
std::string opts;
|
||||||
size_t backlog;
|
size_t backlog;
|
||||||
|
@ -71,11 +67,13 @@ struct ircd::net::listener::acceptor
|
||||||
~acceptor() noexcept;
|
~acceptor() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::net::listener_udp::acceptor
|
struct ircd::net::acceptor_udp
|
||||||
{
|
{
|
||||||
using error_code = boost::system::error_code;
|
using error_code = boost::system::error_code;
|
||||||
|
using datagram = listener_udp::datagram;
|
||||||
|
using flag = listener_udp::flag;
|
||||||
|
|
||||||
static constexpr log::log &log {listener::acceptor::log};
|
static constexpr log::log &log {acceptor::log};
|
||||||
static ip::udp::socket::message_flags flags(const flag &);
|
static ip::udp::socket::message_flags flags(const flag &);
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -92,8 +90,8 @@ struct ircd::net::listener_udp::acceptor
|
||||||
bool interrupt() noexcept;
|
bool interrupt() noexcept;
|
||||||
void join() noexcept;
|
void join() noexcept;
|
||||||
|
|
||||||
acceptor(const string_view &name,
|
acceptor_udp(const string_view &name,
|
||||||
const json::object &opts);
|
const json::object &opts);
|
||||||
|
|
||||||
~acceptor() noexcept;
|
~acceptor_udp() noexcept;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,24 +14,27 @@
|
||||||
namespace ircd::net
|
namespace ircd::net
|
||||||
{
|
{
|
||||||
struct listener;
|
struct listener;
|
||||||
|
struct acceptor;
|
||||||
struct listener_udp;
|
struct listener_udp;
|
||||||
|
struct acceptor_udp;
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &s, const listener &);
|
std::ostream &operator<<(std::ostream &s, const listener &);
|
||||||
|
std::ostream &operator<<(std::ostream &s, const acceptor &);
|
||||||
std::ostream &operator<<(std::ostream &s, const listener_udp &);
|
std::ostream &operator<<(std::ostream &s, const listener_udp &);
|
||||||
|
std::ostream &operator<<(std::ostream &s, const acceptor_udp &);
|
||||||
|
|
||||||
extern conf::item<bool> listen;
|
extern conf::item<bool> listen;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ircd::net::listener
|
struct ircd::net::listener
|
||||||
{
|
{
|
||||||
struct acceptor;
|
|
||||||
using callback = std::function<void (listener &, const std::shared_ptr<socket> &)>;
|
using callback = std::function<void (listener &, const std::shared_ptr<socket> &)>;
|
||||||
using proffer = std::function<bool (listener &, const ipport &)>;
|
using proffer = std::function<bool (listener &, const ipport &)>;
|
||||||
|
|
||||||
IRCD_EXCEPTION(net::error, error)
|
IRCD_EXCEPTION(net::error, error)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<struct acceptor> acceptor;
|
std::shared_ptr<net::acceptor> acceptor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit operator json::object() const;
|
explicit operator json::object() const;
|
||||||
|
@ -57,14 +60,13 @@ struct ircd::net::listener
|
||||||
|
|
||||||
struct ircd::net::listener_udp
|
struct ircd::net::listener_udp
|
||||||
{
|
{
|
||||||
struct acceptor;
|
|
||||||
struct datagram;
|
struct datagram;
|
||||||
enum flag :uint;
|
enum flag :uint;
|
||||||
|
|
||||||
IRCD_EXCEPTION(net::error, error)
|
IRCD_EXCEPTION(net::error, error)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<struct acceptor> acceptor;
|
std::unique_ptr<net::acceptor_udp> acceptor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit operator json::object() const;
|
explicit operator json::object() const;
|
||||||
|
|
60
ircd/net.cc
60
ircd/net.cc
|
@ -1019,7 +1019,7 @@ ircd::net::listener_udp::listener_udp(const string_view &name,
|
||||||
const json::object &opts)
|
const json::object &opts)
|
||||||
:acceptor
|
:acceptor
|
||||||
{
|
{
|
||||||
std::make_unique<struct acceptor>(name, opts)
|
std::make_unique<net::acceptor_udp>(name, opts)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1065,24 +1065,24 @@ namespace ircd::net
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener::acceptor
|
// acceptor
|
||||||
//
|
//
|
||||||
|
|
||||||
decltype(ircd::net::listener::acceptor::log)
|
decltype(ircd::net::acceptor::log)
|
||||||
ircd::net::listener::acceptor::log
|
ircd::net::acceptor::log
|
||||||
{
|
{
|
||||||
"listener"
|
"listener"
|
||||||
};
|
};
|
||||||
|
|
||||||
decltype(ircd::net::listener::acceptor::timeout)
|
decltype(ircd::net::acceptor::timeout)
|
||||||
ircd::net::listener::acceptor::timeout
|
ircd::net::acceptor::timeout
|
||||||
{
|
{
|
||||||
{ "name", "ircd.net.acceptor.timeout" },
|
{ "name", "ircd.net.acceptor.timeout" },
|
||||||
{ "default", 12000L },
|
{ "default", 12000L },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::net::operator<<(std::ostream &s, const struct listener::acceptor &a)
|
ircd::net::operator<<(std::ostream &s, const acceptor &a)
|
||||||
{
|
{
|
||||||
thread_local char addrbuf[128];
|
thread_local char addrbuf[128];
|
||||||
s << "'" << a.name << "' @ [" << string(addrbuf, a.ep.address()) << "]:" << a.ep.port();
|
s << "'" << a.name << "' @ [" << string(addrbuf, a.ep.address()) << "]:" << a.ep.port();
|
||||||
|
@ -1090,16 +1090,16 @@ ircd::net::operator<<(std::ostream &s, const struct listener::acceptor &a)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener::acceptor::acceptor
|
// acceptor::acceptor
|
||||||
//
|
//
|
||||||
|
|
||||||
ircd::net::listener::acceptor::acceptor(net::listener &listener,
|
ircd::net::acceptor::acceptor(net::listener &listener,
|
||||||
const string_view &name,
|
const string_view &name,
|
||||||
const json::object &opts,
|
const json::object &opts,
|
||||||
listener::callback cb,
|
listener::callback cb,
|
||||||
listener::proffer pcb)
|
listener::proffer pcb)
|
||||||
try
|
try
|
||||||
:listener
|
:listener_
|
||||||
{
|
{
|
||||||
&listener
|
&listener
|
||||||
}
|
}
|
||||||
|
@ -1185,13 +1185,13 @@ catch(const boost::system::system_error &e)
|
||||||
throw_system_error(e);
|
throw_system_error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::net::listener::acceptor::~acceptor()
|
ircd::net::acceptor::~acceptor()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::net::listener::acceptor::join()
|
ircd::net::acceptor::join()
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
interrupt();
|
interrupt();
|
||||||
|
@ -1211,7 +1211,7 @@ catch(const std::exception &e)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::net::listener::acceptor::interrupt()
|
ircd::net::acceptor::interrupt()
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
interrupting = true;
|
interrupting = true;
|
||||||
|
@ -1235,7 +1235,7 @@ catch(const boost::system::system_error &e)
|
||||||
/// socket. After the connect, an asynchronous SSL handshake handler is set
|
/// socket. After the connect, an asynchronous SSL handshake handler is set
|
||||||
/// for the socket.
|
/// for the socket.
|
||||||
bool
|
bool
|
||||||
ircd::net::listener::acceptor::set_handle()
|
ircd::net::acceptor::set_handle()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assert(!handle_set);
|
assert(!handle_set);
|
||||||
|
@ -1262,7 +1262,7 @@ catch(const std::exception &e)
|
||||||
/// asynchronous SSL handshake sequence.
|
/// asynchronous SSL handshake sequence.
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
ircd::net::listener::acceptor::accept(const error_code &ec,
|
ircd::net::acceptor::accept(const error_code &ec,
|
||||||
const std::shared_ptr<socket> sock,
|
const std::shared_ptr<socket> sock,
|
||||||
const std::weak_ptr<acceptor> a)
|
const std::weak_ptr<acceptor> a)
|
||||||
noexcept try
|
noexcept try
|
||||||
|
@ -1290,7 +1290,7 @@ noexcept try
|
||||||
|
|
||||||
// Call the proffer-callback if available. This allows the application
|
// Call the proffer-callback if available. This allows the application
|
||||||
// to check whether to allow or deny this remote before the handshake.
|
// to check whether to allow or deny this remote before the handshake.
|
||||||
if(pcb && !pcb(*listener, remote_ipport(*sock)))
|
if(pcb && !pcb(*listener_, remote_ipport(*sock)))
|
||||||
{
|
{
|
||||||
net::close(*sock, dc::RST, close_ignore);
|
net::close(*sock, dc::RST, close_ignore);
|
||||||
return;
|
return;
|
||||||
|
@ -1365,7 +1365,7 @@ catch(const std::exception &e)
|
||||||
/// result.
|
/// result.
|
||||||
///
|
///
|
||||||
bool
|
bool
|
||||||
ircd::net::listener::acceptor::check_accept_error(const error_code &ec,
|
ircd::net::acceptor::check_accept_error(const error_code &ec,
|
||||||
socket &sock)
|
socket &sock)
|
||||||
{
|
{
|
||||||
using std::errc;
|
using std::errc;
|
||||||
|
@ -1389,7 +1389,7 @@ ircd::net::listener::acceptor::check_accept_error(const error_code &ec,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::net::listener::acceptor::handshake(const error_code &ec,
|
ircd::net::acceptor::handshake(const error_code &ec,
|
||||||
const std::shared_ptr<socket> sock,
|
const std::shared_ptr<socket> sock,
|
||||||
const std::weak_ptr<acceptor> a)
|
const std::weak_ptr<acceptor> a)
|
||||||
noexcept try
|
noexcept try
|
||||||
|
@ -1421,7 +1421,7 @@ noexcept try
|
||||||
check_handshake_error(ec, *sock);
|
check_handshake_error(ec, *sock);
|
||||||
sock->cancel_timeout();
|
sock->cancel_timeout();
|
||||||
assert(bool(cb));
|
assert(bool(cb));
|
||||||
cb(*listener, sock);
|
cb(*listener_, sock);
|
||||||
}
|
}
|
||||||
catch(const ctx::interrupted &e)
|
catch(const ctx::interrupted &e)
|
||||||
{
|
{
|
||||||
|
@ -1469,7 +1469,7 @@ catch(const std::exception &e)
|
||||||
/// result.
|
/// result.
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
ircd::net::listener::acceptor::check_handshake_error(const error_code &ec,
|
ircd::net::acceptor::check_handshake_error(const error_code &ec,
|
||||||
socket &sock)
|
socket &sock)
|
||||||
{
|
{
|
||||||
using std::errc;
|
using std::errc;
|
||||||
|
@ -1496,7 +1496,7 @@ ircd::net::listener::acceptor::check_handshake_error(const error_code &ec,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::net::listener::acceptor::configure(const json::object &opts)
|
ircd::net::acceptor::configure(const json::object &opts)
|
||||||
{
|
{
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
|
@ -1659,21 +1659,21 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener_udp::acceptor
|
// acceptor_udp
|
||||||
//
|
//
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::net::operator<<(std::ostream &s, const struct listener_udp::acceptor &a)
|
ircd::net::operator<<(std::ostream &s, const acceptor_udp &a)
|
||||||
{
|
{
|
||||||
s << "'" << a.name << "' @ [" << string(a.ep.address()) << "]:" << a.ep.port();
|
s << "'" << a.name << "' @ [" << string(a.ep.address()) << "]:" << a.ep.port();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener_udp::acceptor::acceptor
|
// acceptor_udp::acceptor
|
||||||
//
|
//
|
||||||
|
|
||||||
ircd::net::listener_udp::acceptor::acceptor(const string_view &name,
|
ircd::net::acceptor_udp::acceptor_udp(const string_view &name,
|
||||||
const json::object &opts)
|
const json::object &opts)
|
||||||
try
|
try
|
||||||
:name
|
:name
|
||||||
|
@ -1717,13 +1717,13 @@ catch(const boost::system::system_error &e)
|
||||||
throw_system_error(e);
|
throw_system_error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::net::listener_udp::acceptor::~acceptor()
|
ircd::net::acceptor_udp::~acceptor_udp()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::net::listener_udp::acceptor::join()
|
ircd::net::acceptor_udp::join()
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
interrupt();
|
interrupt();
|
||||||
|
@ -1741,7 +1741,7 @@ catch(const std::exception &e)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::net::listener_udp::acceptor::interrupt()
|
ircd::net::acceptor_udp::interrupt()
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
a.cancel();
|
a.cancel();
|
||||||
|
@ -1758,7 +1758,7 @@ catch(const boost::system::system_error &e)
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::net::listener_udp::datagram &
|
ircd::net::listener_udp::datagram &
|
||||||
ircd::net::listener_udp::acceptor::operator()(datagram &datagram)
|
ircd::net::acceptor_udp::operator()(datagram &datagram)
|
||||||
{
|
{
|
||||||
assert(ctx::current);
|
assert(ctx::current);
|
||||||
|
|
||||||
|
@ -1794,7 +1794,7 @@ ircd::net::listener_udp::acceptor::operator()(datagram &datagram)
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::asio::ip::udp::socket::message_flags
|
boost::asio::ip::udp::socket::message_flags
|
||||||
ircd::net::listener_udp::acceptor::flags(const flag &flag)
|
ircd::net::acceptor_udp::flags(const flag &flag)
|
||||||
{
|
{
|
||||||
ip::udp::socket::message_flags ret{0};
|
ip::udp::socket::message_flags ret{0};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue