0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 10:08:36 +02:00
construct/include/ircd/net/listener.h

99 lines
1.9 KiB
C
Raw Normal View History

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;
using callback = std::function<void (const std::shared_ptr<socket> &)>;
2017-10-19 10:30:19 +02:00
IRCD_EXCEPTION(net::error, error)
2017-10-19 10:30:19 +02:00
private:
std::shared_ptr<struct acceptor> acceptor;
2017-10-19 10:30:19 +02:00
public:
listener(const string_view &name,
const json::object &options,
callback);
explicit
listener(const string_view &name,
const std::string &options,
callback);
2017-10-19 10:30:19 +02:00
~listener() noexcept;
};
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:
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;
};
struct ircd::net::listener_udp::datagram
{
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};
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,
};