Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ console_bs_SOURCES = \
console/executor_store.cpp \
console/executor_test_reader.cpp \
console/executor_test_writer.cpp \
console/executor_windows.cpp \
console/executor_window.cpp \
console/localize.hpp \
console/main.cpp \
console/stack_trace.cpp \
Expand Down
3 changes: 1 addition & 2 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ if (with-console)
"../../console/executor_store.cpp"
"../../console/executor_test_reader.cpp"
"../../console/executor_test_writer.cpp"
"../../console/executor_windows.cpp"
"../../console/libbitcoin.ico"
"../../console/executor_window.cpp"
"../../console/localize.hpp"
"../../console/main.cpp"
"../../console/stack_trace.cpp"
Expand Down
2 changes: 1 addition & 1 deletion builds/msvc/vs2022/bs/bs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<ClCompile Include="..\..\..\..\console\executor_store.cpp" />
<ClCompile Include="..\..\..\..\console\executor_test_reader.cpp" />
<ClCompile Include="..\..\..\..\console\executor_test_writer.cpp" />
<ClCompile Include="..\..\..\..\console\executor_windows.cpp" />
<ClCompile Include="..\..\..\..\console\executor_window.cpp" />
<ClCompile Include="..\..\..\..\console\main.cpp" />
<ClCompile Include="..\..\..\..\console\stack_trace.cpp" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion builds/msvc/vs2022/bs/bs.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<ClCompile Include="..\..\..\..\console\executor_test_writer.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\console\executor_windows.cpp">
<ClCompile Include="..\..\..\..\console\executor_window.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\console\main.cpp">
Expand Down
29 changes: 29 additions & 0 deletions console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace libbitcoin {
namespace server {

using boost::format;
using namespace system;
using namespace std::placeholders;

// static initializers.
Expand Down Expand Up @@ -81,6 +82,34 @@ executor::~executor()
// ----------------------------------------------------------------------------
// static

#if defined(HAVE_MSC)
BOOL WINAPI executor::control_handler(DWORD signal)
{
switch (signal)
{
// Keyboard events. These prevent exit altogether when TRUE returned.
// handle_stop(signal) therefore shuts down gracefully/completely.
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:

// A signal that the system sends to all processes attached to a
// console when the user closes the console (by clicking Close on the
// console window's window menu). Returning TRUE here does not
// materially delay exit, so aside from capture this is a noop.
case CTRL_CLOSE_EVENT:
executor::handle_stop(possible_narrow_sign_cast<int>(signal));
return TRUE;

////// Only services receive this (*any* user is logging off).
////case CTRL_LOGOFF_EVENT:
////// Only services receive this (all users already logged off).
////case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
#endif

void executor::initialize_stop()
{
poll_for_stopping();
Expand Down
1 change: 1 addition & 0 deletions console/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class executor

HWND window_{};
std::thread thread_{};
std::promise<bool> ready_{};
#endif

// Executor.
Expand Down
32 changes: 4 additions & 28 deletions console/executor_windows.cpp → console/executor_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,10 @@ namespace server {
// TODO: use RegisterServiceCtrlHandlerEx for service registration.

using namespace system;

constexpr auto window_name = L"HiddenShutdownWindow";
constexpr auto window_text = L"Flushing tables...";
constexpr auto window_title = L"Libbitcoin Server";

// static
BOOL WINAPI executor::control_handler(DWORD signal)
{
switch (signal)
{
// Keyboard events. These prevent exit altogether when TRUE returned.
// handle_stop(signal) therefore shuts down gracefully/completely.
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:

// A signal that the system sends to all processes attached to a
// console when the user closes the console (by clicking Close on the
// console window's window menu). Returning TRUE here does not
// materially delay exit, so aside from capture this is a noop.
case CTRL_CLOSE_EVENT:
executor::handle_stop(possible_narrow_sign_cast<int>(signal));
return TRUE;

////// Only services receive this (*any* user is logging off).
////case CTRL_LOGOFF_EVENT:
////// Only services receive this (all users already logged off).
////case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}

// static
LRESULT CALLBACK executor::window_proc(HWND handle, UINT message,
WPARAM wparam, LPARAM lparam)
Expand Down Expand Up @@ -120,6 +92,7 @@ void executor::create_hidden_window()

MSG message{};
BOOL result{};
ready_.set_value(true);
while (!is_zero(result = ::GetMessageW(&message, NULL, 0, 0)))
{
// fault
Expand All @@ -134,6 +107,9 @@ void executor::create_hidden_window()

void executor::destroy_hidden_window()
{
// Wait until window is accepting messages, so WM_QUIT isn't missed.
ready_.get_future().wait();

if (!is_null(window_))
::PostMessageW(window_, WM_QUIT, 0, 0);

Expand Down
Loading