OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tunwrapasio.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_TUN_PERSIST_TUNWRAPASIO_H
13#define OPENVPN_TUN_PERSIST_TUNWRAPASIO_H
14
15#include <utility>
16
17namespace openvpn {
18
19// This object supports that subset of the Asio stream
20// interface required by TunIO, and is intended to wrap
21// a ScopedAsioStream embedded in a TunWrap object.
22// It is used primarily on Windows to wrap the TAP
23// interface HANDLE in way that plays well with Windows
24// I/O completion ports (once a HANDLE is bound to an
25// I/O completion port it cannot be unbound).
26template <typename TunWrap>
28{
29 public:
30 TunWrapAsioStream(const typename TunWrap::Ptr &tun_wrap_arg)
31 : tun_wrap(tun_wrap_arg)
32 {
33 }
34
35
36 void release()
37 {
38 tun_wrap.reset();
39 }
40
41 // Delegate STREAM methods (only need to support the
42 // subset of methods used by TunIO).
43 // Prototypes from asio/windows/basic_stream_handle.hpp
44
45 template <typename MUTABLE_BUFFER, typename HANDLER>
46 void async_read_some(const MUTABLE_BUFFER &buffers, HANDLER &&handler)
47 {
48 return tun_wrap->obj()->async_read_some(buffers, std::move(handler));
49 }
50
51 template <typename CONST_BUFFER>
52 std::size_t write_some(const CONST_BUFFER &buffers)
53 {
54 return tun_wrap->obj()->write_some(buffers);
55 }
56
57 void cancel()
58 {
59 tun_wrap->obj()->cancel();
60 }
61
62 void close()
63 {
64 tun_wrap->obj()->close();
65 }
66
67 private:
68 typename TunWrap::Ptr tun_wrap;
69};
70
71} // namespace openvpn
72#endif
void async_read_some(const MUTABLE_BUFFER &buffers, HANDLER &&handler)
TunWrapAsioStream(const typename TunWrap::Ptr &tun_wrap_arg)
std::size_t write_some(const CONST_BUFFER &buffers)
static void handler(int signum)
Definition cli.cpp:961