7#ifndef OPENVPN_TRANSPORT_COMMONLINK_H
8#define OPENVPN_TRANSPORT_COMMONLINK_H
30#if defined(OPENVPN_DEBUG_TCPLINK) && OPENVPN_DEBUG_TCPLINK >= 1
31#define OPENVPN_LOG_TCPLINK_ERROR(x) OPENVPN_LOG(x)
33#define OPENVPN_LOG_TCPLINK_ERROR(x)
36#if defined(OPENVPN_DEBUG_TCPLINK) && OPENVPN_DEBUG_TCPLINK >= 3
37#define OPENVPN_LOG_TCPLINK_VERBOSE(x) OPENVPN_LOG(x)
39#define OPENVPN_LOG_TCPLINK_VERBOSE(x)
44template <
typename Protocol,
49 typedef std::deque<BufferPtr>
Queue;
95 const size_t size = src.
size();
97 if (size && !RAW_MODE_ONLY)
116#ifdef OPENVPN_GREMLIN
130#ifdef OPENVPN_GREMLIN
131 + (gremlin ? gremlin->send_size() : 0)
169#ifdef OPENVPN_GREMLIN
172 gremlin_queue_send_buffer(buf);
190 [self =
Ptr(
this), tcpfrom =
PacketFrom::SPtr(tcpfrom)](
const openvpn_io::error_code &error,
const size_t bytes_recvd)
mutable
195 self->handle_recv(std::move(tcpfrom), error, bytes_recvd);
197 catch (
const std::exception &e)
200 const char *
msg =
"TCP_SIZE_ERROR";
213 self->stats->error(err);
214 self->read_handler->tcp_error_handler(
msg);
222 typename Protocol::socket &socket_arg,
223 const size_t send_queue_max_size_arg,
224 const size_t free_list_max_size_arg,
237#ifdef OPENVPN_GREMLIN
273 queue.push_back(std::move(buf));
274 if (
queue.size() == 1)
282 [self =
Ptr(
this)](
const openvpn_io::error_code &error,
const size_t bytes_sent)
285 self->handle_send(error, bytes_sent);
289 void handle_send(
const openvpn_io::error_code &error,
const size_t bytes_sent)
300 if (bytes_sent == buf->size())
305 buf->reset_content();
309 else if (bytes_sent < buf->size())
310 buf->advance(bytes_sent);
349 catch ([[maybe_unused]]
const std::exception &e)
364#ifdef OPENVPN_GREMLIN
367 requeue = gremlin_recv(buf);
387 else if (error == openvpn_io::error::eof)
415#ifdef OPENVPN_GREMLIN
417 requeue = gremlin_recv(pkt);
426#ifdef OPENVPN_GREMLIN
427 void gremlin_queue_send_buffer(
BufferPtr &buf)
429 gremlin->send_queue([self =
Ptr(
this), buf = std::move(buf)]()
mutable
433 self->queue_send_buffer(buf);
439 gremlin->recv_queue([self =
Ptr(
this), buf = std::move(buf)]()
mutable
443 const bool requeue = self->read_handler->tcp_read_handler(buf);
445 self->queue_recv(nullptr);
470#ifdef OPENVPN_GREMLIN
471 std::unique_ptr<Gremlin::SendRecvQueue> gremlin;
#define OPENVPN_ASYNC_HANDLER
void move(BufferAllocatedType< T_ > &other)
Moves the contents of another BufferAllocatedType object into this object.
const T * c_data() const
Returns a const pointer to the start of the buffer.
T front() const
Returns the first element of the buffer.
bool allocated() const
Returns true if the data memory is defined (allocated).
size_t size() const
Returns the size of the buffer in T objects.
openvpn_io::const_buffer const_buffer_clamp() const
Return a clamped version of const_buffer().
void write(const T *data, const size_t size)
Write data to the buffer.
bool code_defined() const
openvpn_io::mutable_buffer mutable_buffer_clamp(Buffer &buf) const
size_t prepare(Buffer &buf) const
void reset_align_adjust(const size_t align_adjust)
static void prepend_size(Buffer &buf)
void get(BufferAllocated &ret)
void put(BufferAllocated &buf, const Frame::Context &frame_context)
static Ptr Create(ArgsT &&...args)
Creates a new instance of RcEnable with the given arguments.
virtual void error(const size_t type, const std::string *text=nullptr)
void inc_stat(const size_t type, const count_t value)
bool is_raw_mode_write() const
RCPtr< LinkCommon< Protocol, ReadHandler, RAW_MODE_ONLY > > Ptr
TransportMutateStream::Ptr mutate
virtual void recv_buffer(PacketFrom::SPtr &pfp, const size_t bytes_recvd)=0
void reset_align_adjust(const size_t align_adjust)
const size_t send_queue_max_size
void queue_recv(PacketFrom *tcpfrom)
PacketStream< std::uint16_t > OpenVPNPacketStream
size_t send_queue_size() const
void set_raw_mode_write(const bool mode)
const size_t free_list_max_size
void handle_recv(PacketFrom::SPtr pfp, const openvpn_io::error_code &error, const size_t bytes_recvd)
LinkCommon(ReadHandler read_handler_arg, typename Protocol::socket &socket_arg, const size_t send_queue_max_size_arg, const size_t free_list_max_size_arg, const Frame::Context &frame_context_arg, const SessionStats::Ptr &stats_arg)
std::deque< BufferPtr > Queue
Protocol::socket & socket
void tcp_write_queue_needs_send()
void set_raw_mode_read(const bool mode)
void inject(const Buffer &src)
Frame::Context frame_context
bool send(BufferAllocated &b)
void set_mutate(const TransportMutateStream::Ptr &mutate_arg)
virtual void from_app_send_buffer(BufferPtr &buf)=0
void set_raw_mode(const bool mode)
OpenVPNPacketStream pktstream
bool is_raw_mode_read() const
bool put_pktstream(BufferAllocated &buf, BufferAllocated &pkt)
void handle_send(const openvpn_io::error_code &error, const size_t bytes_sent)
bool send_queue_empty() const
bool process_recv_buffer(BufferAllocated &buf)
void queue_send_buffer(BufferPtr &buf)
virtual void post_recv(BufferAllocated &buf)=0
virtual void pre_send(BufferAllocated &buf)=0
BufferAllocatedType< unsigned char > BufferAllocated
std::unique_ptr< PacketFrom > SPtr
#define OPENVPN_LOG_TCPLINK_VERBOSE(x)
#define OPENVPN_LOG_TCPLINK_ERROR(x)
static const char config[]