-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.cpp
35 lines (28 loc) · 1.18 KB
/
server.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
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <thread>
#include <mutex>
#include <mongocxx/instance.hpp>
#include "src/server/lib/Connection/Connection.h"
#include "src/server/lib/CompanyServer/Server/Server.h"
#include "src/server/lib/CompanyServer/Server/WorkerThread.h"
int main(int argc, char *argv[]) {
try
{
mongocxx::instance instance{};
std::shared_ptr<boost::asio::io_service> io_service(new boost::asio::io_service);
boost::shared_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(*io_service));
boost::shared_ptr<boost::asio::io_service::strand> strand(new boost::asio::io_service::strand(*io_service));
tcp::endpoint endpoint(tcp::v4(), 5556);
Server server = Server(*io_service, *strand, endpoint);
boost::thread_group workers;
for (int i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); ++i) {
auto *t = new boost::thread{ [io_service] { return WorkerThread::run(io_service); } };
workers.add_thread(t);
}
workers.join_all();
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}