77 #include < thread>
88
99 static std::thread threadMessageLoop;
10- extern ::TCHAR myWndClassName[];
1110#endif
1211
1312#include < csignal>
1413
1514static HttpServer::Server *globalServerPtr = nullptr ;
1615
16+ /* *
17+ * Terminate signal
18+ */
1719static void handlerSigTerm (const int sig)
1820{
1921 if (globalServerPtr)
@@ -22,6 +24,9 @@ static void handlerSigTerm(const int sig)
2224 }
2325}
2426
27+ /* *
28+ * Interrupt signal
29+ */
2530static void handlerSigInt (const int sig)
2631{
2732 if (globalServerPtr)
@@ -30,6 +35,9 @@ static void handlerSigInt(const int sig)
3035 }
3136}
3237
38+ /* *
39+ * Signal to restart
40+ */
3341static void handlerSigUsr1 (const int sig)
3442{
3543 if (globalServerPtr)
@@ -39,6 +47,9 @@ static void handlerSigUsr1(const int sig)
3947 }
4048}
4149
50+ /* *
51+ * Signal to update modules
52+ */
4253static void handlerSigUsr2 (const int sig)
4354{
4455 if (globalServerPtr)
@@ -60,6 +71,7 @@ static ::LRESULT CALLBACK WndProc(const ::HWND hWnd, const ::UINT message, const
6071 switch (message)
6172 {
6273 case SIGTERM:
74+ case WM_CLOSE:
6375 {
6476 handlerSigTerm (message);
6577 ::PostMessage (hWnd, WM_QUIT, 0 , 0 ); // Fuck ::PostQuitMessage(0);
@@ -96,11 +108,11 @@ static ::LRESULT CALLBACK WndProc(const ::HWND hWnd, const ::UINT message, const
96108 return 0 ;
97109}
98110
99- static ::WPARAM mainMessageLoop (const ::HINSTANCE hInstance, HttpServer::Event *pCreatedWindow )
111+ static ::WPARAM mainMessageLoop (const ::HINSTANCE hInstance, HttpServer::Event * const eventWindowCreation )
100112{
101113 const ::HWND hWnd = ::CreateWindow (myWndClassName, nullptr , 0 , CW_USEDEFAULT, CW_USEDEFAULT, 0 , 0 , nullptr , nullptr , hInstance, nullptr );
102114
103- pCreatedWindow ->notify ();
115+ eventWindowCreation ->notify (); // After this action, eventWindowCreation will be destroyed (in the other thread)
104116
105117 if (0 == hWnd)
106118 {
@@ -166,11 +178,11 @@ bool bindSignalHandlers(HttpServer::Server *server)
166178 return false ;
167179 }
168180
169- HttpServer::Event createdWindow ;
181+ HttpServer::Event eventWindowCreation ;
170182
171- threadMessageLoop = std::thread (mainMessageLoop, hInstance, &createdWindow );
183+ threadMessageLoop = std::thread (mainMessageLoop, hInstance, &eventWindowCreation );
172184
173- createdWindow .wait ();
185+ eventWindowCreation .wait ();
174186
175187#elif POSIX
176188
0 commit comments