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

59 lines
1.5 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;
struct acceptor;
2019-02-16 01:47:00 +01:00
std::ostream &operator<<(std::ostream &s, const listener &);
std::ostream &operator<<(std::ostream &s, const acceptor &);
2019-02-16 01:47:00 +01:00
extern conf::item<bool> listen;
2017-10-19 10:30:19 +02:00
}
struct ircd::net::listener
{
using callback = std::function<void (listener &, const std::shared_ptr<socket> &)>;
using proffer = std::function<bool (listener &, const ipport &)>;
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<net::acceptor> acceptor;
2017-10-19 10:30:19 +02:00
public:
operator const net::acceptor &() const;
operator net::acceptor &();
explicit operator json::object() const;
string_view name() const;
bool start();
listener(const string_view &name,
const json::object &options,
callback,
proffer = {});
explicit
listener(const string_view &name,
const std::string &options,
callback,
proffer = {});
2017-10-19 10:30:19 +02:00
~listener() noexcept;
friend std::ostream &operator<<(std::ostream &s, const listener &);
2017-10-19 10:30:19 +02:00
};