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
20
#include <
openvpn/buffer/bufhex.hpp
>
21
#include <
openvpn/win/winerr.hpp
>
22
#include <
openvpn/win/scoped_handle.hpp
>
23
24
namespace
openvpn::Win
{
25
26
// Wrap a standard Windows Event object
27
class
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
57
void
signal_event
()
58
{
59
if
(
event
.
defined
())
60
{
61
::SetEvent(
event
());
62
event
.close();
63
}
64
}
65
66
void
release_event
()
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
:
82
ScopedHANDLE
event
;
83
};
84
85
// Windows event object that automatically signals in the destructor
86
struct
DestroyEvent
:
public
Event
87
{
88
~DestroyEvent
()
89
{
90
signal_event
();
91
}
92
};
93
94
}
// namespace openvpn::Win
95
96
#endif
bufhex.hpp
openvpn::Win::Event
Definition
event.hpp:28
openvpn::Win::Event::release_event
void release_event()
Definition
event.hpp:66
openvpn::Win::Event::duplicate_local
std::string duplicate_local()
Definition
event.hpp:40
openvpn::Win::Event::Event
Event(BOOL manual_reset=TRUE)
Definition
event.hpp:30
openvpn::Win::Event::event
ScopedHANDLE event
Definition
event.hpp:82
openvpn::Win::Event::reset
void reset(HANDLE h)
Definition
event.hpp:76
openvpn::Win::Event::operator()
HANDLE operator()() const
Definition
event.hpp:71
openvpn::Win::Event::signal_event
void signal_event()
Definition
event.hpp:57
openvpn::Win::ScopedHANDLE
Definition
scoped_handle.hpp:24
openvpn::Win::ScopedHANDLE::defined
bool defined() const
Definition
scoped_handle.hpp:48
OPENVPN_THROW_EXCEPTION
#define OPENVPN_THROW_EXCEPTION(stuff)
Definition
exception.hpp:166
openvpn::BufHex::render
std::string render(const T obj)
Definition
bufhex.hpp:24
openvpn::Win
Definition
call.hpp:27
scoped_handle.hpp
openvpn::Win::DestroyEvent
Definition
event.hpp:87
openvpn::Win::DestroyEvent::~DestroyEvent
~DestroyEvent()
Definition
event.hpp:88
openvpn::Win::LastError
Definition
winerr.hpp:31
winerr.hpp
openvpn
win
event.hpp
Generated by
1.9.8