MySQL 8.4.2
Source Code Documentation
owned_buffer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_HTTP_SRC_HTTP_BASE_DETAILS_OWNED_BUFFER_H_
27#define ROUTER_SRC_HTTP_SRC_HTTP_BASE_DETAILS_OWNED_BUFFER_H_
28
29#include <string.h>
30
31#include <algorithm>
32#include <memory>
33#include <utility>
34
36
37namespace http {
38namespace base {
39namespace details {
40
41template <typename T>
43 public:
46 ref_buffer(const ref_buffer &other) : ref_{other.ref_} {}
47
48 void *data() const noexcept { return ref_.data(); }
49 size_t size() const noexcept { return ref_.size(); }
50
51 void reset() { ref_.reset(); }
52
53 This &operator+=(size_t n) {
54 ref_ += n;
55 return *this;
56 }
57
58 operator net::const_buffer() const {
59 return net::const_buffer(data(), size());
60 }
61
62 private:
63 T &ref_;
64};
65
66template <typename T>
68 public:
71 ref_buffers(const ref_buffers &other) : ref_{other.ref_} {}
72
73 auto begin() const { return ref_->begin(); }
74 auto end() const { return ref_->end(); }
75
76 This &operator=(const This &t) { ref_ = t.ref_; }
77
78 private:
79 T *ref_;
80};
81
83 public:
84 owned_buffer(size_t n = 0)
85 : buffer_{n ? new uint8_t[n] : nullptr},
88 data_size_{0} {}
89
91 : buffer_{std::move(other.buffer_)},
94 data_size_{other.data_size_} {}
95
96 public: // Methods needed by net_ts stream template
97 void *data() const noexcept { return data_movable_; }
98 size_t size() const noexcept { return data_size_; }
99
100 void reset() {
101 data_movable_ = buffer_.get();
102 data_size_ = 0;
103 }
104
107 data_size_ = data_size_ > n ? data_size_ - n : 0;
108 return *this;
109 }
110
111 operator net::const_buffer() const {
112 return net::const_buffer(data(), size());
113 }
114
115 public: // Other methods
116 size_t space_left() const { return buffer_size_ - data_size_; }
117 bool empty() const { return 0 == data_size_; }
118
119 size_t write(const uint8_t *source, size_t source_size) {
120 const auto bytes_to_copy = std::min(source_size, space_left());
121 memcpy(buffer_.get() + data_size_, source, bytes_to_copy);
122 data_size_ += bytes_to_copy;
123
124 return bytes_to_copy;
125 }
126
127 private:
128 std::unique_ptr<uint8_t[]> buffer_;
129 const size_t buffer_size_;
130
133};
134
135} // namespace details
136} // namespace base
137} // namespace http
138
139#endif // ROUTER_SRC_HTTP_SRC_HTTP_BASE_DETAILS_OWNED_BUFFER_H_
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: owned_buffer.h:82
owned_buffer & operator+=(size_t n)
Definition: owned_buffer.h:105
owned_buffer(size_t n=0)
Definition: owned_buffer.h:84
const size_t buffer_size_
Definition: owned_buffer.h:129
uint8_t * data_movable_
Definition: owned_buffer.h:131
size_t space_left() const
Definition: owned_buffer.h:116
size_t data_size_
Definition: owned_buffer.h:132
owned_buffer(owned_buffer &&other)
Definition: owned_buffer.h:90
void * data() const noexcept
Definition: owned_buffer.h:97
size_t write(const uint8_t *source, size_t source_size)
Definition: owned_buffer.h:119
bool empty() const
Definition: owned_buffer.h:117
size_t size() const noexcept
Definition: owned_buffer.h:98
void reset()
Definition: owned_buffer.h:100
std::unique_ptr< uint8_t[]> buffer_
Definition: owned_buffer.h:128
Definition: owned_buffer.h:42
ref_buffer(T &ref)
Definition: owned_buffer.h:45
This & operator+=(size_t n)
Definition: owned_buffer.h:53
void * data() const noexcept
Definition: owned_buffer.h:48
ref_buffer(const ref_buffer &other)
Definition: owned_buffer.h:46
void reset()
Definition: owned_buffer.h:51
T & ref_
Definition: owned_buffer.h:63
size_t size() const noexcept
Definition: owned_buffer.h:49
Definition: owned_buffer.h:67
ref_buffers(T &ref)
Definition: owned_buffer.h:70
This & operator=(const This &t)
Definition: owned_buffer.h:76
auto begin() const
Definition: owned_buffer.h:73
auto end() const
Definition: owned_buffer.h:74
T * ref_
Definition: owned_buffer.h:79
ref_buffers(const ref_buffers &other)
Definition: owned_buffer.h:71
Definition: buffer.h:135
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
Definition: connection.h:56
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:32
Definition: gcs_xcom_synode.h:64
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
int n
Definition: xcom_base.cc:509