2018-02-04 03:22:01 +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.
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_NET_LISTENER_H
|
|
|
|
|
|
|
|
namespace ircd::net
|
|
|
|
{
|
|
|
|
struct listener;
|
2018-07-08 06:33:23 +02:00
|
|
|
struct listener_udp;
|
2017-10-19 10:30:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::net::listener
|
|
|
|
{
|
|
|
|
struct acceptor;
|
2018-07-07 03:38:08 +02:00
|
|
|
using callback = std::function<void (const std::shared_ptr<socket> &)>;
|
2018-09-02 07:00:38 +02:00
|
|
|
using proffer = std::function<bool (const ipport &)>;
|
2017-10-19 10:30:19 +02:00
|
|
|
|
2018-07-08 04:44:45 +02:00
|
|
|
IRCD_EXCEPTION(net::error, error)
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
private:
|
2017-11-01 23:51:24 +01:00
|
|
|
std::shared_ptr<struct acceptor> acceptor;
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
public:
|
2018-08-30 00:50:55 +02:00
|
|
|
explicit operator json::object() const;
|
2018-08-31 04:15:28 +02:00
|
|
|
string_view name() const;
|
2018-08-30 00:50:55 +02:00
|
|
|
|
2018-07-07 03:38:08 +02:00
|
|
|
listener(const string_view &name,
|
|
|
|
const json::object &options,
|
2018-09-02 07:00:38 +02:00
|
|
|
callback,
|
|
|
|
proffer = {});
|
2018-07-07 03:38:08 +02:00
|
|
|
|
|
|
|
explicit
|
|
|
|
listener(const string_view &name,
|
|
|
|
const std::string &options,
|
2018-09-02 07:00:38 +02:00
|
|
|
callback,
|
|
|
|
proffer = {});
|
2018-07-07 03:38:08 +02:00
|
|
|
|
2017-10-19 10:30:19 +02:00
|
|
|
~listener() noexcept;
|
2018-08-16 09:55:23 +02:00
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &s, const listener &);
|
2017-10-19 10:30:19 +02:00
|
|
|
};
|
2018-07-08 06:33:23 +02:00
|
|
|
|
|
|
|
struct ircd::net::listener_udp
|
|
|
|
{
|
|
|
|
struct acceptor;
|
|
|
|
struct datagram;
|
|
|
|
enum flag :uint;
|
|
|
|
|
|
|
|
IRCD_EXCEPTION(net::error, error)
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<struct acceptor> acceptor;
|
|
|
|
|
|
|
|
public:
|
2018-08-30 00:50:55 +02:00
|
|
|
explicit operator json::object() const;
|
2018-08-31 04:15:28 +02:00
|
|
|
string_view name() const;
|
2018-08-30 00:50:55 +02:00
|
|
|
|
2018-07-08 06:33:23 +02:00
|
|
|
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;
|
2018-08-16 09:55:23 +02:00
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &s, const listener_udp &);
|
2018-07-08 06:33:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::net::listener_udp::datagram
|
|
|
|
{
|
2018-07-08 07:10:29 +02:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const_buffer cbuf;
|
|
|
|
mutable_buffer mbuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
vector_view<const_buffer> cbufs;
|
|
|
|
vector_view<mutable_buffer> mbufs;
|
|
|
|
};
|
|
|
|
|
2018-07-08 06:33:23 +02:00
|
|
|
ipport remote;
|
|
|
|
enum flag flag {(enum flag)0};
|
2018-07-08 07:10:29 +02:00
|
|
|
|
|
|
|
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);
|
2018-07-08 06:33:23 +02:00
|
|
|
|
|
|
|
datagram() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ircd::net::listener_udp::flag
|
|
|
|
:uint
|
|
|
|
{
|
|
|
|
PEEK = 0x01,
|
|
|
|
};
|