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
21
22namespace openvpn {
23
24// returns false if Stop signal prevented full wait
25inline 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);
38 milliseconds -= ms;
39 }
40
41 return !stop;
42}
43
44} // namespace openvpn
45
46#endif
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
bool async_sleep_milliseconds(int milliseconds, Stop *async_stop)
bool sleep_milliseconds(const unsigned int milliseconds)
Definition sleep.hpp:26