@@ -26,38 +26,10 @@ namespace server {
2626// TODO: use RegisterServiceCtrlHandlerEx for service registration.
2727
2828using namespace system ;
29-
3029constexpr auto window_name = L" HiddenShutdownWindow" ;
3130constexpr auto window_text = L" Flushing tables..." ;
3231constexpr auto window_title = L" Libbitcoin Server" ;
3332
34- // static
35- BOOL WINAPI executor::control_handler (DWORD signal)
36- {
37- switch (signal)
38- {
39- // Keyboard events. These prevent exit altogether when TRUE returned.
40- // handle_stop(signal) therefore shuts down gracefully/completely.
41- case CTRL_C_EVENT:
42- case CTRL_BREAK_EVENT:
43-
44- // A signal that the system sends to all processes attached to a
45- // console when the user closes the console (by clicking Close on the
46- // console window's window menu). Returning TRUE here does not
47- // materially delay exit, so aside from capture this is a noop.
48- case CTRL_CLOSE_EVENT:
49- executor::handle_stop (possible_narrow_sign_cast<int >(signal));
50- return TRUE ;
51-
52- // //// Only services receive this (*any* user is logging off).
53- // //case CTRL_LOGOFF_EVENT:
54- // //// Only services receive this (all users already logged off).
55- // //case CTRL_SHUTDOWN_EVENT:
56- default :
57- return FALSE ;
58- }
59- }
60-
6133// static
6234LRESULT CALLBACK executor::window_proc (HWND handle, UINT message,
6335 WPARAM wparam, LPARAM lparam)
@@ -120,6 +92,7 @@ void executor::create_hidden_window()
12092
12193 MSG message{};
12294 BOOL result{};
95+ ready_.set_value (true );
12396 while (!is_zero (result = ::GetMessageW (&message, NULL , 0 , 0 )))
12497 {
12598 // fault
@@ -134,6 +107,9 @@ void executor::create_hidden_window()
134107
135108void executor::destroy_hidden_window ()
136109{
110+ // Wait until window is accepting messages, so WM_QUIT isn't missed.
111+ ready_.get_future ().wait ();
112+
137113 if (!is_null (window_))
138114 ::PostMessageW (window_, WM_QUIT, 0 , 0 );
139115
0 commit comments