OpenVPN 3 Core Library
Loading...
Searching...
No Matches
timespec.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#pragma once
13
14#include <time.h>
15#include <cstdint> // for std::uint64_t
16
17namespace openvpn {
18
19typedef std::uint64_t nanotime_t;
20
21namespace TimeSpec {
22
23inline std::uint64_t milliseconds_since_epoch(const struct timespec &ts)
24{
25 return std::uint64_t(ts.tv_sec) * std::uint64_t(1000)
26 + std::uint64_t(ts.tv_nsec) / std::uint64_t(1000000);
27}
28
29inline nanotime_t nanoseconds_since_epoch(const struct timespec &ts)
30{
31 return std::uint64_t(ts.tv_sec) * std::uint64_t(1000000000)
32 + std::uint64_t(ts.tv_nsec);
33}
34
35} // namespace TimeSpec
36} // namespace openvpn
std::uint64_t milliseconds_since_epoch()
Definition epoch.hpp:22
std::uint64_t nanotime_t
Definition epoch.hpp:20
nanotime_t nanoseconds_since_epoch()
Definition epoch.hpp:30