OpenVPN 3 Core Library
Loading...
Searching...
No Matches
asyncsleep.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
// Interruptible sleep
13
14
#ifndef OPENVPN_COMMON_ASYNCSLEEP_H
15
#define OPENVPN_COMMON_ASYNCSLEEP_H
16
17
#include <algorithm>
18
19
#include <
openvpn/common/stop.hpp
>
20
#include <
openvpn/common/sleep.hpp
>
21
22
namespace
openvpn
{
23
24
// returns false if Stop signal prevented full wait
25
inline
bool
async_sleep_milliseconds
(
int
milliseconds,
Stop
*async_stop)
26
{
27
const
int
milliseconds_per_retry = 250;
28
volatile
bool
stop =
false
;
29
30
// allow asynchronous stop
31
Stop::Scope
stop_scope(async_stop, [&stop]()
32
{ stop =
true
; });
33
34
while
(milliseconds > 0 && !stop)
35
{
36
const
int
ms = std::min(milliseconds, milliseconds_per_retry);
37
sleep_milliseconds
(ms);
38
milliseconds -= ms;
39
}
40
41
return
!stop;
42
}
43
44
}
// namespace openvpn
45
46
#endif
openvpn::Stop::Scope
Definition
stop.hpp:30
openvpn::Stop
Definition
stop.hpp:27
sleep.hpp
openvpn
Support deferred server-side state creation when client connects.
Definition
ovpncli.cpp:95
openvpn::async_sleep_milliseconds
bool async_sleep_milliseconds(int milliseconds, Stop *async_stop)
Definition
asyncsleep.hpp:25
openvpn::sleep_milliseconds
bool sleep_milliseconds(const unsigned int milliseconds)
Definition
sleep.hpp:26
stop.hpp
openvpn
common
asyncsleep.hpp
Generated by
1.9.8