-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.hpp
40 lines (32 loc) · 981 Bytes
/
listener.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/vinniefalco/CppCon2018
//
#ifndef CPPCON2018_LISTENER_HPP
#define CPPCON2018_LISTENER_HPP
#include "net.hpp"
#include <memory>
#include <string>
// Forward declaration
class shared_state;
// Accepts incoming connections and launches the sessions
class listener : public std::enable_shared_from_this<listener>
{
tcp::acceptor acceptor_;
tcp::socket socket_;
std::shared_ptr<shared_state> state_;
void fail(error_code ec, char const* what);
void on_accept(error_code ec);
public:
listener(
net::io_context& ioc,
tcp::endpoint endpoint,
std::shared_ptr<shared_state> const& state);
// Start accepting incoming connections
void run();
};
#endif