OpenVPN 3 Core Library
Loading...
Searching...
No Matches
asiocontext.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#ifndef OPENVPN_ASIO_ASIOCONTEXT_H
13#define OPENVPN_ASIO_ASIOCONTEXT_H
14
15#include <vector>
16#include <memory>
17#include <mutex>
18
19#include <openvpn/io/io.hpp>
20
21namespace openvpn {
23{
24 public:
25 openvpn_io::io_context &new_context(int concurrency_hint)
26 {
27 openvpn_io::io_context *ioc = new openvpn_io::io_context(concurrency_hint);
28 {
29 std::lock_guard lock(mutex);
30 contexts.emplace_back(ioc);
31 }
32 return *ioc;
33 }
34
40 void stop()
41 {
42 std::lock_guard lock(mutex);
43
44 for (auto &context : contexts)
45 context->stop();
46 }
47
48 private:
49 std::mutex mutex;
50 std::vector<std::unique_ptr<openvpn_io::io_context>> contexts;
51};
52} // namespace openvpn
53
54#endif
openvpn_io::io_context & new_context(int concurrency_hint)
std::vector< std::unique_ptr< openvpn_io::io_context > > contexts