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
#include <chrono>
19
#include <thread>
20
21
#include <
openvpn/common/stop.hpp
>
22
23
namespace
openvpn
{
24
25
// returns false if Stop signal prevented full wait
26
inline
bool
async_sleep_milliseconds
(
int
milliseconds,
Stop
*async_stop)
27
{
28
const
int
milliseconds_per_retry = 250;
29
volatile
bool
stop =
false
;
30
31
// allow asynchronous stop
32
Stop::Scope
stop_scope(async_stop, [&stop]()
33
{ stop =
true
; });
34
35
while
(milliseconds > 0 && !stop)
36
{
37
const
int
ms = std::min(milliseconds, milliseconds_per_retry);
38
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
39
milliseconds -= ms;
40
}
41
42
return
!stop;
43
}
44
45
}
// namespace openvpn
46
47
#endif
openvpn::Stop::Scope
Definition
stop.hpp:30
openvpn::Stop
Definition
stop.hpp:27
openvpn
Definition
ovpncli.cpp:97
openvpn::async_sleep_milliseconds
bool async_sleep_milliseconds(int milliseconds, Stop *async_stop)
Definition
asyncsleep.hpp:26
stop.hpp
openvpn
common
asyncsleep.hpp
Generated by
1.9.8