2018-01-19 15:55:48 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2018-02-04 03:22:01 +01:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_NET_ACCEPTOR_H
|
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
// This file is not included with the IRCd standard include stack because
|
|
|
|
// it requires symbols we can't forward declare without boost headers. It
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
struct ircd::net::listener::acceptor
|
|
|
|
:std::enable_shared_from_this<struct ircd::net::listener::acceptor>
|
|
|
|
{
|
|
|
|
using error_code = boost::system::error_code;
|
|
|
|
|
|
|
|
static log::log log;
|
2018-03-09 21:22:10 +01:00
|
|
|
static conf::item<milliseconds> timeout;
|
2018-01-19 15:55:48 +01:00
|
|
|
|
2019-01-18 18:42:44 +01:00
|
|
|
net::listener *listener;
|
2018-01-19 15:55:48 +01:00
|
|
|
std::string name;
|
2018-08-30 00:50:55 +02:00
|
|
|
std::string opts;
|
2018-01-19 15:55:48 +01:00
|
|
|
size_t backlog;
|
2018-07-07 03:38:08 +02:00
|
|
|
listener::callback cb;
|
2018-09-02 07:00:38 +02:00
|
|
|
listener::proffer pcb;
|
2018-01-19 15:55:48 +01:00
|
|
|
asio::ssl::context ssl;
|
|
|
|
ip::tcp::endpoint ep;
|
|
|
|
ip::tcp::acceptor a;
|
|
|
|
size_t accepting {0};
|
|
|
|
size_t handshaking {0};
|
|
|
|
bool interrupting {false};
|
2019-01-18 18:42:44 +01:00
|
|
|
bool handle_set {false};
|
2018-01-19 15:55:48 +01:00
|
|
|
ctx::dock joining;
|
|
|
|
|
|
|
|
void configure(const json::object &opts);
|
|
|
|
|
|
|
|
// Handshake stack
|
|
|
|
void check_handshake_error(const error_code &ec, socket &);
|
|
|
|
void handshake(const error_code &ec, std::shared_ptr<socket>, std::weak_ptr<acceptor>) noexcept;
|
|
|
|
|
|
|
|
// Acceptance stack
|
|
|
|
bool check_accept_error(const error_code &ec, socket &);
|
|
|
|
void accept(const error_code &ec, std::shared_ptr<socket>, std::weak_ptr<acceptor>) noexcept;
|
|
|
|
|
|
|
|
// Accept next
|
2019-01-18 18:42:44 +01:00
|
|
|
bool set_handle();
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
// Acceptor shutdown
|
|
|
|
bool interrupt() noexcept;
|
|
|
|
void join() noexcept;
|
|
|
|
|
2019-01-18 18:42:44 +01:00
|
|
|
acceptor(net::listener &,
|
|
|
|
const string_view &name,
|
2018-07-07 03:38:08 +02:00
|
|
|
const json::object &opts,
|
2018-09-02 07:00:38 +02:00
|
|
|
listener::callback,
|
|
|
|
listener::proffer);
|
2018-07-07 03:38:08 +02:00
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
~acceptor() noexcept;
|
2018-08-16 09:55:23 +02:00
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &s, const acceptor &);
|
2018-01-19 15:55:48 +01:00
|
|
|
};
|
2018-07-08 06:33:23 +02:00
|
|
|
|
|
|
|
struct ircd::net::listener_udp::acceptor
|
|
|
|
{
|
|
|
|
using error_code = boost::system::error_code;
|
|
|
|
|
|
|
|
static constexpr log::log &log {listener::acceptor::log};
|
|
|
|
static ip::udp::socket::message_flags flags(const flag &);
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
std::string opts;
|
|
|
|
ip::udp::endpoint ep;
|
|
|
|
ip::udp::socket a;
|
|
|
|
size_t waiting {0};
|
|
|
|
ctx::dock joining;
|
|
|
|
|
|
|
|
// Yield context for datagram.
|
|
|
|
datagram &operator()(datagram &);
|
|
|
|
|
|
|
|
// Acceptor shutdown
|
|
|
|
bool interrupt() noexcept;
|
|
|
|
void join() noexcept;
|
|
|
|
|
|
|
|
acceptor(const string_view &name,
|
|
|
|
const json::object &opts);
|
|
|
|
|
|
|
|
~acceptor() noexcept;
|
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &s, const acceptor &);
|
|
|
|
};
|