I'm trying to setup mongoos server in a Winndows app.
The server code needs to be in an infinite loop, so does the windows main loop. I put the server code and win loop on 2 threads, the problem is, the program hangs when executed.
Is there a way to make this work
Main Windows loop
int mainLoop(MSG &messages) {
while (GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return 1;
}
Server loop
int serverLoop() {
struct mg_mgr mgr;
struct mg_connection *c;
static const char *s_http_port = "80";
mg_mgr_init(&mgr, NULL);
c = mg_bind(&mgr, s_http_port, ev_handler);
mg_set_protocol_http_websocket(c);
for (;;) {
mg_mgr_poll(&mgr, 1000);
}
mg_mgr_free(&mgr);
return 0;
}
Main
int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nCmdShow){
// ...
thread first(mainLoop,messages);
thread second(serverLoop);
first.join();
second.join();