I am working on a boost.asio based HTTP server. It is supposed to be stopped externally. We use asio signal handling, and it works well for ctrl-c, but does not handle WM_CLOSE, so there is no straightforward way to gracefully close the application externally, e.g. via taskkill. Terminating the process forcibly is not an option. Is there a known approach to this?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Update
Just use any IPC method you would "normally" use
Write a simple process control utility that uses e.g.
named_condition
to signal your asio process to shutdown.Note that
named_codition
is somewhat equivalent to a Win32 Named Event in case you think that simpler for this inherently platform specific piece of codeConsider making a Windows Service (NTService), as it looks like this is what you want
AllocConsole
orCreateWindow
could help. However, you end up with more platform specific stuffOriginal answer, dealing with how to listen for console close events:
This is really not related to using Boost Asio. Of course, on POSIX platforms you could use
boost::asio::signal_set
to handle the SIG_INT and SIG_TERM signals.However, you're on windows, and there is no portable way to detect console close event.
You should write a console handler routine that detects CTRL_CLOSE_EVENT (and CTRL_C_EVENT, if desired), and use SetConsoleCtrlHandler to add the handler routine to your process.
To coordinate with Boost Asio, you could have the handler stop the (global) io_service object and perhaps set some flag for running actions. Finally, you may have to cancel any async operations in flight (e.g.
deadline_timer
s).Once you did that, it should be pretty clean.