-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.h
42 lines (37 loc) · 1.07 KB
/
Server.h
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
42
/*
* Copyright (C) 2021 Ilya Entin
*/
#pragma once
#include <map>
#include "Chronometer.h"
#include "Connection.h"
#include "Crypto.h"
#include "ThreadPoolSessions.h"
class Server;
using ServerPtr = std::shared_ptr<Server>;
using ServerWeakPtr = std::weak_ptr<Server>;
using SessionMap = std::map<std::size_t, RunnableWeakPtr>;
using SessionPtr = std::shared_ptr<class Session>;
class Server : public std::enable_shared_from_this<Server> {
public:
explicit Server(class Policy& policy);
~Server();
bool start();
void stop();
void createFifoSession(const CryptoPP::SecByteBlock& pubB,
std::string_view rsaPubB);
void createTcpSession(tcp::ConnectionPtr connection,
const CryptoPP::SecByteBlock& pubB,
std::string_view rsaPubB);
static void removeNamedMutex();
private:
bool startSession(RunnablePtr runnable, SessionPtr session);
void stopSessions();
Chronometer _chronometer;
SessionMap _sessions;
ThreadPoolBase _threadPoolAcceptor;
ThreadPoolSessions _threadPoolSession;
RunnablePtr _tcpAcceptor;
RunnablePtr _fifoAcceptor;
std::mutex _mutex;
};