0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-03 09:18:19 +02:00

ircd::net: Split headers for UDP and TCP for listener related.

This commit is contained in:
Jason Volk 2019-03-10 14:07:56 -07:00
parent c6975804e7
commit d58b67bca8
6 changed files with 130 additions and 94 deletions

View file

@ -66,32 +66,3 @@ struct ircd::net::acceptor
~acceptor() noexcept;
};
struct ircd::net::acceptor_udp
{
using error_code = boost::system::error_code;
using datagram = listener_udp::datagram;
using flag = listener_udp::flag;
static constexpr log::log &log {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_udp(const string_view &name,
const json::object &opts);
~acceptor_udp() noexcept;
};

View file

@ -0,0 +1,46 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
#pragma once
#define HAVE_IRCD_NET_ACCEPTOR_UDP_H
// 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::acceptor_udp
{
using error_code = boost::system::error_code;
using datagram = listener_udp::datagram;
using flag = listener_udp::flag;
static constexpr log::log &log {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_udp(const string_view &name,
const json::object &opts);
~acceptor_udp() noexcept;
};

View file

@ -39,6 +39,7 @@ namespace ircd::net
#include <ircd/net/socket.h>
#include <ircd/net/acceptor.h>
#include <ircd/net/acceptor_udp.h>
namespace ircd
{

View file

@ -15,13 +15,9 @@ namespace ircd::net
{
struct listener;
struct acceptor;
struct listener_udp;
struct acceptor_udp;
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 acceptor_udp &);
extern conf::item<bool> listen;
}
@ -57,64 +53,3 @@ struct ircd::net::listener
friend std::ostream &operator<<(std::ostream &s, const listener &);
};
struct ircd::net::listener_udp
{
struct datagram;
enum flag :uint;
IRCD_EXCEPTION(net::error, error)
private:
std::unique_ptr<net::acceptor_udp> acceptor;
public:
explicit operator json::object() const;
string_view name() const;
datagram &operator()(datagram &);
listener_udp(const string_view &name,
const json::object &options);
explicit
listener_udp(const string_view &name,
const std::string &options);
~listener_udp() noexcept;
friend std::ostream &operator<<(std::ostream &s, const listener_udp &);
};
struct ircd::net::listener_udp::datagram
{
union
{
const_buffer cbuf;
mutable_buffer mbuf;
};
union
{
vector_view<const_buffer> cbufs;
vector_view<mutable_buffer> mbufs;
};
ipport remote;
enum flag flag {(enum flag)0};
datagram(const const_buffer &buf,
const ipport &remote,
const enum flag &flag = (enum flag)0);
datagram(const mutable_buffer &buf,
const enum flag &flag = (enum flag)0);
datagram() = default;
};
enum ircd::net::listener_udp::flag
:uint
{
PEEK = 0x01,
};

View file

@ -0,0 +1,82 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
#pragma once
#define HAVE_IRCD_NET_LISTENER_UDP_H
namespace ircd::net
{
struct listener_udp;
struct acceptor_udp;
std::ostream &operator<<(std::ostream &s, const listener_udp &);
std::ostream &operator<<(std::ostream &s, const acceptor_udp &);
}
struct ircd::net::listener_udp
{
struct datagram;
enum flag :uint;
IRCD_EXCEPTION(net::error, error)
private:
std::unique_ptr<net::acceptor_udp> acceptor;
public:
explicit operator json::object() const;
string_view name() const;
datagram &operator()(datagram &);
listener_udp(const string_view &name,
const json::object &options);
explicit
listener_udp(const string_view &name,
const std::string &options);
~listener_udp() noexcept;
friend std::ostream &operator<<(std::ostream &s, const listener_udp &);
};
struct ircd::net::listener_udp::datagram
{
union
{
const_buffer cbuf;
mutable_buffer mbuf;
};
union
{
vector_view<const_buffer> cbufs;
vector_view<mutable_buffer> mbufs;
};
ipport remote;
enum flag flag {(enum flag)0};
datagram(const const_buffer &buf,
const ipport &remote,
const enum flag &flag = (enum flag)0);
datagram(const mutable_buffer &buf,
const enum flag &flag = (enum flag)0);
datagram() = default;
};
enum ircd::net::listener_udp::flag
:uint
{
PEEK = 0x01,
};

View file

@ -38,6 +38,7 @@ namespace ircd::net
#include "ipport.h"
#include "dns.h"
#include "listener.h"
#include "listener_udp.h"
#include "sock_opts.h"
#include "open.h"
#include "close.h"