0

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();
2
Contributors
2
Replies
19
Views
1 Week
Discussion Span
Last Post by rproffitt
0

PS. I couldn't find "Mongoos" examples. Mongoose, yes, but that is not what you asked for.

In case you need a Windows Mongoose server example, read https://github.com/cesanta/mongoose Scroll down to "Study mongoose example code". However this won't be all you need to know about Windows and tight loops.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.