| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2 |
|
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
|
| 3 |
|
|
3 |
|
|
| 4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
4 |
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
| 5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
5 |
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
| 6 |
|
|
6 |
|
|
| 7 |
|
// Official repository: https://github.com/cppalliance/capy
|
7 |
|
// Official repository: https://github.com/cppalliance/capy
|
| 8 |
|
|
8 |
|
|
| 9 |
|
|
9 |
|
|
| 10 |
|
#ifndef BOOST_CAPY_IO_ANY_BUFFER_SINK_HPP
|
10 |
|
#ifndef BOOST_CAPY_IO_ANY_BUFFER_SINK_HPP
|
| 11 |
|
#define BOOST_CAPY_IO_ANY_BUFFER_SINK_HPP
|
11 |
|
#define BOOST_CAPY_IO_ANY_BUFFER_SINK_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/capy/detail/config.hpp>
|
13 |
|
#include <boost/capy/detail/config.hpp>
|
| 14 |
|
#include <boost/capy/detail/await_suspend_helper.hpp>
|
14 |
|
#include <boost/capy/detail/await_suspend_helper.hpp>
|
| 15 |
|
#include <boost/capy/buffers.hpp>
|
15 |
|
#include <boost/capy/buffers.hpp>
|
| 16 |
|
#include <boost/capy/buffers/buffer_copy.hpp>
|
16 |
|
#include <boost/capy/buffers/buffer_copy.hpp>
|
| 17 |
|
#include <boost/capy/buffers/buffer_param.hpp>
|
17 |
|
#include <boost/capy/buffers/buffer_param.hpp>
|
| 18 |
|
#include <boost/capy/concept/buffer_sink.hpp>
|
18 |
|
#include <boost/capy/concept/buffer_sink.hpp>
|
| 19 |
|
#include <boost/capy/concept/io_awaitable.hpp>
|
19 |
|
#include <boost/capy/concept/io_awaitable.hpp>
|
| 20 |
|
#include <boost/capy/concept/write_sink.hpp>
|
20 |
|
#include <boost/capy/concept/write_sink.hpp>
|
| 21 |
|
#include <boost/capy/coro.hpp>
|
21 |
|
#include <boost/capy/coro.hpp>
|
| 22 |
|
#include <boost/capy/ex/executor_ref.hpp>
|
22 |
|
#include <boost/capy/ex/executor_ref.hpp>
|
| 23 |
|
#include <boost/capy/io_result.hpp>
|
23 |
|
#include <boost/capy/io_result.hpp>
|
| 24 |
- |
#include <boost/capy/task.hpp>
|
24 |
+ |
#include <boost/capy/io_task.hpp>
|
| 25 |
|
|
25 |
|
|
| 26 |
|
|
26 |
|
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
|
29 |
|
|
| 30 |
|
|
30 |
|
|
|
|
|
31 |
+ |
|
| 31 |
|
|
32 |
|
|
| 32 |
|
|
33 |
|
|
| 33 |
|
|
34 |
|
|
| 34 |
|
|
35 |
|
|
| 35 |
|
|
36 |
|
|
| 36 |
|
|
37 |
|
|
| 37 |
|
|
38 |
|
|
| 38 |
|
/** Type-erased wrapper for any BufferSink.
|
39 |
|
/** Type-erased wrapper for any BufferSink.
|
| 39 |
|
|
40 |
|
|
| 40 |
|
This class provides type erasure for any type satisfying the
|
41 |
|
This class provides type erasure for any type satisfying the
|
| 41 |
|
@ref BufferSink concept, enabling runtime polymorphism for
|
42 |
|
@ref BufferSink concept, enabling runtime polymorphism for
|
| 42 |
|
buffer sink operations. It uses cached awaitable storage to achieve
|
43 |
|
buffer sink operations. It uses cached awaitable storage to achieve
|
| 43 |
|
zero steady-state allocation after construction.
|
44 |
|
zero steady-state allocation after construction.
|
| 44 |
|
|
45 |
|
|
| 45 |
- |
The wrapper also satisfies @ref WriteSink through templated
|
46 |
+ |
The wrapper exposes two interfaces for producing data:
|
| 46 |
- |
@ref write methods. These methods copy data from the caller's
|
47 |
+ |
the @ref BufferSink interface (`prepare`, `commit`, `commit_eof`)
|
| 47 |
- |
buffers into the sink's internal storage, incurring one extra
|
48 |
+ |
and the @ref WriteSink interface (`write_some`, `write`,
|
| 48 |
- |
buffer copy compared to using @ref prepare and @ref commit
|
49 |
+ |
`write_eof`). Choose the interface that matches how your data
|
| 49 |
- |
|
50 |
+ |
|
|
|
|
51 |
+ |
|
|
|
|
52 |
+ |
@par Choosing an Interface
|
|
|
|
53 |
+ |
|
|
|
|
54 |
+ |
Use the **BufferSink** interface when you are a generator that
|
|
|
|
55 |
+ |
produces data into externally-provided buffers. The sink owns
|
|
|
|
56 |
+ |
the memory; you call @ref prepare to obtain writable buffers,
|
|
|
|
57 |
+ |
fill them, then call @ref commit or @ref commit_eof.
|
|
|
|
58 |
+ |
|
|
|
|
59 |
+ |
Use the **WriteSink** interface when you already have buffers
|
|
|
|
60 |
+ |
containing the data to write:
|
|
|
|
61 |
+ |
- If the entire body is available up front, call
|
|
|
|
62 |
+ |
@ref write_eof(buffers) to send everything atomically.
|
|
|
|
63 |
+ |
- If data arrives incrementally, call @ref write or
|
|
|
|
64 |
+ |
@ref write_some in a loop, then @ref write_eof() when done.
|
|
|
|
65 |
+ |
Prefer `write` (complete) unless your streaming pattern
|
|
|
|
66 |
+ |
benefits from partial writes via `write_some`.
|
|
|
|
67 |
+ |
|
|
|
|
68 |
+ |
If the wrapped type only satisfies @ref BufferSink, the
|
|
|
|
69 |
+ |
@ref WriteSink operations are provided automatically.
|
|
|
|
70 |
+ |
|
|
|
|
71 |
+ |
|
| 50 |
- |
The wrapper supports two construction modes:
|
|
|
|
| 51 |
|
|
72 |
|
|
| 52 |
|
- **Owning**: Pass by value to transfer ownership. The wrapper
|
73 |
|
- **Owning**: Pass by value to transfer ownership. The wrapper
|
| 53 |
|
allocates storage and owns the sink.
|
74 |
|
allocates storage and owns the sink.
|
| 54 |
|
- **Reference**: Pass a pointer to wrap without ownership. The
|
75 |
|
- **Reference**: Pass a pointer to wrap without ownership. The
|
| 55 |
|
pointed-to sink must outlive this wrapper.
|
76 |
|
pointed-to sink must outlive this wrapper.
|
| 56 |
|
|
77 |
|
|
| 57 |
|
@par Awaitable Preallocation
|
78 |
|
@par Awaitable Preallocation
|
| 58 |
|
The constructor preallocates storage for the type-erased awaitable.
|
79 |
|
The constructor preallocates storage for the type-erased awaitable.
|
| 59 |
|
This reserves all virtual address space at server startup
|
80 |
|
This reserves all virtual address space at server startup
|
| 60 |
|
so memory usage can be measured up front, rather than
|
81 |
|
so memory usage can be measured up front, rather than
|
| 61 |
|
allocating piecemeal as traffic arrives.
|
82 |
|
allocating piecemeal as traffic arrives.
|
| 62 |
|
|
83 |
|
|
| 63 |
|
|
84 |
|
|
| 64 |
|
Not thread-safe. Concurrent operations on the same wrapper
|
85 |
|
Not thread-safe. Concurrent operations on the same wrapper
|
| 65 |
|
|
86 |
|
|
| 66 |
|
|
87 |
|
|
| 67 |
|
|
88 |
|
|
| 68 |
|
|
89 |
|
|
| 69 |
|
// Owning - takes ownership of the sink
|
90 |
|
// Owning - takes ownership of the sink
|
| 70 |
|
any_buffer_sink abs(some_buffer_sink{args...});
|
91 |
|
any_buffer_sink abs(some_buffer_sink{args...});
|
| 71 |
|
|
92 |
|
|
| 72 |
|
// Reference - wraps without ownership
|
93 |
|
// Reference - wraps without ownership
|
| 73 |
|
|
94 |
|
|
| 74 |
|
any_buffer_sink abs(&sink);
|
95 |
|
any_buffer_sink abs(&sink);
|
| 75 |
|
|
96 |
|
|
|
|
|
97 |
+ |
// BufferSink interface: generate into callee-owned buffers
|
| 76 |
|
|
98 |
|
|
| 77 |
|
auto bufs = abs.prepare(arr);
|
99 |
|
auto bufs = abs.prepare(arr);
|
| 78 |
|
// Write data into bufs[0..bufs.size())
|
100 |
|
// Write data into bufs[0..bufs.size())
|
| 79 |
|
auto [ec] = co_await abs.commit(bytes_written);
|
101 |
|
auto [ec] = co_await abs.commit(bytes_written);
|
| 80 |
- |
auto [ec2] = co_await abs.commit_eof();
|
102 |
+ |
auto [ec2] = co_await abs.commit_eof(0);
|
|
|
|
103 |
+ |
|
|
|
|
104 |
+ |
// WriteSink interface: send caller-owned buffers
|
|
|
|
105 |
+ |
auto [ec3, n] = co_await abs.write(make_buffer("hello", 5));
|
|
|
|
106 |
+ |
auto [ec4] = co_await abs.write_eof();
|
|
|
|
107 |
+ |
|
|
|
|
108 |
+ |
// Or send everything at once
|
|
|
|
109 |
+ |
auto [ec5, n2] = co_await abs.write_eof(
|
|
|
|
110 |
+ |
|
| 81 |
|
|
111 |
|
|
| 82 |
|
|
112 |
|
|
| 83 |
|
@see any_buffer_source, BufferSink, WriteSink
|
113 |
|
@see any_buffer_source, BufferSink, WriteSink
|
| 84 |
|
|
114 |
|
|
| 85 |
|
|
115 |
|
|
| 86 |
|
|
116 |
|
|
| 87 |
|
|
117 |
|
|
| 88 |
|
|
118 |
|
|
|
|
|
119 |
+ |
struct write_awaitable_ops;
|
| 89 |
|
|
120 |
|
|
| 90 |
|
|
121 |
|
|
| 91 |
|
|
122 |
|
|
| 92 |
|
|
123 |
|
|
|
|
|
124 |
+ |
// hot-path members first for cache locality
|
| 93 |
|
|
125 |
|
|
| 94 |
|
vtable const* vt_ = nullptr;
|
126 |
|
vtable const* vt_ = nullptr;
|
| 95 |
- |
void* storage_ = nullptr;
|
|
|
|
| 96 |
|
void* cached_awaitable_ = nullptr;
|
127 |
|
void* cached_awaitable_ = nullptr;
|
| 97 |
|
awaitable_ops const* active_ops_ = nullptr;
|
128 |
|
awaitable_ops const* active_ops_ = nullptr;
|
|
|
|
129 |
+ |
write_awaitable_ops const* active_write_ops_ = nullptr;
|
|
|
|
130 |
+ |
void* storage_ = nullptr;
|
| 98 |
|
|
131 |
|
|
| 99 |
|
|
132 |
|
|
| 100 |
|
|
133 |
|
|
| 101 |
|
|
134 |
|
|
| 102 |
|
Destroys the owned sink (if any) and releases the cached
|
135 |
|
Destroys the owned sink (if any) and releases the cached
|
| 103 |
|
|
136 |
|
|
| 104 |
|
|
137 |
|
|
| 105 |
|
|
138 |
|
|
| 106 |
|
|
139 |
|
|
| 107 |
|
|
140 |
|
|
| 108 |
|
|
141 |
|
|
| 109 |
|
Constructs an empty wrapper. Operations on a default-constructed
|
142 |
|
Constructs an empty wrapper. Operations on a default-constructed
|
| 110 |
|
wrapper result in undefined behavior.
|
143 |
|
wrapper result in undefined behavior.
|
| 111 |
|
|
144 |
|
|
| 112 |
|
any_buffer_sink() = default;
|
145 |
|
any_buffer_sink() = default;
|
| 113 |
|
|
146 |
|
|
| 114 |
|
|
147 |
|
|
| 115 |
|
|
148 |
|
|
| 116 |
|
The awaitable cache is per-instance and cannot be shared.
|
149 |
|
The awaitable cache is per-instance and cannot be shared.
|
| 117 |
|
|
150 |
|
|
| 118 |
|
any_buffer_sink(any_buffer_sink const&) = delete;
|
151 |
|
any_buffer_sink(any_buffer_sink const&) = delete;
|
| 119 |
|
any_buffer_sink& operator=(any_buffer_sink const&) = delete;
|
152 |
|
any_buffer_sink& operator=(any_buffer_sink const&) = delete;
|
| 120 |
|
|
153 |
|
|
| 121 |
|
|
154 |
|
|
| 122 |
|
|
155 |
|
|
| 123 |
|
Transfers ownership of the wrapped sink (if owned) and
|
156 |
|
Transfers ownership of the wrapped sink (if owned) and
|
| 124 |
|
cached awaitable storage from `other`. After the move, `other` is
|
157 |
|
cached awaitable storage from `other`. After the move, `other` is
|
| 125 |
|
in a default-constructed state.
|
158 |
|
in a default-constructed state.
|
| 126 |
|
|
159 |
|
|
| 127 |
|
@param other The wrapper to move from.
|
160 |
|
@param other The wrapper to move from.
|
| 128 |
|
|
161 |
|
|
| 129 |
|
any_buffer_sink(any_buffer_sink&& other) noexcept
|
162 |
|
any_buffer_sink(any_buffer_sink&& other) noexcept
|
| 130 |
|
: sink_(std::exchange(other.sink_, nullptr))
|
163 |
|
: sink_(std::exchange(other.sink_, nullptr))
|
| 131 |
|
, vt_(std::exchange(other.vt_, nullptr))
|
164 |
|
, vt_(std::exchange(other.vt_, nullptr))
|
| 132 |
- |
, storage_(std::exchange(other.storage_, nullptr))
|
|
|
|
| 133 |
|
, cached_awaitable_(std::exchange(other.cached_awaitable_, nullptr))
|
165 |
|
, cached_awaitable_(std::exchange(other.cached_awaitable_, nullptr))
|
| 134 |
|
, active_ops_(std::exchange(other.active_ops_, nullptr))
|
166 |
|
, active_ops_(std::exchange(other.active_ops_, nullptr))
|
|
|
|
167 |
+ |
, active_write_ops_(std::exchange(other.active_write_ops_, nullptr))
|
|
|
|
168 |
+ |
, storage_(std::exchange(other.storage_, nullptr))
|
| 135 |
|
|
169 |
|
|
| 136 |
|
|
170 |
|
|
| 137 |
|
|
171 |
|
|
| 138 |
|
/** Move assignment operator.
|
172 |
|
/** Move assignment operator.
|
| 139 |
|
|
173 |
|
|
| 140 |
|
Destroys any owned sink and releases existing resources,
|
174 |
|
Destroys any owned sink and releases existing resources,
|
| 141 |
|
then transfers ownership from `other`.
|
175 |
|
then transfers ownership from `other`.
|
| 142 |
|
|
176 |
|
|
| 143 |
|
@param other The wrapper to move from.
|
177 |
|
@param other The wrapper to move from.
|
| 144 |
|
@return Reference to this wrapper.
|
178 |
|
@return Reference to this wrapper.
|
| 145 |
|
|
179 |
|
|
| 146 |
|
|
180 |
|
|
| 147 |
|
operator=(any_buffer_sink&& other) noexcept;
|
181 |
|
operator=(any_buffer_sink&& other) noexcept;
|
| 148 |
|
|
182 |
|
|
| 149 |
|
/** Construct by taking ownership of a BufferSink.
|
183 |
|
/** Construct by taking ownership of a BufferSink.
|
| 150 |
|
|
184 |
|
|
| 151 |
|
Allocates storage and moves the sink into this wrapper.
|
185 |
|
Allocates storage and moves the sink into this wrapper.
|
| 152 |
- |
The wrapper owns the sink and will destroy it.
|
186 |
+ |
The wrapper owns the sink and will destroy it. If `S` also
|
|
|
|
187 |
+ |
satisfies @ref WriteSink, native write operations are
|
|
|
|
188 |
+ |
forwarded through the virtual boundary.
|
| 153 |
|
|
189 |
|
|
| 154 |
|
@param s The sink to take ownership of.
|
190 |
|
@param s The sink to take ownership of.
|
| 155 |
|
|
191 |
|
|
| 156 |
|
|
192 |
|
|
| 157 |
|
requires (!std::same_as<std::decay_t<S>, any_buffer_sink>)
|
193 |
|
requires (!std::same_as<std::decay_t<S>, any_buffer_sink>)
|
| 158 |
|
|
194 |
|
|
| 159 |
|
|
195 |
|
|
| 160 |
|
/** Construct by wrapping a BufferSink without ownership.
|
196 |
|
/** Construct by wrapping a BufferSink without ownership.
|
| 161 |
|
|
197 |
|
|
| 162 |
|
Wraps the given sink by pointer. The sink must remain
|
198 |
|
Wraps the given sink by pointer. The sink must remain
|
| 163 |
- |
valid for the lifetime of this wrapper.
|
199 |
+ |
valid for the lifetime of this wrapper. If `S` also
|
|
|
|
200 |
+ |
satisfies @ref WriteSink, native write operations are
|
|
|
|
201 |
+ |
forwarded through the virtual boundary.
|
| 164 |
|
|
202 |
|
|
| 165 |
|
@param s Pointer to the sink to wrap.
|
203 |
|
@param s Pointer to the sink to wrap.
|
| 166 |
|
|
204 |
|
|
| 167 |
|
|
205 |
|
|
| 168 |
|
|
206 |
|
|
| 169 |
|
|
207 |
|
|
| 170 |
|
/** Check if the wrapper contains a valid sink.
|
208 |
|
/** Check if the wrapper contains a valid sink.
|
| 171 |
|
|
209 |
|
|
| 172 |
|
@return `true` if wrapping a sink, `false` if default-constructed
|
210 |
|
@return `true` if wrapping a sink, `false` if default-constructed
|
| 173 |
|
|
211 |
|
|
| 174 |
|
|
212 |
|
|
| 175 |
|
|
213 |
|
|
| 176 |
|
has_value() const noexcept
|
214 |
|
has_value() const noexcept
|
| 177 |
|
|
215 |
|
|
| 178 |
|
|
216 |
|
|
| 179 |
|
|
217 |
|
|
| 180 |
|
|
218 |
|
|
| 181 |
|
/** Check if the wrapper contains a valid sink.
|
219 |
|
/** Check if the wrapper contains a valid sink.
|
| 182 |
|
|
220 |
|
|
| 183 |
|
@return `true` if wrapping a sink, `false` if default-constructed
|
221 |
|
@return `true` if wrapping a sink, `false` if default-constructed
|
| 184 |
|
|
222 |
|
|
| 185 |
|
|
223 |
|
|
| 186 |
|
|
224 |
|
|
| 187 |
|
operator bool() const noexcept
|
225 |
|
operator bool() const noexcept
|
| 188 |
|
|
226 |
|
|
| 189 |
|
|
227 |
|
|
| 190 |
|
|
228 |
|
|
| 191 |
|
|
229 |
|
|
| 192 |
|
/** Prepare writable buffers.
|
230 |
|
/** Prepare writable buffers.
|
| 193 |
|
|
231 |
|
|
| 194 |
|
Fills the provided span with mutable buffer descriptors
|
232 |
|
Fills the provided span with mutable buffer descriptors
|
| 195 |
|
pointing to the underlying sink's internal storage. This
|
233 |
|
pointing to the underlying sink's internal storage. This
|
| 196 |
|
operation is synchronous.
|
234 |
|
operation is synchronous.
|
| 197 |
|
|
235 |
|
|
| 198 |
|
@param dest Span of mutable_buffer to fill.
|
236 |
|
@param dest Span of mutable_buffer to fill.
|
| 199 |
|
|
237 |
|
|
| 200 |
|
@return A span of filled buffers.
|
238 |
|
@return A span of filled buffers.
|
| 201 |
|
|
239 |
|
|
| 202 |
|
|
240 |
|
|
| 203 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
241 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 204 |
|
|
242 |
|
|
| 205 |
|
std::span<mutable_buffer>
|
243 |
|
std::span<mutable_buffer>
|
| 206 |
|
prepare(std::span<mutable_buffer> dest);
|
244 |
|
prepare(std::span<mutable_buffer> dest);
|
| 207 |
|
|
245 |
|
|
| 208 |
|
/** Commit bytes written to the prepared buffers.
|
246 |
|
/** Commit bytes written to the prepared buffers.
|
| 209 |
|
|
247 |
|
|
| 210 |
|
Commits `n` bytes written to the buffers returned by the
|
248 |
|
Commits `n` bytes written to the buffers returned by the
|
| 211 |
|
most recent call to @ref prepare. The operation may trigger
|
249 |
|
most recent call to @ref prepare. The operation may trigger
|
| 212 |
|
|
250 |
|
|
| 213 |
|
|
251 |
|
|
| 214 |
|
@param n The number of bytes to commit.
|
252 |
|
@param n The number of bytes to commit.
|
| 215 |
|
|
253 |
|
|
| 216 |
|
@return An awaitable yielding `(error_code)`.
|
254 |
|
@return An awaitable yielding `(error_code)`.
|
| 217 |
|
|
255 |
|
|
| 218 |
|
|
256 |
|
|
| 219 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
257 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 220 |
|
|
258 |
|
|
| 221 |
|
|
259 |
|
|
| 222 |
|
|
260 |
|
|
| 223 |
|
|
261 |
|
|
| 224 |
- |
/** Commit bytes written with optional end-of-stream.
|
262 |
+ |
/** Commit final bytes and signal end-of-stream.
|
| 225 |
|
|
263 |
|
|
| 226 |
|
Commits `n` bytes written to the buffers returned by the
|
264 |
|
Commits `n` bytes written to the buffers returned by the
|
| 227 |
- |
most recent call to @ref prepare. If `eof` is true, also
|
265 |
+ |
most recent call to @ref prepare and finalizes the sink.
|
| 228 |
- |
|
266 |
+ |
After success, no further operations are permitted.
|
| 229 |
|
|
267 |
|
|
| 230 |
- |
@param eof If true, signals end-of-stream after committing.
|
|
|
|
| 231 |
|
@param n The number of bytes to commit.
|
268 |
|
@param n The number of bytes to commit.
|
| 232 |
|
|
269 |
|
|
| 233 |
|
@return An awaitable yielding `(error_code)`.
|
270 |
|
@return An awaitable yielding `(error_code)`.
|
| 234 |
|
|
271 |
|
|
| 235 |
|
|
272 |
|
|
| 236 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
273 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 237 |
|
|
274 |
|
|
| 238 |
|
|
275 |
|
|
| 239 |
- |
commit(std::size_t n, bool eof);
|
276 |
+ |
commit_eof(std::size_t n);
|
| 240 |
|
|
277 |
|
|
| 241 |
- |
/** Signal end-of-stream.
|
278 |
+ |
/** Write some data from a buffer sequence.
|
| 242 |
|
|
279 |
|
|
| 243 |
- |
Indicates that no more data will be written to the sink.
|
280 |
+ |
Writes one or more bytes from the buffer sequence to the
|
| 244 |
- |
The operation completes when the sink is finalized, or
|
281 |
+ |
underlying sink. May consume less than the full sequence.
|
| 245 |
- |
|
|
|
|
| 246 |
|
|
282 |
|
|
| 247 |
- |
@return An awaitable yielding `(error_code)`.
|
283 |
+ |
When the wrapped type provides native @ref WriteSink support,
|
|
|
|
284 |
+ |
the operation forwards directly. Otherwise it is synthesized
|
|
|
|
285 |
+ |
from @ref prepare and @ref commit with a buffer copy.
|
|
|
|
286 |
+ |
|
|
|
|
287 |
+ |
@param buffers The buffer sequence to write.
|
|
|
|
288 |
+ |
|
|
|
|
289 |
+ |
@return An awaitable yielding `(error_code,std::size_t)`.
|
| 248 |
|
|
290 |
|
|
| 249 |
|
|
291 |
|
|
| 250 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
292 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 251 |
|
|
293 |
|
|
| 252 |
- |
|
294 |
+ |
template<ConstBufferSequence CB>
|
| 253 |
- |
|
295 |
+ |
|
|
|
|
296 |
+ |
|
| 254 |
|
|
297 |
|
|
| 255 |
- |
/** Write data from a buffer sequence.
|
298 |
+ |
/** Write all data from a buffer sequence.
|
| 256 |
|
|
299 |
|
|
| 257 |
|
Writes all data from the buffer sequence to the underlying
|
300 |
|
Writes all data from the buffer sequence to the underlying
|
| 258 |
|
sink. This method satisfies the @ref WriteSink concept.
|
301 |
|
sink. This method satisfies the @ref WriteSink concept.
|
| 259 |
|
|
302 |
|
|
| 260 |
- |
@note This operation copies data from the caller's buffers
|
303 |
+ |
When the wrapped type provides native @ref WriteSink support,
|
| 261 |
- |
into the sink's internal buffers. For zero-copy writes,
|
304 |
+ |
each window is forwarded directly. Otherwise the data is
|
| 262 |
- |
use @ref prepare and @ref commit directly.
|
305 |
+ |
copied into the sink via @ref prepare and @ref commit.
|
| 263 |
|
|
306 |
|
|
| 264 |
|
@param buffers The buffer sequence to write.
|
307 |
|
@param buffers The buffer sequence to write.
|
| 265 |
|
|
308 |
|
|
| 266 |
|
@return An awaitable yielding `(error_code,std::size_t)`.
|
309 |
|
@return An awaitable yielding `(error_code,std::size_t)`.
|
| 267 |
|
|
310 |
|
|
| 268 |
|
|
311 |
|
|
| 269 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
312 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 270 |
|
|
313 |
|
|
| 271 |
|
template<ConstBufferSequence CB>
|
314 |
|
template<ConstBufferSequence CB>
|
| 272 |
- |
task<io_result<std::size_t>>
|
315 |
+ |
|
| 273 |
|
|
316 |
|
|
| 274 |
|
|
317 |
|
|
| 275 |
- |
/** Write data with optional end-of-stream.
|
318 |
+ |
/** Atomically write data and signal end-of-stream.
|
| 276 |
|
|
319 |
|
|
| 277 |
|
Writes all data from the buffer sequence to the underlying
|
320 |
|
Writes all data from the buffer sequence to the underlying
|
| 278 |
- |
sink, optionally finalizing it afterwards. This method
|
321 |
+ |
sink and then signals end-of-stream.
|
| 279 |
- |
satisfies the @ref WriteSink concept.
|
|
|
|
| 280 |
|
|
322 |
|
|
| 281 |
- |
@note This operation copies data from the caller's buffers
|
323 |
+ |
When the wrapped type provides native @ref WriteSink support,
|
| 282 |
- |
into the sink's internal buffers. For zero-copy writes,
|
324 |
+ |
the final window is sent atomically via the underlying
|
| 283 |
- |
use @ref prepare and @ref commit directly.
|
325 |
+ |
`write_eof(buffers)`. Otherwise the data is synthesized
|
|
|
|
326 |
+ |
through @ref prepare, @ref commit, and @ref commit_eof.
|
| 284 |
|
|
327 |
|
|
| 285 |
- |
@param eof If true, finalize the sink after writing.
|
|
|
|
| 286 |
|
@param buffers The buffer sequence to write.
|
328 |
|
@param buffers The buffer sequence to write.
|
| 287 |
|
|
329 |
|
|
| 288 |
|
@return An awaitable yielding `(error_code,std::size_t)`.
|
330 |
|
@return An awaitable yielding `(error_code,std::size_t)`.
|
| 289 |
|
|
331 |
|
|
| 290 |
|
|
332 |
|
|
| 291 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
333 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 292 |
|
|
334 |
|
|
| 293 |
|
template<ConstBufferSequence CB>
|
335 |
|
template<ConstBufferSequence CB>
|
| 294 |
- |
task<io_result<std::size_t>>
|
336 |
+ |
|
| 295 |
- |
write(CB buffers, bool eof);
|
337 |
+ |
|
| 296 |
|
|
338 |
|
|
| 297 |
|
/** Signal end-of-stream.
|
339 |
|
/** Signal end-of-stream.
|
| 298 |
|
|
340 |
|
|
| 299 |
|
Indicates that no more data will be written to the sink.
|
341 |
|
Indicates that no more data will be written to the sink.
|
| 300 |
|
This method satisfies the @ref WriteSink concept.
|
342 |
|
This method satisfies the @ref WriteSink concept.
|
| 301 |
|
|
343 |
|
|
|
|
|
344 |
+ |
When the wrapped type provides native @ref WriteSink support,
|
|
|
|
345 |
+ |
the underlying `write_eof()` is called. Otherwise the
|
|
|
|
346 |
+ |
operation is implemented as `commit_eof(0)`.
|
|
|
|
347 |
+ |
|
| 302 |
|
@return An awaitable yielding `(error_code)`.
|
348 |
|
@return An awaitable yielding `(error_code)`.
|
| 303 |
|
|
349 |
|
|
| 304 |
|
|
350 |
|
|
| 305 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
351 |
|
The wrapper must contain a valid sink (`has_value() == true`).
|
| 306 |
|
|
352 |
|
|
| 307 |
|
|
353 |
|
|
| 308 |
|
|
354 |
|
|
| 309 |
|
|
355 |
|
|
| 310 |
|
|
356 |
|
|
| 311 |
|
/** Rebind to a new sink after move.
|
357 |
|
/** Rebind to a new sink after move.
|
| 312 |
|
|
358 |
|
|
| 313 |
|
Updates the internal pointer to reference a new sink object.
|
359 |
|
Updates the internal pointer to reference a new sink object.
|
| 314 |
|
Used by owning wrappers after move assignment when the owned
|
360 |
|
Used by owning wrappers after move assignment when the owned
|
| 315 |
|
object has moved to a new location.
|
361 |
|
object has moved to a new location.
|
| 316 |
|
|
362 |
|
|
| 317 |
|
@param new_sink The new sink to bind to. Must be the same
|
363 |
|
@param new_sink The new sink to bind to. Must be the same
|
| 318 |
|
type as the original sink.
|
364 |
|
type as the original sink.
|
| 319 |
|
|
365 |
|
|
| 320 |
|
@note Terminates if called with a sink of different type
|
366 |
|
@note Terminates if called with a sink of different type
|
| 321 |
|
|
367 |
|
|
| 322 |
|
|
368 |
|
|
| 323 |
|
|
369 |
|
|
| 324 |
|
|
370 |
|
|
| 325 |
|
rebind(S& new_sink) noexcept
|
371 |
|
rebind(S& new_sink) noexcept
|
| 326 |
|
|
372 |
|
|
| 327 |
|
if(vt_ != &vtable_for_impl<S>::value)
|
373 |
|
if(vt_ != &vtable_for_impl<S>::value)
|
| 328 |
|
|
374 |
|
|
| 329 |
|
|
375 |
|
|
| 330 |
|
|
376 |
|
|
|
|
|
377 |
+ |
|
|
|
|
378 |
+ |
|
|
|
|
379 |
+ |
/** Forward a partial write through the vtable.
|
|
|
|
380 |
+ |
|
|
|
|
381 |
+ |
Constructs the underlying `write_some` awaitable in
|
|
|
|
382 |
+ |
cached storage and returns a type-erased awaitable.
|
|
|
|
383 |
+ |
|
|
|
|
384 |
+ |
|
|
|
|
385 |
+ |
write_some_(std::span<const_buffer const> buffers);
|
|
|
|
386 |
+ |
|
|
|
|
387 |
+ |
/** Forward a complete write through the vtable.
|
|
|
|
388 |
+ |
|
|
|
|
389 |
+ |
Constructs the underlying `write` awaitable in
|
|
|
|
390 |
+ |
cached storage and returns a type-erased awaitable.
|
|
|
|
391 |
+ |
|
|
|
|
392 |
+ |
|
|
|
|
393 |
+ |
write_(std::span<const_buffer const> buffers);
|
|
|
|
394 |
+ |
|
|
|
|
395 |
+ |
/** Forward an atomic write-with-EOF through the vtable.
|
|
|
|
396 |
+ |
|
|
|
|
397 |
+ |
Constructs the underlying `write_eof(buffers)` awaitable
|
|
|
|
398 |
+ |
in cached storage and returns a type-erased awaitable.
|
|
|
|
399 |
+ |
|
|
|
|
400 |
+ |
|
|
|
|
401 |
+ |
write_eof_buffers_(std::span<const_buffer const> buffers);
|
| 331 |
|
|
402 |
|
|
| 332 |
|
|
403 |
|
|
| 333 |
|
//----------------------------------------------------------
|
404 |
|
//----------------------------------------------------------
|
| 334 |
|
|
405 |
|
|
|
|
|
406 |
+ |
/** Type-erased ops for awaitables yielding `io_result<>`. */
|
| 335 |
|
struct any_buffer_sink::awaitable_ops
|
407 |
|
struct any_buffer_sink::awaitable_ops
|
| 336 |
|
|
408 |
|
|
| 337 |
|
bool (*await_ready)(void*);
|
409 |
|
bool (*await_ready)(void*);
|
| 338 |
|
coro (*await_suspend)(void*, coro, executor_ref, std::stop_token);
|
410 |
|
coro (*await_suspend)(void*, coro, executor_ref, std::stop_token);
|
| 339 |
|
io_result<> (*await_resume)(void*);
|
411 |
|
io_result<> (*await_resume)(void*);
|
| 340 |
|
void (*destroy)(void*) noexcept;
|
412 |
|
void (*destroy)(void*) noexcept;
|
| 341 |
|
|
413 |
|
|
| 342 |
|
|
414 |
|
|
|
|
|
415 |
+ |
/** Type-erased ops for awaitables yielding `io_result<std::size_t>`. */
|
|
|
|
416 |
+ |
struct any_buffer_sink::write_awaitable_ops
|
|
|
|
417 |
+ |
|
|
|
|
418 |
+ |
bool (*await_ready)(void*);
|
|
|
|
419 |
+ |
coro (*await_suspend)(void*, coro, executor_ref, std::stop_token);
|
|
|
|
420 |
+ |
io_result<std::size_t> (*await_resume)(void*);
|
|
|
|
421 |
+ |
void (*destroy)(void*) noexcept;
|
|
|
|
422 |
+ |
|
|
|
|
423 |
+ |
|
| 343 |
|
struct any_buffer_sink::vtable
|
424 |
|
struct any_buffer_sink::vtable
|
| 344 |
|
|
425 |
|
|
| 345 |
|
void (*destroy)(void*) noexcept;
|
426 |
|
void (*destroy)(void*) noexcept;
|
| 346 |
|
std::span<mutable_buffer> (*do_prepare)(
|
427 |
|
std::span<mutable_buffer> (*do_prepare)(
|
| 347 |
|
|
428 |
|
|
| 348 |
|
std::span<mutable_buffer> dest);
|
429 |
|
std::span<mutable_buffer> dest);
|
| 349 |
|
std::size_t awaitable_size;
|
430 |
|
std::size_t awaitable_size;
|
| 350 |
|
std::size_t awaitable_align;
|
431 |
|
std::size_t awaitable_align;
|
| 351 |
|
awaitable_ops const* (*construct_commit_awaitable)(
|
432 |
|
awaitable_ops const* (*construct_commit_awaitable)(
|
| 352 |
|
|
433 |
|
|
| 353 |
|
|
434 |
|
|
| 354 |
- |
|
435 |
+ |
|
| 355 |
- |
|
436 |
+ |
awaitable_ops const* (*construct_commit_eof_awaitable)(
|
| 356 |
- |
awaitable_ops const* (*construct_eof_awaitable)(
|
437 |
+ |
|
|
|
|
438 |
+ |
|
|
|
|
439 |
+ |
|
|
|
|
440 |
+ |
|
|
|
|
441 |
+ |
// WriteSink forwarding (null when wrapped type is BufferSink-only)
|
|
|
|
442 |
+ |
write_awaitable_ops const* (*construct_write_some_awaitable)(
|
|
|
|
443 |
+ |
|
|
|
|
444 |
+ |
|
|
|
|
445 |
+ |
std::span<const_buffer const> buffers);
|
|
|
|
446 |
+ |
write_awaitable_ops const* (*construct_write_awaitable)(
|
|
|
|
447 |
+ |
|
|
|
|
448 |
+ |
|
|
|
|
449 |
+ |
std::span<const_buffer const> buffers);
|
|
|
|
450 |
+ |
write_awaitable_ops const* (*construct_write_eof_buffers_awaitable)(
|
|
|
|
451 |
+ |
|
|
|
|
452 |
+ |
|
|
|
|
453 |
+ |
std::span<const_buffer const> buffers);
|
|
|
|
454 |
+ |
awaitable_ops const* (*construct_write_eof_awaitable)(
|
| 357 |
|
|
455 |
|
|
| 358 |
|
|
456 |
|
|
| 359 |
|
|
457 |
|
|
| 360 |
|
|
458 |
|
|
| 361 |
|
|
459 |
|
|
| 362 |
|
struct any_buffer_sink::vtable_for_impl
|
460 |
|
struct any_buffer_sink::vtable_for_impl
|
| 363 |
|
|
461 |
|
|
| 364 |
|
using CommitAwaitable = decltype(std::declval<S&>().commit(
|
462 |
|
using CommitAwaitable = decltype(std::declval<S&>().commit(
|
| 365 |
- |
|
463 |
+ |
|
| 366 |
- |
using EofAwaitable = decltype(std::declval<S&>().commit_eof());
|
464 |
+ |
using CommitEofAwaitable = decltype(std::declval<S&>().commit_eof(
|
|
|
|
465 |
+ |
|
| 367 |
|
|
466 |
|
|
| 368 |
|
|
467 |
|
|
| 369 |
|
do_destroy_impl(void* sink) noexcept
|
468 |
|
do_destroy_impl(void* sink) noexcept
|
| 370 |
|
|
469 |
|
|
| 371 |
|
static_cast<S*>(sink)->~S();
|
470 |
|
static_cast<S*>(sink)->~S();
|
| 372 |
|
|
471 |
|
|
| 373 |
|
|
472 |
|
|
| 374 |
|
static std::span<mutable_buffer>
|
473 |
|
static std::span<mutable_buffer>
|
| 375 |
|
|
474 |
|
|
| 376 |
|
|
475 |
|
|
| 377 |
|
std::span<mutable_buffer> dest)
|
476 |
|
std::span<mutable_buffer> dest)
|
| 378 |
|
|
477 |
|
|
| 379 |
|
auto& s = *static_cast<S*>(sink);
|
478 |
|
auto& s = *static_cast<S*>(sink);
|
| 380 |
|
|
479 |
|
|
| 381 |
|
|
480 |
|
|
| 382 |
|
|
481 |
|
|
| 383 |
|
static awaitable_ops const*
|
482 |
|
static awaitable_ops const*
|
| 384 |
|
construct_commit_awaitable_impl(
|
483 |
|
construct_commit_awaitable_impl(
|
| 385 |
|
|
484 |
|
|
| 386 |
|
|
485 |
|
|
| 387 |
- |
|
486 |
+ |
|
| 388 |
- |
|
|
|
|
| 389 |
|
|
487 |
|
|
| 390 |
|
auto& s = *static_cast<S*>(sink);
|
488 |
|
auto& s = *static_cast<S*>(sink);
|
| 391 |
- |
::new(storage) CommitAwaitable(s.commit(n, eof));
|
489 |
+ |
::new(storage) CommitAwaitable(s.commit(n));
|
| 392 |
|
|
490 |
|
|
| 393 |
|
static constexpr awaitable_ops ops = {
|
491 |
|
static constexpr awaitable_ops ops = {
|
| 394 |
|
|
492 |
|
|
| 395 |
|
return static_cast<CommitAwaitable*>(p)->await_ready();
|
493 |
|
return static_cast<CommitAwaitable*>(p)->await_ready();
|
| 396 |
|
|
494 |
|
|
| 397 |
|
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
495 |
|
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
| 398 |
|
return detail::call_await_suspend(
|
496 |
|
return detail::call_await_suspend(
|
| 399 |
|
static_cast<CommitAwaitable*>(p), h, ex, token);
|
497 |
|
static_cast<CommitAwaitable*>(p), h, ex, token);
|
| 400 |
|
|
498 |
|
|
| 401 |
|
|
499 |
|
|
| 402 |
|
return static_cast<CommitAwaitable*>(p)->await_resume();
|
500 |
|
return static_cast<CommitAwaitable*>(p)->await_resume();
|
| 403 |
|
|
501 |
|
|
| 404 |
|
|
502 |
|
|
| 405 |
|
static_cast<CommitAwaitable*>(p)->~CommitAwaitable();
|
503 |
|
static_cast<CommitAwaitable*>(p)->~CommitAwaitable();
|
| 406 |
|
|
504 |
|
|
| 407 |
|
|
505 |
|
|
| 408 |
|
|
506 |
|
|
| 409 |
|
|
507 |
|
|
| 410 |
|
|
508 |
|
|
| 411 |
|
static awaitable_ops const*
|
509 |
|
static awaitable_ops const*
|
| 412 |
- |
construct_eof_awaitable_impl(
|
510 |
+ |
construct_commit_eof_awaitable_impl(
|
|
|
|
511 |
+ |
|
|
|
|
512 |
+ |
|
|
|
|
513 |
+ |
|
|
|
|
514 |
+ |
|
|
|
|
515 |
+ |
auto& s = *static_cast<S*>(sink);
|
|
|
|
516 |
+ |
::new(storage) CommitEofAwaitable(s.commit_eof(n));
|
|
|
|
517 |
+ |
|
|
|
|
518 |
+ |
static constexpr awaitable_ops ops = {
|
|
|
|
519 |
+ |
|
|
|
|
520 |
+ |
return static_cast<CommitEofAwaitable*>(p)->await_ready();
|
|
|
|
521 |
+ |
|
|
|
|
522 |
+ |
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
|
|
|
523 |
+ |
return detail::call_await_suspend(
|
|
|
|
524 |
+ |
static_cast<CommitEofAwaitable*>(p), h, ex, token);
|
|
|
|
525 |
+ |
|
|
|
|
526 |
+ |
|
|
|
|
527 |
+ |
return static_cast<CommitEofAwaitable*>(p)->await_resume();
|
|
|
|
528 |
+ |
|
|
|
|
529 |
+ |
|
|
|
|
530 |
+ |
static_cast<CommitEofAwaitable*>(p)->~CommitEofAwaitable();
|
|
|
|
531 |
+ |
|
|
|
|
532 |
+ |
|
|
|
|
533 |
+ |
|
|
|
|
534 |
+ |
|
|
|
|
535 |
+ |
|
|
|
|
536 |
+ |
//------------------------------------------------------
|
|
|
|
537 |
+ |
// WriteSink forwarding (only instantiated when WriteSink<S>)
|
|
|
|
538 |
+ |
|
|
|
|
539 |
+ |
static write_awaitable_ops const*
|
|
|
|
540 |
+ |
construct_write_some_awaitable_impl(
|
|
|
|
541 |
+ |
|
|
|
|
542 |
+ |
|
|
|
|
543 |
+ |
std::span<const_buffer const> buffers)
|
|
|
|
544 |
+ |
|
|
|
|
545 |
+ |
|
|
|
|
546 |
+ |
using Aw = decltype(std::declval<S&>().write_some(
|
|
|
|
547 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
548 |
+ |
auto& s = *static_cast<S*>(sink);
|
|
|
|
549 |
+ |
::new(storage) Aw(s.write_some(buffers));
|
|
|
|
550 |
+ |
|
|
|
|
551 |
+ |
static constexpr write_awaitable_ops ops = {
|
|
|
|
552 |
+ |
|
|
|
|
553 |
+ |
return static_cast<Aw*>(p)->await_ready();
|
|
|
|
554 |
+ |
|
|
|
|
555 |
+ |
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
|
|
|
556 |
+ |
return detail::call_await_suspend(
|
|
|
|
557 |
+ |
static_cast<Aw*>(p), h, ex, token);
|
|
|
|
558 |
+ |
|
|
|
|
559 |
+ |
|
|
|
|
560 |
+ |
return static_cast<Aw*>(p)->await_resume();
|
|
|
|
561 |
+ |
|
|
|
|
562 |
+ |
|
|
|
|
563 |
+ |
static_cast<Aw*>(p)->~Aw();
|
|
|
|
564 |
+ |
|
|
|
|
565 |
+ |
|
|
|
|
566 |
+ |
|
|
|
|
567 |
+ |
|
|
|
|
568 |
+ |
|
|
|
|
569 |
+ |
static write_awaitable_ops const*
|
|
|
|
570 |
+ |
construct_write_awaitable_impl(
|
|
|
|
571 |
+ |
|
|
|
|
572 |
+ |
|
|
|
|
573 |
+ |
std::span<const_buffer const> buffers)
|
|
|
|
574 |
+ |
|
|
|
|
575 |
+ |
|
|
|
|
576 |
+ |
using Aw = decltype(std::declval<S&>().write(
|
|
|
|
577 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
578 |
+ |
auto& s = *static_cast<S*>(sink);
|
|
|
|
579 |
+ |
::new(storage) Aw(s.write(buffers));
|
|
|
|
580 |
+ |
|
|
|
|
581 |
+ |
static constexpr write_awaitable_ops ops = {
|
|
|
|
582 |
+ |
|
|
|
|
583 |
+ |
return static_cast<Aw*>(p)->await_ready();
|
|
|
|
584 |
+ |
|
|
|
|
585 |
+ |
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
|
|
|
586 |
+ |
return detail::call_await_suspend(
|
|
|
|
587 |
+ |
static_cast<Aw*>(p), h, ex, token);
|
|
|
|
588 |
+ |
|
|
|
|
589 |
+ |
|
|
|
|
590 |
+ |
return static_cast<Aw*>(p)->await_resume();
|
|
|
|
591 |
+ |
|
|
|
|
592 |
+ |
|
|
|
|
593 |
+ |
static_cast<Aw*>(p)->~Aw();
|
|
|
|
594 |
+ |
|
|
|
|
595 |
+ |
|
|
|
|
596 |
+ |
|
|
|
|
597 |
+ |
|
|
|
|
598 |
+ |
|
|
|
|
599 |
+ |
static write_awaitable_ops const*
|
|
|
|
600 |
+ |
construct_write_eof_buffers_awaitable_impl(
|
|
|
|
601 |
+ |
|
|
|
|
602 |
+ |
|
|
|
|
603 |
+ |
std::span<const_buffer const> buffers)
|
|
|
|
604 |
+ |
|
|
|
|
605 |
+ |
|
|
|
|
606 |
+ |
using Aw = decltype(std::declval<S&>().write_eof(
|
|
|
|
607 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
608 |
+ |
auto& s = *static_cast<S*>(sink);
|
|
|
|
609 |
+ |
::new(storage) Aw(s.write_eof(buffers));
|
|
|
|
610 |
+ |
|
|
|
|
611 |
+ |
static constexpr write_awaitable_ops ops = {
|
|
|
|
612 |
+ |
|
|
|
|
613 |
+ |
return static_cast<Aw*>(p)->await_ready();
|
|
|
|
614 |
+ |
|
|
|
|
615 |
+ |
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
|
|
|
616 |
+ |
return detail::call_await_suspend(
|
|
|
|
617 |
+ |
static_cast<Aw*>(p), h, ex, token);
|
|
|
|
618 |
+ |
|
|
|
|
619 |
+ |
|
|
|
|
620 |
+ |
return static_cast<Aw*>(p)->await_resume();
|
|
|
|
621 |
+ |
|
|
|
|
622 |
+ |
|
|
|
|
623 |
+ |
static_cast<Aw*>(p)->~Aw();
|
|
|
|
624 |
+ |
|
|
|
|
625 |
+ |
|
|
|
|
626 |
+ |
|
|
|
|
627 |
+ |
|
|
|
|
628 |
+ |
|
|
|
|
629 |
+ |
static awaitable_ops const*
|
|
|
|
630 |
+ |
construct_write_eof_awaitable_impl(
|
| 413 |
|
|
631 |
|
|
| 414 |
|
|
632 |
|
|
|
|
|
633 |
+ |
|
| 415 |
|
|
634 |
|
|
|
|
|
635 |
+ |
using Aw = decltype(std::declval<S&>().write_eof());
|
| 416 |
|
auto& s = *static_cast<S*>(sink);
|
636 |
|
auto& s = *static_cast<S*>(sink);
|
| 417 |
- |
::new(storage) EofAwaitable(s.commit_eof());
|
637 |
+ |
::new(storage) Aw(s.write_eof());
|
| 418 |
|
|
638 |
|
|
| 419 |
|
static constexpr awaitable_ops ops = {
|
639 |
|
static constexpr awaitable_ops ops = {
|
| 420 |
|
|
640 |
|
|
| 421 |
- |
return static_cast<EofAwaitable*>(p)->await_ready();
|
641 |
+ |
return static_cast<Aw*>(p)->await_ready();
|
| 422 |
|
|
642 |
|
|
| 423 |
|
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
643 |
|
+[](void* p, coro h, executor_ref ex, std::stop_token token) {
|
| 424 |
|
return detail::call_await_suspend(
|
644 |
|
return detail::call_await_suspend(
|
| 425 |
- |
static_cast<EofAwaitable*>(p), h, ex, token);
|
645 |
+ |
static_cast<Aw*>(p), h, ex, token);
|
| 426 |
|
|
646 |
|
|
| 427 |
|
|
647 |
|
|
| 428 |
- |
return static_cast<EofAwaitable*>(p)->await_resume();
|
648 |
+ |
return static_cast<Aw*>(p)->await_resume();
|
| 429 |
|
|
649 |
|
|
| 430 |
|
|
650 |
|
|
| 431 |
- |
static_cast<EofAwaitable*>(p)->~EofAwaitable();
|
651 |
+ |
static_cast<Aw*>(p)->~Aw();
|
| 432 |
|
|
652 |
|
|
| 433 |
|
|
653 |
|
|
| 434 |
|
|
654 |
|
|
| 435 |
|
|
655 |
|
|
| 436 |
|
|
656 |
|
|
| 437 |
- |
static constexpr std::size_t max_awaitable_size =
|
657 |
+ |
//------------------------------------------------------
|
| 438 |
- |
sizeof(CommitAwaitable) > sizeof(EofAwaitable)
|
658 |
+ |
|
|
|
|
659 |
+ |
static consteval std::size_t
|
|
|
|
660 |
+ |
compute_max_size() noexcept
|
|
|
|
661 |
+ |
|
|
|
|
662 |
+ |
std::size_t s = sizeof(CommitAwaitable) > sizeof(CommitEofAwaitable)
|
| 439 |
|
? sizeof(CommitAwaitable)
|
663 |
|
? sizeof(CommitAwaitable)
|
| 440 |
- |
|
664 |
+ |
: sizeof(CommitEofAwaitable);
|
|
|
|
665 |
+ |
if constexpr (WriteSink<S>)
|
|
|
|
666 |
+ |
|
|
|
|
667 |
+ |
using WS = decltype(std::declval<S&>().write_some(
|
|
|
|
668 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
669 |
+ |
using W = decltype(std::declval<S&>().write(
|
|
|
|
670 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
671 |
+ |
using WEB = decltype(std::declval<S&>().write_eof(
|
|
|
|
672 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
673 |
+ |
using WE = decltype(std::declval<S&>().write_eof());
|
| 441 |
|
|
674 |
|
|
| 442 |
- |
static constexpr std::size_t max_awaitable_align =
|
675 |
+ |
if(sizeof(WS) > s) s = sizeof(WS);
|
| 443 |
- |
alignof(CommitAwaitable) > alignof(EofAwaitable)
|
676 |
+ |
if(sizeof(W) > s) s = sizeof(W);
|
|
|
|
677 |
+ |
if(sizeof(WEB) > s) s = sizeof(WEB);
|
|
|
|
678 |
+ |
if(sizeof(WE) > s) s = sizeof(WE);
|
|
|
|
679 |
+ |
|
|
|
|
680 |
+ |
|
|
|
|
681 |
+ |
|
|
|
|
682 |
+ |
|
|
|
|
683 |
+ |
static consteval std::size_t
|
|
|
|
684 |
+ |
compute_max_align() noexcept
|
|
|
|
685 |
+ |
|
|
|
|
686 |
+ |
std::size_t a = alignof(CommitAwaitable) > alignof(CommitEofAwaitable)
|
| 444 |
|
? alignof(CommitAwaitable)
|
687 |
|
? alignof(CommitAwaitable)
|
| 445 |
- |
|
688 |
+ |
: alignof(CommitEofAwaitable);
|
|
|
|
689 |
+ |
if constexpr (WriteSink<S>)
|
|
|
|
690 |
+ |
|
|
|
|
691 |
+ |
using WS = decltype(std::declval<S&>().write_some(
|
|
|
|
692 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
693 |
+ |
using W = decltype(std::declval<S&>().write(
|
|
|
|
694 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
695 |
+ |
using WEB = decltype(std::declval<S&>().write_eof(
|
|
|
|
696 |
+ |
std::span<const_buffer const>{}));
|
|
|
|
697 |
+ |
using WE = decltype(std::declval<S&>().write_eof());
|
| 446 |
|
|
698 |
|
|
| 447 |
- |
static constexpr vtable value = {
|
699 |
+ |
if(alignof(WS) > a) a = alignof(WS);
|
| 448 |
- |
|
700 |
+ |
if(alignof(W) > a) a = alignof(W);
|
| 449 |
- |
|
701 |
+ |
if(alignof(WEB) > a) a = alignof(WEB);
|
| 450 |
- |
|
702 |
+ |
if(alignof(WE) > a) a = alignof(WE);
|
| 451 |
- |
|
703 |
+ |
|
| 452 |
- |
&construct_commit_awaitable_impl,
|
704 |
+ |
|
| 453 |
- |
&construct_eof_awaitable_impl
|
705 |
+ |
|
| 454 |
- |
|
706 |
+ |
|
|
|
|
707 |
+ |
|
|
|
|
708 |
+ |
|
|
|
|
709 |
+ |
|
|
|
|
710 |
+ |
|
|
|
|
711 |
+ |
v.destroy = &do_destroy_impl;
|
|
|
|
712 |
+ |
v.do_prepare = &do_prepare_impl;
|
|
|
|
713 |
+ |
v.awaitable_size = compute_max_size();
|
|
|
|
714 |
+ |
v.awaitable_align = compute_max_align();
|
|
|
|
715 |
+ |
v.construct_commit_awaitable = &construct_commit_awaitable_impl;
|
|
|
|
716 |
+ |
v.construct_commit_eof_awaitable = &construct_commit_eof_awaitable_impl;
|
|
|
|
717 |
+ |
v.construct_write_some_awaitable = nullptr;
|
|
|
|
718 |
+ |
v.construct_write_awaitable = nullptr;
|
|
|
|
719 |
+ |
v.construct_write_eof_buffers_awaitable = nullptr;
|
|
|
|
720 |
+ |
v.construct_write_eof_awaitable = nullptr;
|
|
|
|
721 |
+ |
|
|
|
|
722 |
+ |
if constexpr (WriteSink<S>)
|
|
|
|
723 |
+ |
|
|
|
|
724 |
+ |
v.construct_write_some_awaitable =
|
|
|
|
725 |
+ |
&construct_write_some_awaitable_impl;
|
|
|
|
726 |
+ |
v.construct_write_awaitable =
|
|
|
|
727 |
+ |
&construct_write_awaitable_impl;
|
|
|
|
728 |
+ |
v.construct_write_eof_buffers_awaitable =
|
|
|
|
729 |
+ |
&construct_write_eof_buffers_awaitable_impl;
|
|
|
|
730 |
+ |
v.construct_write_eof_awaitable =
|
|
|
|
731 |
+ |
&construct_write_eof_awaitable_impl;
|
|
|
|
732 |
+ |
|
|
|
|
733 |
+ |
|
|
|
|
734 |
+ |
|
|
|
|
735 |
+ |
|
|
|
|
736 |
+ |
static constexpr vtable value = make_vtable();
|
| 455 |
|
|
737 |
|
|
| 456 |
|
|
738 |
|
|
| 457 |
|
//----------------------------------------------------------
|
739 |
|
//----------------------------------------------------------
|
| 458 |
|
|
740 |
|
|
| 459 |
|
|
741 |
|
|
| 460 |
|
any_buffer_sink::~any_buffer_sink()
|
742 |
|
any_buffer_sink::~any_buffer_sink()
|
| 461 |
|
|
743 |
|
|
| 462 |
|
|
744 |
|
|
| 463 |
|
|
745 |
|
|
| 464 |
|
|
746 |
|
|
| 465 |
|
::operator delete(storage_);
|
747 |
|
::operator delete(storage_);
|
| 466 |
|
|
748 |
|
|
| 467 |
|
|
749 |
|
|
| 468 |
|
::operator delete(cached_awaitable_);
|
750 |
|
::operator delete(cached_awaitable_);
|
| 469 |
|
|
751 |
|
|
| 470 |
|
|
752 |
|
|
| 471 |
|
|
753 |
|
|
| 472 |
|
any_buffer_sink::operator=(any_buffer_sink&& other) noexcept
|
754 |
|
any_buffer_sink::operator=(any_buffer_sink&& other) noexcept
|
| 473 |
|
|
755 |
|
|
| 474 |
|
|
756 |
|
|
| 475 |
|
|
757 |
|
|
| 476 |
|
|
758 |
|
|
| 477 |
|
|
759 |
|
|
| 478 |
|
|
760 |
|
|
| 479 |
|
::operator delete(storage_);
|
761 |
|
::operator delete(storage_);
|
| 480 |
|
|
762 |
|
|
| 481 |
|
|
763 |
|
|
| 482 |
|
::operator delete(cached_awaitable_);
|
764 |
|
::operator delete(cached_awaitable_);
|
| 483 |
|
sink_ = std::exchange(other.sink_, nullptr);
|
765 |
|
sink_ = std::exchange(other.sink_, nullptr);
|
| 484 |
|
vt_ = std::exchange(other.vt_, nullptr);
|
766 |
|
vt_ = std::exchange(other.vt_, nullptr);
|
| 485 |
|
cached_awaitable_ = std::exchange(other.cached_awaitable_, nullptr);
|
767 |
|
cached_awaitable_ = std::exchange(other.cached_awaitable_, nullptr);
|
| 486 |
|
storage_ = std::exchange(other.storage_, nullptr);
|
768 |
|
storage_ = std::exchange(other.storage_, nullptr);
|
| 487 |
|
active_ops_ = std::exchange(other.active_ops_, nullptr);
|
769 |
|
active_ops_ = std::exchange(other.active_ops_, nullptr);
|
|
|
|
770 |
+ |
active_write_ops_ = std::exchange(other.active_write_ops_, nullptr);
|
| 488 |
|
|
771 |
|
|
| 489 |
|
|
772 |
|
|
| 490 |
|
|
773 |
|
|
| 491 |
|
|
774 |
|
|
| 492 |
|
|
775 |
|
|
| 493 |
|
requires (!std::same_as<std::decay_t<S>, any_buffer_sink>)
|
776 |
|
requires (!std::same_as<std::decay_t<S>, any_buffer_sink>)
|
| 494 |
|
any_buffer_sink::any_buffer_sink(S s)
|
777 |
|
any_buffer_sink::any_buffer_sink(S s)
|
| 495 |
|
: vt_(&vtable_for_impl<S>::value)
|
778 |
|
: vt_(&vtable_for_impl<S>::value)
|
| 496 |
|
|
779 |
|
|
| 497 |
|
|
780 |
|
|
| 498 |
|
|
781 |
|
|
| 499 |
|
|
782 |
|
|
| 500 |
|
|
783 |
|
|
| 501 |
|
if(!committed && self->storage_) {
|
784 |
|
if(!committed && self->storage_) {
|
| 502 |
|
self->vt_->destroy(self->sink_);
|
785 |
|
self->vt_->destroy(self->sink_);
|
| 503 |
|
::operator delete(self->storage_);
|
786 |
|
::operator delete(self->storage_);
|
| 504 |
|
self->storage_ = nullptr;
|
787 |
|
self->storage_ = nullptr;
|
| 505 |
|
|
788 |
|
|
| 506 |
|
|
789 |
|
|
| 507 |
|
|
790 |
|
|
| 508 |
|
|
791 |
|
|
| 509 |
|
|
792 |
|
|
| 510 |
|
storage_ = ::operator new(sizeof(S));
|
793 |
|
storage_ = ::operator new(sizeof(S));
|
| 511 |
|
sink_ = ::new(storage_) S(std::move(s));
|
794 |
|
sink_ = ::new(storage_) S(std::move(s));
|
| 512 |
- |
// Preallocate the awaitable storage (sized for max of commit/eof)
|
|
|
|
| 513 |
|
|
795 |
|
|
| 514 |
|
cached_awaitable_ = ::operator new(vt_->awaitable_size);
|
796 |
|
cached_awaitable_ = ::operator new(vt_->awaitable_size);
|
| 515 |
|
|
797 |
|
|
| 516 |
|
|
798 |
|
|
| 517 |
|
|
799 |
|
|
| 518 |
|
|
800 |
|
|
| 519 |
|
|
801 |
|
|
| 520 |
|
any_buffer_sink::any_buffer_sink(S* s)
|
802 |
|
any_buffer_sink::any_buffer_sink(S* s)
|
| 521 |
|
|
803 |
|
|
| 522 |
|
, vt_(&vtable_for_impl<S>::value)
|
804 |
|
, vt_(&vtable_for_impl<S>::value)
|
| 523 |
- |
// Preallocate the awaitable storage (sized for max of commit/eof)
|
|
|
|
| 524 |
|
|
805 |
|
|
| 525 |
|
cached_awaitable_ = ::operator new(vt_->awaitable_size);
|
806 |
|
cached_awaitable_ = ::operator new(vt_->awaitable_size);
|
| 526 |
|
|
807 |
|
|
| 527 |
|
|
808 |
|
|
| 528 |
|
//----------------------------------------------------------
|
809 |
|
//----------------------------------------------------------
|
| 529 |
|
|
810 |
|
|
| 530 |
|
inline std::span<mutable_buffer>
|
811 |
|
inline std::span<mutable_buffer>
|
| 531 |
|
any_buffer_sink::prepare(std::span<mutable_buffer> dest)
|
812 |
|
any_buffer_sink::prepare(std::span<mutable_buffer> dest)
|
| 532 |
|
|
813 |
|
|
| 533 |
|
return vt_->do_prepare(sink_, dest);
|
814 |
|
return vt_->do_prepare(sink_, dest);
|
| 534 |
|
|
815 |
|
|
| 535 |
|
|
816 |
|
|
| 536 |
|
|
817 |
|
|
| 537 |
- |
any_buffer_sink::commit(std::size_t n, bool eof)
|
818 |
+ |
any_buffer_sink::commit(std::size_t n)
|
| 538 |
|
|
819 |
|
|
| 539 |
|
|
820 |
|
|
| 540 |
|
|
821 |
|
|
| 541 |
|
|
822 |
|
|
| 542 |
- |
|
|
|
|
| 543 |
|
|
823 |
|
|
| 544 |
|
|
824 |
|
|
| 545 |
|
|
825 |
|
|
| 546 |
- |
await_ready() const noexcept
|
826 |
+ |
|
| 547 |
|
|
827 |
|
|
| 548 |
- |
|
828 |
+ |
self_->active_ops_ = self_->vt_->construct_commit_awaitable(
|
|
|
|
829 |
+ |
|
|
|
|
830 |
+ |
self_->cached_awaitable_,
|
|
|
|
831 |
+ |
|
|
|
|
832 |
+ |
return self_->active_ops_->await_ready(self_->cached_awaitable_);
|
| 549 |
|
|
833 |
|
|
| 550 |
|
|
834 |
|
|
| 551 |
|
|
835 |
|
|
| 552 |
|
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
836 |
|
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
| 553 |
|
|
837 |
|
|
| 554 |
- |
// Construct the underlying awaitable into cached storage
|
838 |
+ |
return self_->active_ops_->await_suspend(
|
| 555 |
- |
self_->active_ops_ = self_->vt_->construct_commit_awaitable(
|
839 |
+ |
self_->cached_awaitable_, h, ex, token);
|
|
|
|
840 |
+ |
|
|
|
|
841 |
+ |
|
|
|
|
842 |
+ |
|
|
|
|
843 |
+ |
|
|
|
|
844 |
+ |
|
|
|
|
845 |
+ |
|
|
|
|
846 |
+ |
|
|
|
|
847 |
+ |
|
|
|
|
848 |
+ |
self->active_ops_->destroy(self->cached_awaitable_);
|
|
|
|
849 |
+ |
self->active_ops_ = nullptr;
|
|
|
|
850 |
+ |
|
|
|
|
851 |
+ |
|
|
|
|
852 |
+ |
return self_->active_ops_->await_resume(
|
|
|
|
853 |
+ |
self_->cached_awaitable_);
|
|
|
|
854 |
+ |
|
|
|
|
855 |
+ |
|
|
|
|
856 |
+ |
return awaitable{this, n};
|
|
|
|
857 |
+ |
|
|
|
|
858 |
+ |
|
|
|
|
859 |
+ |
|
|
|
|
860 |
+ |
any_buffer_sink::commit_eof(std::size_t n)
|
|
|
|
861 |
+ |
|
|
|
|
862 |
+ |
|
|
|
|
863 |
+ |
|
|
|
|
864 |
+ |
|
|
|
|
865 |
+ |
|
|
|
|
866 |
+ |
|
|
|
|
867 |
+ |
|
|
|
|
868 |
+ |
|
|
|
|
869 |
+ |
|
|
|
|
870 |
+ |
self_->active_ops_ = self_->vt_->construct_commit_eof_awaitable(
|
| 556 |
|
|
871 |
|
|
| 557 |
|
self_->cached_awaitable_,
|
872 |
|
self_->cached_awaitable_,
|
| 558 |
- |
|
873 |
+ |
|
| 559 |
- |
|
874 |
+ |
return self_->active_ops_->await_ready(self_->cached_awaitable_);
|
| 560 |
- |
|
875 |
+ |
|
| 561 |
- |
// Check if underlying is immediately ready
|
|
|
|
| 562 |
- |
if(self_->active_ops_->await_ready(self_->cached_awaitable_))
|
|
|
|
| 563 |
- |
|
|
|
|
| 564 |
|
|
876 |
|
|
| 565 |
- |
// Forward to underlying awaitable
|
877 |
+ |
|
|
|
|
878 |
+ |
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
|
|
|
879 |
+ |
|
| 566 |
|
return self_->active_ops_->await_suspend(
|
880 |
|
return self_->active_ops_->await_suspend(
|
| 567 |
|
self_->cached_awaitable_, h, ex, token);
|
881 |
|
self_->cached_awaitable_, h, ex, token);
|
| 568 |
|
|
882 |
|
|
| 569 |
|
|
883 |
|
|
| 570 |
|
|
884 |
|
|
| 571 |
|
|
885 |
|
|
| 572 |
|
|
886 |
|
|
| 573 |
|
|
887 |
|
|
| 574 |
|
|
888 |
|
|
| 575 |
|
|
889 |
|
|
| 576 |
|
self->active_ops_->destroy(self->cached_awaitable_);
|
890 |
|
self->active_ops_->destroy(self->cached_awaitable_);
|
| 577 |
|
self->active_ops_ = nullptr;
|
891 |
|
self->active_ops_ = nullptr;
|
| 578 |
|
|
892 |
|
|
| 579 |
|
|
893 |
|
|
| 580 |
|
return self_->active_ops_->await_resume(
|
894 |
|
return self_->active_ops_->await_resume(
|
| 581 |
|
self_->cached_awaitable_);
|
895 |
|
self_->cached_awaitable_);
|
| 582 |
|
|
896 |
|
|
| 583 |
|
|
897 |
|
|
| 584 |
- |
return awaitable{this, n, eof};
|
898 |
+ |
return awaitable{this, n};
|
| 585 |
|
|
899 |
|
|
| 586 |
|
|
900 |
|
|
|
|
|
901 |
+ |
//----------------------------------------------------------
|
|
|
|
902 |
+ |
// Private helpers for native WriteSink forwarding
|
|
|
|
903 |
+ |
|
| 587 |
|
|
904 |
|
|
| 588 |
- |
any_buffer_sink::commit(std::size_t n)
|
905 |
+ |
any_buffer_sink::write_some_(
|
|
|
|
906 |
+ |
std::span<const_buffer const> buffers)
|
| 589 |
|
|
907 |
|
|
| 590 |
- |
|
908 |
+ |
|
|
|
|
909 |
+ |
|
|
|
|
910 |
+ |
|
|
|
|
911 |
+ |
std::span<const_buffer const> buffers_;
|
|
|
|
912 |
+ |
|
|
|
|
913 |
+ |
|
|
|
|
914 |
+ |
await_ready() const noexcept
|
|
|
|
915 |
+ |
|
|
|
|
916 |
+ |
|
|
|
|
917 |
+ |
|
|
|
|
918 |
+ |
|
|
|
|
919 |
+ |
|
|
|
|
920 |
+ |
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
|
|
|
921 |
+ |
|
|
|
|
922 |
+ |
self_->active_write_ops_ =
|
|
|
|
923 |
+ |
self_->vt_->construct_write_some_awaitable(
|
|
|
|
924 |
+ |
|
|
|
|
925 |
+ |
self_->cached_awaitable_,
|
|
|
|
926 |
+ |
|
|
|
|
927 |
+ |
|
|
|
|
928 |
+ |
if(self_->active_write_ops_->await_ready(
|
|
|
|
929 |
+ |
self_->cached_awaitable_))
|
|
|
|
930 |
+ |
|
|
|
|
931 |
+ |
|
|
|
|
932 |
+ |
return self_->active_write_ops_->await_suspend(
|
|
|
|
933 |
+ |
self_->cached_awaitable_, h, ex, token);
|
|
|
|
934 |
+ |
|
|
|
|
935 |
+ |
|
|
|
|
936 |
+ |
|
|
|
|
937 |
+ |
|
|
|
|
938 |
+ |
|
|
|
|
939 |
+ |
|
|
|
|
940 |
+ |
|
|
|
|
941 |
+ |
|
|
|
|
942 |
+ |
self->active_write_ops_->destroy(
|
|
|
|
943 |
+ |
self->cached_awaitable_);
|
|
|
|
944 |
+ |
self->active_write_ops_ = nullptr;
|
|
|
|
945 |
+ |
|
|
|
|
946 |
+ |
|
|
|
|
947 |
+ |
return self_->active_write_ops_->await_resume(
|
|
|
|
948 |
+ |
self_->cached_awaitable_);
|
|
|
|
949 |
+ |
|
|
|
|
950 |
+ |
|
|
|
|
951 |
+ |
return awaitable{this, buffers};
|
| 591 |
|
|
952 |
|
|
| 592 |
|
|
953 |
|
|
| 593 |
|
|
954 |
|
|
| 594 |
- |
any_buffer_sink::commit_eof()
|
955 |
+ |
|
|
|
|
956 |
+ |
std::span<const_buffer const> buffers)
|
| 595 |
|
|
957 |
|
|
| 596 |
|
|
958 |
|
|
| 597 |
|
|
959 |
|
|
| 598 |
|
|
960 |
|
|
|
|
|
961 |
+ |
std::span<const_buffer const> buffers_;
|
| 599 |
|
|
962 |
|
|
| 600 |
|
|
963 |
|
|
| 601 |
|
await_ready() const noexcept
|
964 |
|
await_ready() const noexcept
|
| 602 |
|
|
965 |
|
|
| 603 |
|
|
966 |
|
|
| 604 |
|
|
967 |
|
|
| 605 |
|
|
968 |
|
|
| 606 |
|
|
969 |
|
|
| 607 |
|
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
970 |
|
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
| 608 |
|
|
971 |
|
|
| 609 |
- |
// Construct the underlying awaitable into cached storage
|
972 |
+ |
self_->active_write_ops_ =
|
| 610 |
- |
self_->active_ops_ = self_->vt_->construct_eof_awaitable(
|
973 |
+ |
self_->vt_->construct_write_awaitable(
|
| 611 |
- |
|
974 |
+ |
|
|
|
|
975 |
+ |
self_->cached_awaitable_,
|
|
|
|
976 |
+ |
|
|
|
|
977 |
+ |
|
|
|
|
978 |
+ |
if(self_->active_write_ops_->await_ready(
|
|
|
|
979 |
+ |
self_->cached_awaitable_))
|
|
|
|
980 |
+ |
|
|
|
|
981 |
+ |
|
|
|
|
982 |
+ |
return self_->active_write_ops_->await_suspend(
|
|
|
|
983 |
+ |
self_->cached_awaitable_, h, ex, token);
|
|
|
|
984 |
+ |
|
|
|
|
985 |
+ |
|
|
|
|
986 |
+ |
|
|
|
|
987 |
+ |
|
|
|
|
988 |
+ |
|
|
|
|
989 |
+ |
|
|
|
|
990 |
+ |
|
|
|
|
991 |
+ |
|
|
|
|
992 |
+ |
self->active_write_ops_->destroy(
|
|
|
|
993 |
+ |
self->cached_awaitable_);
|
|
|
|
994 |
+ |
self->active_write_ops_ = nullptr;
|
|
|
|
995 |
+ |
|
|
|
|
996 |
+ |
|
|
|
|
997 |
+ |
return self_->active_write_ops_->await_resume(
|
| 612 |
|
self_->cached_awaitable_);
|
998 |
|
self_->cached_awaitable_);
|
|
|
|
999 |
+ |
|
|
|
|
1000 |
+ |
|
|
|
|
1001 |
+ |
return awaitable{this, buffers};
|
|
|
|
1002 |
+ |
|
| 613 |
|
|
1003 |
|
|
| 614 |
- |
// Check if underlying is immediately ready
|
1004 |
+ |
|
| 615 |
- |
if(self_->active_ops_->await_ready(self_->cached_awaitable_))
|
1005 |
+ |
any_buffer_sink::write_eof_buffers_(
|
|
|
|
1006 |
+ |
std::span<const_buffer const> buffers)
|
|
|
|
1007 |
+ |
|
|
|
|
1008 |
+ |
|
|
|
|
1009 |
+ |
|
|
|
|
1010 |
+ |
|
|
|
|
1011 |
+ |
std::span<const_buffer const> buffers_;
|
|
|
|
1012 |
+ |
|
|
|
|
1013 |
+ |
|
|
|
|
1014 |
+ |
await_ready() const noexcept
|
|
|
|
1015 |
+ |
|
|
|
|
1016 |
+ |
|
|
|
|
1017 |
+ |
|
|
|
|
1018 |
+ |
|
|
|
|
1019 |
+ |
|
|
|
|
1020 |
+ |
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
|
|
|
1021 |
+ |
|
|
|
|
1022 |
+ |
self_->active_write_ops_ =
|
|
|
|
1023 |
+ |
self_->vt_->construct_write_eof_buffers_awaitable(
|
|
|
|
1024 |
+ |
|
|
|
|
1025 |
+ |
self_->cached_awaitable_,
|
|
|
|
1026 |
+ |
|
|
|
|
1027 |
+ |
|
|
|
|
1028 |
+ |
if(self_->active_write_ops_->await_ready(
|
|
|
|
1029 |
+ |
self_->cached_awaitable_))
|
| 616 |
|
|
1030 |
|
|
| 617 |
|
|
1031 |
|
|
| 618 |
- |
// Forward to underlying awaitable
|
1032 |
+ |
return self_->active_write_ops_->await_suspend(
|
| 619 |
- |
return self_->active_ops_->await_suspend(
|
|
|
|
| 620 |
|
self_->cached_awaitable_, h, ex, token);
|
1033 |
|
self_->cached_awaitable_, h, ex, token);
|
| 621 |
|
|
1034 |
|
|
| 622 |
|
|
1035 |
|
|
| 623 |
- |
|
1036 |
+ |
|
| 624 |
|
|
1037 |
|
|
| 625 |
|
|
1038 |
|
|
| 626 |
|
|
1039 |
|
|
| 627 |
|
|
1040 |
|
|
| 628 |
|
|
1041 |
|
|
| 629 |
- |
self->active_ops_->destroy(self->cached_awaitable_);
|
1042 |
+ |
self->active_write_ops_->destroy(
|
| 630 |
- |
self->active_ops_ = nullptr;
|
1043 |
+ |
self->cached_awaitable_);
|
|
|
|
1044 |
+ |
self->active_write_ops_ = nullptr;
|
| 631 |
|
|
1045 |
|
|
| 632 |
|
|
1046 |
|
|
| 633 |
- |
return self_->active_ops_->await_resume(
|
1047 |
+ |
return self_->active_write_ops_->await_resume(
|
| 634 |
|
self_->cached_awaitable_);
|
1048 |
|
self_->cached_awaitable_);
|
| 635 |
|
|
1049 |
|
|
| 636 |
|
|
1050 |
|
|
| 637 |
- |
|
1051 |
+ |
return awaitable{this, buffers};
|
| 638 |
|
|
1052 |
|
|
| 639 |
|
|
1053 |
|
|
| 640 |
|
//----------------------------------------------------------
|
1054 |
|
//----------------------------------------------------------
|
|
|
|
1055 |
+ |
// Public WriteSink methods
|
| 641 |
|
|
1056 |
|
|
| 642 |
|
template<ConstBufferSequence CB>
|
1057 |
|
template<ConstBufferSequence CB>
|
| 643 |
- |
task<io_result<std::size_t>>
|
1058 |
+ |
|
| 644 |
- |
any_buffer_sink::write(CB buffers)
|
1059 |
+ |
any_buffer_sink::write_some(CB buffers)
|
| 645 |
|
|
1060 |
|
|
| 646 |
- |
return write(buffers, false);
|
1061 |
+ |
buffer_param<CB> bp(buffers);
|
|
|
|
1062 |
+ |
|
|
|
|
1063 |
+ |
|
|
|
|
1064 |
+ |
|
|
|
|
1065 |
+ |
|
|
|
|
1066 |
+ |
|
|
|
|
1067 |
+ |
if(vt_->construct_write_some_awaitable)
|
|
|
|
1068 |
+ |
co_return co_await write_some_(src);
|
|
|
|
1069 |
+ |
|
|
|
|
1070 |
+ |
// Synthesized path: prepare + buffer_copy + commit
|
|
|
|
1071 |
+ |
mutable_buffer arr[detail::max_iovec_];
|
|
|
|
1072 |
+ |
auto dst_bufs = prepare(arr);
|
|
|
|
1073 |
+ |
|
|
|
|
1074 |
+ |
|
|
|
|
1075 |
+ |
auto [ec] = co_await commit(0);
|
|
|
|
1076 |
+ |
|
|
|
|
1077 |
+ |
|
|
|
|
1078 |
+ |
|
|
|
|
1079 |
+ |
|
|
|
|
1080 |
+ |
|
|
|
|
1081 |
+ |
|
|
|
|
1082 |
+ |
|
|
|
|
1083 |
+ |
auto n = buffer_copy(dst_bufs, src);
|
|
|
|
1084 |
+ |
auto [ec] = co_await commit(n);
|
|
|
|
1085 |
+ |
|
|
|
|
1086 |
+ |
|
|
|
|
1087 |
+ |
|
| 647 |
|
|
1088 |
|
|
| 648 |
|
|
1089 |
|
|
| 649 |
|
template<ConstBufferSequence CB>
|
1090 |
|
template<ConstBufferSequence CB>
|
| 650 |
- |
task<io_result<std::size_t>>
|
1091 |
+ |
|
| 651 |
- |
any_buffer_sink::write(CB buffers, bool eof)
|
1092 |
+ |
any_buffer_sink::write(CB buffers)
|
| 652 |
|
|
1093 |
|
|
| 653 |
|
buffer_param<CB> bp(buffers);
|
1094 |
|
buffer_param<CB> bp(buffers);
|
| 654 |
|
|
1095 |
|
|
| 655 |
|
|
1096 |
|
|
|
|
|
1097 |
+ |
|
|
|
|
1098 |
+ |
if(vt_->construct_write_awaitable)
|
|
|
|
1099 |
+ |
|
|
|
|
1100 |
+ |
|
|
|
|
1101 |
+ |
|
|
|
|
1102 |
+ |
|
|
|
|
1103 |
+ |
|
|
|
|
1104 |
+ |
|
|
|
|
1105 |
+ |
|
|
|
|
1106 |
+ |
auto [ec, n] = co_await write_(bufs);
|
|
|
|
1107 |
+ |
|
|
|
|
1108 |
+ |
|
|
|
|
1109 |
+ |
|
|
|
|
1110 |
+ |
|
|
|
|
1111 |
+ |
|
|
|
|
1112 |
+ |
|
|
|
|
1113 |
+ |
|
|
|
|
1114 |
+ |
|
|
|
|
1115 |
+ |
// Synthesized path: prepare + buffer_copy + commit
|
| 656 |
|
|
1116 |
|
|
| 657 |
|
|
1117 |
|
|
| 658 |
|
|
1118 |
|
|
| 659 |
|
|
1119 |
|
|
| 660 |
|
|
1120 |
|
|
| 661 |
|
|
1121 |
|
|
| 662 |
|
mutable_buffer arr[detail::max_iovec_];
|
1122 |
|
mutable_buffer arr[detail::max_iovec_];
|
| 663 |
|
auto dst_bufs = prepare(arr);
|
1123 |
|
auto dst_bufs = prepare(arr);
|
| 664 |
|
|
1124 |
|
|
| 665 |
|
|
1125 |
|
|
| 666 |
|
auto [ec] = co_await commit(0);
|
1126 |
|
auto [ec] = co_await commit(0);
|
| 667 |
|
|
1127 |
|
|
| 668 |
|
|
1128 |
|
|
| 669 |
|
|
1129 |
|
|
| 670 |
|
|
1130 |
|
|
| 671 |
|
|
1131 |
|
|
| 672 |
|
auto n = buffer_copy(dst_bufs, src);
|
1132 |
|
auto n = buffer_copy(dst_bufs, src);
|
| 673 |
|
auto [ec] = co_await commit(n);
|
1133 |
|
auto [ec] = co_await commit(n);
|
| 674 |
|
|
1134 |
|
|
| 675 |
|
|
1135 |
|
|
| 676 |
|
|
1136 |
|
|
| 677 |
|
|
1137 |
|
|
| 678 |
|
|
1138 |
|
|
| 679 |
- |
|
|
|
|
| 680 |
- |
|
|
|
|
| 681 |
- |
auto [ec] = co_await commit_eof();
|
|
|
|
| 682 |
- |
|
|
|
|
| 683 |
- |
|
|
|
|
| 684 |
- |
|
|
|
|
| 685 |
- |
|
|
|
|
| 686 |
|
|
1139 |
|
|
| 687 |
|
|
1140 |
|
|
| 688 |
|
|
1141 |
|
|
| 689 |
|
|
1142 |
|
|
| 690 |
|
|
1143 |
|
|
| 691 |
|
any_buffer_sink::write_eof()
|
1144 |
|
any_buffer_sink::write_eof()
|
| 692 |
|
|
1145 |
|
|
| 693 |
- |
|
1146 |
+ |
|
|
|
|
1147 |
+ |
|
|
|
|
1148 |
+ |
|
|
|
|
1149 |
+ |
|
|
|
|
1150 |
+ |
|
|
|
|
1151 |
+ |
|
|
|
|
1152 |
+ |
|
|
|
|
1153 |
+ |
if(self_->vt_->construct_write_eof_awaitable)
|
|
|
|
1154 |
+ |
|
|
|
|
1155 |
+ |
// Native WriteSink: forward to underlying write_eof()
|
|
|
|
1156 |
+ |
|
|
|
|
1157 |
+ |
self_->vt_->construct_write_eof_awaitable(
|
|
|
|
1158 |
+ |
|
|
|
|
1159 |
+ |
self_->cached_awaitable_);
|
|
|
|
1160 |
+ |
|
|
|
|
1161 |
+ |
|
|
|
|
1162 |
+ |
|
|
|
|
1163 |
+ |
// Synthesized: commit_eof(0)
|
|
|
|
1164 |
+ |
|
|
|
|
1165 |
+ |
self_->vt_->construct_commit_eof_awaitable(
|
|
|
|
1166 |
+ |
|
|
|
|
1167 |
+ |
self_->cached_awaitable_,
|
|
|
|
1168 |
+ |
|
|
|
|
1169 |
+ |
|
|
|
|
1170 |
+ |
return self_->active_ops_->await_ready(
|
|
|
|
1171 |
+ |
self_->cached_awaitable_);
|
|
|
|
1172 |
+ |
|
|
|
|
1173 |
+ |
|
|
|
|
1174 |
+ |
|
|
|
|
1175 |
+ |
await_suspend(coro h, executor_ref ex, std::stop_token token)
|
|
|
|
1176 |
+ |
|
|
|
|
1177 |
+ |
return self_->active_ops_->await_suspend(
|
|
|
|
1178 |
+ |
self_->cached_awaitable_, h, ex, token);
|
|
|
|
1179 |
+ |
|
|
|
|
1180 |
+ |
|
|
|
|
1181 |
+ |
|
|
|
|
1182 |
+ |
|
|
|
|
1183 |
+ |
|
|
|
|
1184 |
+ |
|
|
|
|
1185 |
+ |
|
|
|
|
1186 |
+ |
|
|
|
|
1187 |
+ |
self->active_ops_->destroy(self->cached_awaitable_);
|
|
|
|
1188 |
+ |
self->active_ops_ = nullptr;
|
|
|
|
1189 |
+ |
|
|
|
|
1190 |
+ |
|
|
|
|
1191 |
+ |
return self_->active_ops_->await_resume(
|
|
|
|
1192 |
+ |
self_->cached_awaitable_);
|
|
|
|
1193 |
+ |
|
|
|
|
1194 |
+ |
|
|
|
|
1195 |
+ |
|
|
|
|
1196 |
+ |
|
|
|
|
1197 |
+ |
|
|
|
|
1198 |
+ |
template<ConstBufferSequence CB>
|
|
|
|
1199 |
+ |
|
|
|
|
1200 |
+ |
any_buffer_sink::write_eof(CB buffers)
|
|
|
|
1201 |
+ |
|
|
|
|
1202 |
+ |
|
|
|
|
1203 |
+ |
if(vt_->construct_write_eof_buffers_awaitable)
|
|
|
|
1204 |
+ |
|
|
|
|
1205 |
+ |
const_buffer_param<CB> bp(buffers);
|
|
|
|
1206 |
+ |
|
|
|
|
1207 |
+ |
|
|
|
|
1208 |
+ |
|
|
|
|
1209 |
+ |
|
|
|
|
1210 |
+ |
|
|
|
|
1211 |
+ |
|
|
|
|
1212 |
+ |
|
|
|
|
1213 |
+ |
auto [ec] = co_await write_eof();
|
|
|
|
1214 |
+ |
|
|
|
|
1215 |
+ |
|
|
|
|
1216 |
+ |
|
|
|
|
1217 |
+ |
|
|
|
|
1218 |
+ |
|
|
|
|
1219 |
+ |
// Last window: send atomically with EOF
|
|
|
|
1220 |
+ |
auto [ec, n] = co_await write_eof_buffers_(bufs);
|
|
|
|
1221 |
+ |
|
|
|
|
1222 |
+ |
|
|
|
|
1223 |
+ |
|
|
|
|
1224 |
+ |
|
|
|
|
1225 |
+ |
auto [ec, n] = co_await write_(bufs);
|
|
|
|
1226 |
+ |
|
|
|
|
1227 |
+ |
|
|
|
|
1228 |
+ |
|
|
|
|
1229 |
+ |
|
|
|
|
1230 |
+ |
|
|
|
|
1231 |
+ |
|
|
|
|
1232 |
+ |
|
|
|
|
1233 |
+ |
// Synthesized path: prepare + buffer_copy + commit + commit_eof
|
|
|
|
1234 |
+ |
buffer_param<CB> bp(buffers);
|
|
|
|
1235 |
+ |
|
|
|
|
1236 |
+ |
|
|
|
|
1237 |
+ |
|
|
|
|
1238 |
+ |
|
|
|
|
1239 |
+ |
|
|
|
|
1240 |
+ |
|
|
|
|
1241 |
+ |
|
|
|
|
1242 |
+ |
|
|
|
|
1243 |
+ |
mutable_buffer arr[detail::max_iovec_];
|
|
|
|
1244 |
+ |
auto dst_bufs = prepare(arr);
|
|
|
|
1245 |
+ |
|
|
|
|
1246 |
+ |
|
|
|
|
1247 |
+ |
auto [ec] = co_await commit(0);
|
|
|
|
1248 |
+ |
|
|
|
|
1249 |
+ |
|
|
|
|
1250 |
+ |
|
|
|
|
1251 |
+ |
|
|
|
|
1252 |
+ |
|
|
|
|
1253 |
+ |
auto n = buffer_copy(dst_bufs, src);
|
|
|
|
1254 |
+ |
auto [ec] = co_await commit(n);
|
|
|
|
1255 |
+ |
|
|
|
|
1256 |
+ |
|
|
|
|
1257 |
+ |
|
|
|
|
1258 |
+ |
|
|
|
|
1259 |
+ |
|
|
|
|
1260 |
+ |
|
|
|
|
1261 |
+ |
auto [ec] = co_await commit_eof(0);
|
|
|
|
1262 |
+ |
|
|
|
|
1263 |
+ |
|
|
|
|
1264 |
+ |
|
|
|
|
1265 |
+ |
|
| 694 |
|
|
1266 |
|
|
| 695 |
|
|
1267 |
|
|
| 696 |
|
//----------------------------------------------------------
|
1268 |
|
//----------------------------------------------------------
|
| 697 |
|
|
1269 |
|
|
|
|
|
1270 |
+ |
static_assert(BufferSink<any_buffer_sink>);
|
| 698 |
|
static_assert(WriteSink<any_buffer_sink>);
|
1271 |
|
static_assert(WriteSink<any_buffer_sink>);
|
| 699 |
|
|
1272 |
|
|
| 700 |
|
|
1273 |
|
|
| 701 |
|
|
1274 |
|
|
| 702 |
|
|
1275 |
|
|
| 703 |
|
|
1276 |
|
|