-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (55 loc) · 1.99 KB
/
main.cpp
File metadata and controls
60 lines (55 loc) · 1.99 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
#include <iostream>
#include <unordered_map>
#include <thread>
#include "SyncedFileServer.h"
#include "User.h"
#include "exceptions/socketException.h"
#include "exceptions/dataException.h"
#include "exceptions/filesystemException.h"
#include "Server.h"
#include <filesystem>
#include <fstream>
#include <boost/property_tree/exceptions.hpp>
#include <boost/property_tree/json_parser/error.hpp>
#include <shared_mutex>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
#include <boost/asio.hpp>
namespace pt = boost::property_tree;
using boost::asio::ip::tcp;
using boost::asio::deadline_timer;
int main() {
std::string crt, key, dhTemp, crtPsw;
int max_threads, port;
try {
pt::ptree root;
pt::read_json("config.json", root);
max_threads = std::stoi(root.get_child("max_threads").data());
port = std::stoi(root.get_child("port").data());
crt = root.get_child("cert_path").data();
key = root.get_child("cert_key").data();
dhTemp = root.get_child("dh_pem").data();
crtPsw = root.get_child("cert_password").data();
if(port<0 || max_threads<0)
throw std::runtime_error("Port o max_threads non possono essere minori di 0");
} catch (std::runtime_error &error) {
std::cerr << "Errore caricamento file configurazione" << std::endl;
std::cerr << error.what() << std::endl;
exit(-1);
}
if(std::filesystem::is_directory("./temp"))
std::filesystem::remove_all("./temp");
boost::asio::io_service io_service;
Server server(io_service, port, crt, key, crtPsw, dhTemp);
std::cout << "Il server si sta avviando sulla porta: " << port << std::endl;
server.do_accept();
std::vector<std::thread> threads;
threads.reserve(max_threads-1);
for(int i=0; i<max_threads-1; i++)
threads.emplace_back(std::thread(
[&io_service](){
io_service.run();
}));
io_service.run();
}