aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server/main/server.hpp
blob: 6233bff6d3f301243ce3f3ca746608741199daa3 (plain) (blame)
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
41
// Copyright (c) 2019 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "math-server" project.
// For details, see https://github.com/egor-tensin/math-server.
// Distributed under the MIT License.

#pragma once

#include "session_manager.hpp"
#include "settings.hpp"

#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>

#include <cstddef>

namespace math::server {

class Server {
public:
    Server(const Settings& settings);
    Server(unsigned short port, std::size_t threads);

    void run();

private:
    void wait_for_signal();
    void handle_signal(const boost::system::error_code&, int);

    void accept();
    void handle_accept(SessionPtr session, const boost::system::error_code& ec);

    const std::size_t m_numof_threads;

    boost::asio::io_context m_io_context;
    boost::asio::signal_set m_signals;
    boost::asio::ip::tcp::acceptor m_acceptor;

    SessionManager m_session_mgr;
};

}