OpenVPN 3 Core Library
Loading...
Searching...
No Matches
asiotimersafe.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
#pragma once
13
14
#include <
openvpn/common/rc.hpp
>
15
#include <
openvpn/time/asiotimer.hpp
>
16
17
// AsioTimerSafe is like AsioTimer but with strict cancellation
18
// semantics that guarantees that a handler will never be called
19
// with a non-error status after the timer is cancelled.
20
21
namespace
openvpn
{
22
class
AsioTimerSafe
23
{
24
public
:
25
typedef
std::unique_ptr<AsioTimerSafe>
UPtr
;
26
27
AsioTimerSafe
(openvpn_io::io_context &io_context)
28
:
timer_
(io_context),
29
epoch_
(new
Epoch
)
30
{
31
}
32
33
std::size_t
expires_at
(
const
Time
&t)
34
{
35
inc_epoch
();
36
return
timer_
.
expires_at
(t);
37
}
38
39
std::size_t
expires_after
(
const
Time::Duration &d)
40
{
41
inc_epoch
();
42
return
timer_
.
expires_after
(d);
43
}
44
45
std::size_t
cancel
()
46
{
47
inc_epoch
();
48
return
timer_
.cancel();
49
}
50
51
template
<
typename
F>
52
void
async_wait
(F &&func)
53
{
54
inc_epoch
();
55
timer_
.async_wait([func = std::move(func),
epoch
=
epoch
(), eptr =
epoch_
](
const
openvpn_io::error_code &error)
56
{ func(
epoch
== eptr->epoch ? error : openvpn_io::error::operation_aborted); });
57
}
58
59
private
:
60
typedef
std::size_t
epoch_t
;
61
62
struct
Epoch
:
public
RC
<thread_unsafe_refcount>
63
{
64
typedef
RCPtr<Epoch>
Ptr
;
65
epoch_t
epoch
= 0;
66
};
67
68
epoch_t
epoch
()
const
69
{
70
return
epoch_
->
epoch
;
71
}
72
73
void
inc_epoch
()
74
{
75
++
epoch_
->
epoch
;
76
}
77
78
AsioTimer
timer_
;
79
Epoch::Ptr
epoch_
;
80
};
81
}
// namespace openvpn
asiotimer.hpp
openvpn::AsioTimerSafe
Definition
asiotimersafe.hpp:23
openvpn::AsioTimerSafe::epoch
epoch_t epoch() const
Definition
asiotimersafe.hpp:68
openvpn::AsioTimerSafe::expires_at
std::size_t expires_at(const Time &t)
Definition
asiotimersafe.hpp:33
openvpn::AsioTimerSafe::cancel
std::size_t cancel()
Definition
asiotimersafe.hpp:45
openvpn::AsioTimerSafe::timer_
AsioTimer timer_
Definition
asiotimersafe.hpp:78
openvpn::AsioTimerSafe::expires_after
std::size_t expires_after(const Time::Duration &d)
Definition
asiotimersafe.hpp:39
openvpn::AsioTimerSafe::epoch_t
std::size_t epoch_t
Definition
asiotimersafe.hpp:60
openvpn::AsioTimerSafe::UPtr
std::unique_ptr< AsioTimerSafe > UPtr
Definition
asiotimersafe.hpp:25
openvpn::AsioTimerSafe::epoch_
Epoch::Ptr epoch_
Definition
asiotimersafe.hpp:79
openvpn::AsioTimerSafe::async_wait
void async_wait(F &&func)
Definition
asiotimersafe.hpp:52
openvpn::AsioTimerSafe::inc_epoch
void inc_epoch()
Definition
asiotimersafe.hpp:73
openvpn::AsioTimerSafe::AsioTimerSafe
AsioTimerSafe(openvpn_io::io_context &io_context)
Definition
asiotimersafe.hpp:27
openvpn::AsioTimer
Definition
asiotimer.hpp:55
openvpn::AsioTimer::expires_at
std::size_t expires_at(const Time &t)
Definition
asiotimer.hpp:64
openvpn::AsioTimer::expires_after
std::size_t expires_after(const Time::Duration &d)
Definition
asiotimer.hpp:69
openvpn::RCPtr
The smart pointer class.
Definition
rc.hpp:119
openvpn::RC
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Definition
rc.hpp:912
openvpn::TimeType< oulong >
openvpn
Definition
ovpncli.cpp:97
rc.hpp
openvpn::AsioTimerSafe::Epoch
Definition
asiotimersafe.hpp:63
openvpn::AsioTimerSafe::Epoch::Ptr
RCPtr< Epoch > Ptr
Definition
asiotimersafe.hpp:64
openvpn::AsioTimerSafe::Epoch::epoch
epoch_t epoch
Definition
asiotimersafe.hpp:65
openvpn
time
asiotimersafe.hpp
Generated by
1.9.8