-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (50 loc) · 1.87 KB
/
main.cpp
File metadata and controls
67 lines (50 loc) · 1.87 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
#include "include/config_commands.h"
#include "include/main_application.h"
#include "include/ssl_manager.h"
#include "server/include/config_manager.h"
#include "server/include/log.h"
#include "server/include/router.h"
#include <csignal>
#include <filesystem>
#include <iostream>
#include <string>
using namespace server;
int main(int argc, char *argv[]) {
try {
LOG_INFO << "Size of Socket: " << sizeof(Socket) << " bytes";
LOG_INFO("Server starting up");
LOG_INFO("Process ID: " + std::to_string(getpid()));
std::filesystem::path projectRoot = std::filesystem::current_path();
std::filesystem::path configPath = projectRoot / "conf" / "config";
LOG_INFO("Project root: " + projectRoot.string());
MainApplication::createAutoConfig(projectRoot);
LOG_TRACE("Initializing Router MIME types");
server::Router::initializeMime();
EventLoop mainLoop;
auto mainApplication = std::make_shared<MainApplication>();
mainApplication->initSignalHandlers(&mainLoop);
ConfigManager &configManager = ConfigManager::getInstance();
configManager.registerCommands(getAllCommands());
server::ConfigManager::setServerCallback([mainApplication](const ServerConfig &conf) {
mainApplication->addServer(conf);
});
std::string context = MainApplication::loadConfig(configPath);
configManager.configParse(context.c_str(), context.length());
int ret = mainApplication->handleParam(argc, argv);
if (ret != 2) {
return ret;
}
if (!ConfigManager::isCanRun()) {
LOG_INFO("Server is not ready yet, exiting...");
return 0;
}
mainApplication->startAllServers();
mainLoop.loop();
mainApplication->stopAll();
return 0;
} catch (const std::exception &e) {
LOG_FATAL("Fatal error occurred: " + std::string(e.what()));
std::cerr << "Fatal error: " << e.what() << '\n';
return 1;
}
}