OpenVPN 3 Core Library
Loading...
Searching...
No Matches
memq.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
// A queue of buffers, implemented as std::deque<BufferPtr>.
13
14
#ifndef OPENVPN_BUFFER_MEMQ_H
15
#define OPENVPN_BUFFER_MEMQ_H
16
17
#include <deque>
18
19
#include <
openvpn/common/size.hpp
>
20
#include <
openvpn/buffer/buffer.hpp
>
21
22
namespace
openvpn
{
23
24
class
MemQBase
25
{
26
public
:
27
MemQBase
()
28
:
length
(0)
29
{
30
}
31
32
size_t
size
()
const
33
{
34
return
q
.size();
35
}
36
37
bool
empty
()
const
38
{
39
return
q
.empty();
40
}
41
42
size_t
total_length
()
const
43
{
44
return
length
;
45
}
46
47
void
clear
()
48
{
49
while
(!
q
.empty())
50
q
.pop_back();
51
length
= 0;
52
}
53
54
void
write_buf
(
const
BufferPtr
&bp)
55
{
56
// An empty buffer has nothing to queue but would still make empty() lie, since that
57
// answers for the queue and not for what is in it: the queue would look ready while
58
// reading it yields nothing, and a reader with no bytes and no reason to wait takes
59
// that for the end of the stream.
60
if
(bp->empty())
61
return
;
62
63
q
.push_back(bp);
64
length
+= bp->size();
65
}
66
67
BufferPtr
read_buf
()
68
{
69
BufferPtr
ret =
q
.front();
70
q
.pop_front();
71
length
-= ret->size();
72
return
ret;
73
}
74
75
BufferPtr
&
peek
()
76
{
77
return
q
.front();
78
}
79
80
void
pop
()
81
{
82
length
-=
q
.front()->size();
83
q
.pop_front();
84
}
85
86
void
resize
(
const
size_t
cap)
87
{
88
q
.resize(cap);
89
}
90
91
protected
:
92
using
q_type
= std::deque<BufferPtr>;
93
size_t
length
;
94
q_type
q
;
95
};
96
97
}
// namespace openvpn
98
99
#endif
// OPENVPN_BUFFER_MEMQ_H
buffer.hpp
openvpn::MemQBase
Definition
memq.hpp:25
openvpn::MemQBase::pop
void pop()
Definition
memq.hpp:80
openvpn::MemQBase::empty
bool empty() const
Definition
memq.hpp:37
openvpn::MemQBase::q
q_type q
Definition
memq.hpp:94
openvpn::MemQBase::MemQBase
MemQBase()
Definition
memq.hpp:27
openvpn::MemQBase::total_length
size_t total_length() const
Definition
memq.hpp:42
openvpn::MemQBase::size
size_t size() const
Definition
memq.hpp:32
openvpn::MemQBase::resize
void resize(const size_t cap)
Definition
memq.hpp:86
openvpn::MemQBase::clear
void clear()
Definition
memq.hpp:47
openvpn::MemQBase::q_type
std::deque< BufferPtr > q_type
Definition
memq.hpp:92
openvpn::MemQBase::length
size_t length
Definition
memq.hpp:93
openvpn::MemQBase::read_buf
BufferPtr read_buf()
Definition
memq.hpp:67
openvpn::MemQBase::write_buf
void write_buf(const BufferPtr &bp)
Definition
memq.hpp:54
openvpn::MemQBase::peek
BufferPtr & peek()
Definition
memq.hpp:75
openvpn::RCPtr< BufferAllocatedRc >
openvpn
Definition
ovpncli.cpp:97
size.hpp
openvpn
buffer
memq.hpp
Generated by
1.9.8