2015-11-06 01:11:49 +01:00
|
|
|
// OpenVPN -- An application to securely tunnel IP networks
|
|
|
|
// over a single port, with support for SSL/TLS-based
|
|
|
|
// session authentication and key exchange,
|
|
|
|
// packet encryption, packet authentication, and
|
|
|
|
// packet compression.
|
|
|
|
//
|
2017-03-18 20:11:09 +01:00
|
|
|
// Copyright (C) 2012-2017 OpenVPN Technologies, Inc.
|
2015-11-06 01:11:49 +01:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
2017-03-16 09:41:16 +01:00
|
|
|
// it under the terms of the GNU General Public License Version 3
|
2015-11-06 01:11:49 +01:00
|
|
|
// as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-03-16 09:41:16 +01:00
|
|
|
// GNU General Public License for more details.
|
2015-11-06 01:11:49 +01:00
|
|
|
//
|
2017-03-16 09:41:16 +01:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2015-11-06 01:11:49 +01:00
|
|
|
// along with this program in the COPYING file.
|
|
|
|
// If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// Portable millisecond sleep
|
|
|
|
|
|
|
|
#ifndef OPENVPN_COMMON_SLEEP_H
|
|
|
|
#define OPENVPN_COMMON_SLEEP_H
|
|
|
|
|
|
|
|
#include <openvpn/common/platform.hpp>
|
|
|
|
|
|
|
|
#ifdef OPENVPN_PLATFORM_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace openvpn {
|
2015-11-25 19:34:41 +01:00
|
|
|
inline bool sleep_milliseconds(const unsigned int milliseconds)
|
2015-11-06 01:11:49 +01:00
|
|
|
{
|
|
|
|
#ifdef OPENVPN_PLATFORM_WIN
|
|
|
|
::Sleep(milliseconds);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = milliseconds / 1000U;
|
|
|
|
ts.tv_nsec = (milliseconds % 1000U) * 1000000U;
|
|
|
|
return ::nanosleep(&ts, nullptr) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|