1
2
3
4
5
6 #include <cmajor/build/ServerExecutionContext.hpp>
7
8 namespace cmajor { namespace build {
9
10 void RunContinuousSocketServer(SocketServer* socketServer)
11 {
12 try
13 {
14 socketServer->Run("type 'exit <ENTER>' to stop and exit server");
15 }
16 catch (const std::exception& ex;)
17 {
18 if (socketServer->GetLog())
19 {
20 socketServer->GetLog()->Write("RunContinuousSocketServer got exception '" + std::string(ex.what()) + "'", nullptr);
21 }
22 }
23 }
24
25 ServerExecutionContext::ServerExecutionContext(const std::string& serverName)
26 {
27 socketServer.reset(new SocketServer(GetLog(), serverName, true));
28 serverThread = std::thread({RunContinuousSocketServer, socketServer.get() });
29 socketServer->WaitForRunning();
30 }
31
32 ServerExecutionContext::~ServerExecutionContext()
33 {
34 try
35 {
36 serverThread.join();
37 }
38 catch (const std::exception&;)
39 {
40 }
41 }
42
43 void ServerExecutionContext::ExitServer()
44 {
45 return socketServer->ExitContinuous();
46 }
47
48 } }