OpenVPN 3 Core Library
Loading...
Searching...
No Matches
link.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_COMMON_LINK_H
13#define OPENVPN_COMMON_LINK_H
14
15#include <utility>
16
17namespace openvpn {
18
19// Link creates a sender-receiver relationship between two objects.
20// SEND is the sender interface, while RECV is the receiver interface.
21// The receiver class should publicly inherit from Link and implement
22// the receiver interface.
23// Multiple inheritance of Link is intended for objects that play a
24// receiver role for multiple interfaces (such as the server-side
25// client instance object), and for this reason RECV common base
26// classes such as RC should be virtually inherited.
27// Usage of Link may create a memory reference cycle between
28// Link-derived objects and the SEND object. Therefore be sure
29// to manually break cycles as part of an explicit stop() method.
30template <typename SEND, typename RECV>
31class Link : public RECV
32{
33 protected:
34 Link() = default;
35
36 Link(typename SEND::Ptr send_arg)
37 : send(std::move(send_arg))
38 {
39 }
40
41 Link(SEND *send_arg)
42 : send(send_arg)
43 {
44 static_assert(std::is_base_of_v<RC<thread_unsafe_refcount>, SEND> || std::is_base_of_v<RC<thread_safe_refcount>, SEND>,
45 "Using a raw pointer to initialise Link requires an intrusive pointer");
46 }
47
48 typename SEND::Ptr send;
49};
50
51} // namespace openvpn
52
53#endif