-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.h
More file actions
64 lines (57 loc) · 1.77 KB
/
Server.h
File metadata and controls
64 lines (57 loc) · 1.77 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2021 Ilya Entin
*/
#pragma once
#include <map>
#include <boost/core/noncopyable.hpp>
#include "Chronometer.h"
#include "ThreadPoolSessions.h"
namespace tcp {
using ConnectionPtr = std::shared_ptr<struct Connection>;
}
using ServerPtr = std::shared_ptr<class Server>;
using ServerWeakPtr = std::weak_ptr<Server>;
using SessionMap = std::map<std::size_t, RunnableWeakPtr>;
using SessionPtr = std::shared_ptr<class Session>;
using PolicyPtr = std::unique_ptr<class Policy>;
class Server : public std::enable_shared_from_this<Server>,
private boost::noncopyable {
public:
Server();
~Server();
bool start();
void stop();
void createFifoSession(std::string_view primarySignatureWithKey,
std::string_view primaryPubKeyAes,
std::string_view secondarySignatureWithKey,
std::string_view secondaryPubKeyAes);
void createTcpSession(tcp::ConnectionPtr connection,
std::string_view primarySignatureWithKey,
std::string_view primaryPubKeyAes,
std::string_view secondarySignatureWithKey,
std::string_view secondaryPubKeyAes);
const PolicyPtr& getPolicy() const { return _policy; }
static void removeNamedMutex();
private:
void setPolicy();
template <typename SESSION>
bool startSession(SESSION session) {
session->start();
std::size_t clientId = session->getId();
auto [it, inserted] = _sessions.emplace(clientId, session);
if (!inserted)
return false;
_threadPoolSession.calculateStatus(session);
_threadPoolSession.push(session);
return true;
}
void stopSessions();
Chronometer _chronometer;
SessionMap _sessions;
ThreadPoolBase _threadPoolAcceptor;
ThreadPoolSessions _threadPoolSession;
RunnablePtr _tcpAcceptor;
RunnablePtr _fifoAcceptor;
PolicyPtr _policy;
std::mutex _mutex;
};