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
21
22namespace openvpn {
23
25{
26 public:
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 q.push_back(bp);
57 length += bp->size();
58 }
59
61 {
62 BufferPtr ret = q.front();
63 q.pop_front();
64 length -= ret->size();
65 return ret;
66 }
67
69 {
70 return q.front();
71 }
72
73 void pop()
74 {
75 length -= q.front()->size();
76 q.pop_front();
77 }
78
79 void resize(const size_t cap)
80 {
81 q.resize(cap);
82 }
83
84 protected:
85 typedef std::deque<BufferPtr> q_type;
86 size_t length;
88};
89
90} // namespace openvpn
91
92#endif // OPENVPN_BUFFER_MEMQ_H
bool empty() const
Definition memq.hpp:37
size_t total_length() const
Definition memq.hpp:42
size_t size() const
Definition memq.hpp:32
void resize(const size_t cap)
Definition memq.hpp:79
size_t length
Definition memq.hpp:86
BufferPtr read_buf()
Definition memq.hpp:60
std::deque< BufferPtr > q_type
Definition memq.hpp:85
void write_buf(const BufferPtr &bp)
Definition memq.hpp:54
BufferPtr & peek()
Definition memq.hpp:68
std::string ret