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 using Queue = std::deque<BufferPtr>;
45
46 public:
48 ReadHandler,
49 RAW_MODE_ONLY>;
51
53
54 friend Base;
55
56 TCPLink(ReadHandler read_handler_arg,
57 typename Protocol::socket &socket_arg,
58 const size_t send_queue_max_size_arg, // 0 to disable
59 const size_t free_list_max_size_arg,
60 const Frame::Context &frame_context_arg,
61 const SessionStats::Ptr &stats_arg)
62 : Base(read_handler_arg,
63 socket_arg,
64 send_queue_max_size_arg,
65 free_list_max_size_arg,
66 frame_context_arg,
67 stats_arg)
68 {
69 }
70
71 private:
72 // Called by LinkCommon
73 void from_app_send_buffer(BufferPtr &buf) override
74 {
76 }
77
78 void recv_buffer(PacketFrom::SPtr &pfp, const size_t bytes_recvd) override
79 {
80 bool requeue = true;
81 OPENVPN_LOG_TCPLINK_VERBOSE("TCP recv raw="
82 << Base::raw_mode_read << " size=" << bytes_recvd);
83
84 pfp->buf.set_size(bytes_recvd);
85 requeue = Base::process_recv_buffer(pfp->buf);
86 if (!Base::halt && requeue)
87 Base::queue_recv(pfp.release()); // reuse PacketFrom object
88 }
89};
90} // namespace openvpn::TCPTransport
91
92#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)