forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.h
More file actions
119 lines (93 loc) · 3.05 KB
/
Server.h
File metadata and controls
119 lines (93 loc) · 3.05 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include <cstddef>
#include <memory>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <csignal>
#include <atomic>
#include "SocketList.h"
#include "DataVariantAbstract.h"
#include "ServerApplicationsTree.h"
#include "ServerApplicationDefaultSettings.h"
#include "Module.h"
#include "Event.h"
namespace HttpServer
{
class Server
{
protected:
std::unordered_map<std::string, DataVariantAbstract *> variants;
std::unordered_map<std::string, std::string> settings;
std::unordered_map<std::string, std::string> mimes_types;
std::vector<Module> modules;
ServerApplicationsTree apps_tree;
std::vector<Socket> server_sockets;
Event *eventNotFullQueue;
Event *eventProcessQueue;
Event *eventUpdateModule;
Event *eventThreadCycle;
mutable std::atomic_size_t threads_working_count;
mutable std::mutex sockets_queue_mtx;
// Флаг, означающий - активированы ли главные циклы сервера
// (с помощью этого флага можно деактивировать циклы, чтобы завершить работу сервера)
sig_atomic_t process_flag;
sig_atomic_t restart_flag;
protected:
int cycleQueue(std::queue<Socket> &);
void sendStatus(const Socket &, const std::chrono::milliseconds &, const size_t) const;
int threadRequestProc(Socket) const;
void threadRequestCycle(std::queue<Socket> &) const;
int transferFilePart(const Socket &, const std::chrono::milliseconds &, const std::string &, const time_t, const size_t, const std::string &, const std::string &, const std::string &, const bool) const;
int transferFile(
const Socket &,
const std::chrono::milliseconds &,
const std::string &,
const std::unordered_map<std::string, std::string> &,
const std::unordered_map<std::string, std::string> &,
const std::string &,
const bool
) const;
bool parseIncomingVars(std::unordered_multimap<std::string, std::string> &, const std::string &) const;
bool init();
int run();
void clear();
System::native_processid_type getPidFromFile() const;
void updateModules();
bool updateModule(Module &, std::unordered_set<ServerApplicationSettings *> &, const size_t);
private:
void addDataVariant(DataVariantAbstract *);
public:
Server();
~Server() = default;
void stopProcess();
inline void unsetProcess()
{
this->process_flag = false;
}
inline void setRestart()
{
this->restart_flag = true;
}
inline void setUpdateModule()
{
if (this->eventUpdateModule)
{
this->eventUpdateModule->notify();
}
}
inline void setProcessQueue()
{
if (this->eventProcessQueue)
{
this->eventProcessQueue->notify();
}
}
int command_help(const int argc, const char *argv[]) const;
int command_start(const int argc, const char *argv[]);
int command_restart(const int argc, const char *argv[]) const;
int command_terminate(const int argc, const char *argv[]) const;
int command_update_module(const int argc, const char *argv[]) const;
};
};