OpenVPN 3 Core Library
Loading...
Searching...
No Matches
sleep.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// Portable millisecond sleep
13
14#ifndef OPENVPN_COMMON_SLEEP_H
15#define OPENVPN_COMMON_SLEEP_H
16
18
19#ifdef OPENVPN_PLATFORM_WIN
20#include <windows.h>
21#else
22#include <time.h>
23#endif
24
25namespace openvpn {
26inline bool sleep_milliseconds(const unsigned int milliseconds)
27{
28#ifdef OPENVPN_PLATFORM_WIN
29 ::Sleep(milliseconds);
30 return true;
31#else
32 struct timespec ts;
33 ts.tv_sec = milliseconds / 1000U;
34 ts.tv_nsec = (milliseconds % 1000U) * 1000000U;
35 return ::nanosleep(&ts, nullptr) == 0;
36#endif
37}
38} // namespace openvpn
39
40#endif
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
bool sleep_milliseconds(const unsigned int milliseconds)
Definition sleep.hpp:26