OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tcplink.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// Low-level TCP transport object.
13
14#ifndef OPENVPN_TRANSPORT_TCPLINK_H
15#define OPENVPN_TRANSPORT_TCPLINK_H
16
17#include <deque>
18#include <utility> // for std::move
19#include <memory>
20
21#include <openvpn/io/io.hpp>
22
25#include <openvpn/common/rc.hpp>
32
33#ifdef OPENVPN_GREMLIN
35#endif
36
37namespace openvpn::TCPTransport {
38
39template <typename Protocol, typename ReadHandler, bool RAW_MODE_ONLY>
40class TCPLink : public LinkCommon<Protocol,
41 ReadHandler,
42 RAW_MODE_ONLY>
43{
44 typedef std::deque<BufferPtr> Queue;
45
46 public:
47 typedef LinkCommon<Protocol,
48 ReadHandler,
49 RAW_MODE_ONLY>
52
54
55 friend Base;
56
57 TCPLink(ReadHandler read_handler_arg,
58 typename Protocol::socket &socket_arg,
59 const size_t send_queue_max_size_arg, // 0 to disable
60 const size_t free_list_max_size_arg,
61 const Frame::Context &frame_context_arg,
62 const SessionStats::Ptr &stats_arg)
63 : Base(read_handler_arg,
64 socket_arg,
65 send_queue_max_size_arg,
66 free_list_max_size_arg,
67 frame_context_arg,
68 stats_arg)
69 {
70 }
71
72 private:
73 // Called by LinkCommon
74 virtual void from_app_send_buffer(BufferPtr &buf) override
75 {
77 }
78
79 virtual void recv_buffer(PacketFrom::SPtr &pfp, const size_t bytes_recvd) override
80 {
81 bool requeue = true;
82 OPENVPN_LOG_TCPLINK_VERBOSE("TCP recv raw="
83 << Base::raw_mode_read << " size=" << bytes_recvd);
84
85 pfp->buf.set_size(bytes_recvd);
86 requeue = Base::process_recv_buffer(pfp->buf);
87 if (!Base::halt && requeue)
88 Base::queue_recv(pfp.release()); // reuse PacketFrom object
89 }
90};
91} // namespace openvpn::TCPTransport
92
93#endif
The smart pointer class.
Definition rc.hpp:119
void queue_recv(PacketFrom *tcpfrom)
bool process_recv_buffer(BufferAllocated &buf)
void queue_send_buffer(BufferPtr &buf)
std::unique_ptr< PacketFrom > SPtr
#define OPENVPN_LOG_TCPLINK_VERBOSE(x)