46 DWORD status = ::WaitForSingleObject(
handle_.native_handle(), 0);
53 throw Exception(
"CancelableHandle: destroy event is already signaled");
55 throw Exception(
"CancelableHandle: destroy event is abandoned");
71 catch (
const openvpn_io::system_error &)
94 template <
typename Handler>
107 std::shared_ptr<bool>
is_closed_ = std::make_shared<bool>(
false);
Wrapper for an asynchronous handle supporting cancellation and closure.
void check_is_already_signalled()
Checks if the handle's event is already signaled.
void async_wait(Handler &&handler)
Initiates an asynchronous wait on the handle.
~CancelableHandle()
Destructor ensures handle cancellation and closure.
CancelableHandle(openvpn_io::io_context &io_context)
Constructs with the given I/O context.
openvpn_io::windows::object_handle handle_
Asynchronous Windows object handle.
std::shared_ptr< bool > is_closed_
Indicates if handle is closed.
void cancel_and_close()
Cancels and closes the handle if not already closed.
void assign(HANDLE handle)
Assigns a native Windows handle.
static void handler(int signum)
#define OPENVPN_THROW_EXCEPTION(stuff)