-
Notifications
You must be signed in to change notification settings - Fork 4
/
Processor.cpp
executable file
·57 lines (51 loc) · 1.8 KB
/
Processor.cpp
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
#include <boost/asio.hpp>
#include <boost/bind/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
#include <process.h>
#include <stdlib.h>
#include "Config.h"
#include "Loger.h"
#include "Processor.h"
#include "RequestHandlerProviderImp.h"
#include "RequestLoger.h"
#include "ServerApi.h"
#include "http_server/server.h"
#include "MT4ServerAPI.h"
Processor& Processor::Instance() {
static Processor _instance;
return _instance;
}
void Processor::Initialize() {
FUNC_WARDER;
// Init the http server settings
Config::Instance().GetString("Http.Server.port!reboot", m_server_port, sizeof(m_server_port) - 1, "8080");
Config::Instance().GetString("Max.Http.Threads!reboot", m_max_thread, sizeof(m_max_thread) - 1, "16");
LOG("Processor::Initialize %s, %s", m_server_port, m_max_thread);
m_thread = boost::thread(boost::bind(&Processor::StartServer, this, m_server_port, m_max_thread));
}
void Processor::Shutdown() {
if (m_http_server != NULL) {
m_http_server->stop();
}
m_thread.join();
}
void Processor::StartServer(const char* port, const char* num_threads) {
LOG("http server port: %s, threads: %s", port, num_threads);
try {
// Initialise the server.
RequestHandlerProviderImp provider;
// RequestLoger req_loger;
std::size_t number = boost::lexical_cast<std::size_t>(num_threads);
m_http_server = new http::server::server("0.0.0.0", port, number, &provider, nullptr);
// Run the server until stopped.
m_http_server->run();
} catch (std::exception& e) {
LOG("http server failed: %s", e.what());
}
if (m_http_server != 0) {
delete m_http_server;
m_http_server = NULL;
}
LOG("http server stops.");
}