OpenVPN 3 Core Library
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11//
12
13#ifndef OPENVPN_WIN_EVENT_H
14#define OPENVPN_WIN_EVENT_H
15
16#include <windows.h>
17
18#include <string>
19
23
24namespace openvpn::Win {
25
26// Wrap a standard Windows Event object
27class Event
28{
29 public:
30 explicit Event(BOOL manual_reset = TRUE)
31 {
32 event.reset(::CreateEvent(NULL, manual_reset, FALSE, NULL));
33 if (!event.defined())
34 {
35 const Win::LastError err;
36 OPENVPN_THROW_EXCEPTION("Win::Event: cannot create Windows event: " << err.message());
37 }
38 }
39
40 std::string duplicate_local()
41 {
42 HANDLE new_handle;
43 if (!::DuplicateHandle(GetCurrentProcess(),
44 event(),
45 GetCurrentProcess(),
46 &new_handle,
47 0,
48 FALSE,
49 DUPLICATE_SAME_ACCESS))
50 {
51 const Win::LastError err;
52 OPENVPN_THROW_EXCEPTION("Win::Event: DuplicateHandle failed: " << err.message());
53 }
54 return BufHex::render(new_handle);
55 }
56
58 {
59 if (event.defined())
60 {
61 ::SetEvent(event());
62 event.close();
63 }
64 }
65
67 {
68 event.close();
69 }
70
71 HANDLE operator()() const
72 {
73 return event();
74 }
75
76 void reset(HANDLE h)
77 {
78 event.reset(h);
79 }
80
81 private:
83};
84
85// Windows event object that automatically signals in the destructor
86struct DestroyEvent : public Event
87{
89 {
91 }
92};
93
94} // namespace openvpn::Win
95
96#endif
void release_event()
Definition event.hpp:66
std::string duplicate_local()
Definition event.hpp:40
Event(BOOL manual_reset=TRUE)
Definition event.hpp:30
ScopedHANDLE event
Definition event.hpp:82
void reset(HANDLE h)
Definition event.hpp:76
HANDLE operator()() const
Definition event.hpp:71
void signal_event()
Definition event.hpp:57
#define OPENVPN_THROW_EXCEPTION(stuff)
std::string render(const T obj)
Definition bufhex.hpp:24