OpenVPN 3 Core Library
Loading...
Searching...
No Matches
initprocess.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// Process-wide static initialization
13
14#pragma once
15
16#include <thread>
17#include <mutex>
18
21#include <openvpn/time/time.hpp>
25
26namespace openvpn::InitProcess {
27class Init
28{
29 private:
31 {
32 public:
34 {
35 // initialize time base
37
38 // initialize compression
40
41 // init OpenSSL if included
42 init_openssl("auto");
43
45 }
46
51
52 private:
53 // SSL library init happens when instantiated
55 };
56
57 // process-wide singular instance
58 inline static std::weak_ptr<InitImpl> init_instance; // GLOBAL
59 inline static std::mutex the_instance_mutex; // GLOBAL
60
61 // istance of this class to refcount
62 std::shared_ptr<InitImpl> initptr;
63
64 public:
66 {
67 std::lock_guard<std::mutex> lock(the_instance_mutex);
68
69 initptr = init_instance.lock();
70 if (!initptr)
71 {
72 initptr = std::make_shared<InitImpl>();
74 }
75 }
76
78 {
79 // explicitly reset smart pointer to make the destructor run under the lock_guard
80 std::lock_guard<std::mutex> lock(the_instance_mutex);
81 initptr.reset();
82 }
83};
84
85} // namespace openvpn::InitProcess
static void init_static()
Definition compress.hpp:523
static std::weak_ptr< InitImpl > init_instance
static std::mutex the_instance_mutex
std::shared_ptr< InitImpl > initptr
static void reset_base()
Definition time.hpp:425
void init_openssl(const std::string &engine)
void base64_uninit_static()
Definition base64.hpp:310
void base64_init_static()
Definition base64.hpp:302