83.81% Lines (88/105) 100.00% Functions (21/21)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2026 Michael Vandeberg 3   // Copyright (c) 2026 Michael Vandeberg
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/http 8   // Official repository: https://github.com/cppalliance/http
9   // 9   //
10   10  
11   #ifndef BOOST_HTTP_TEST_WRITE_SINK_HPP 11   #ifndef BOOST_HTTP_TEST_WRITE_SINK_HPP
12   #define BOOST_HTTP_TEST_WRITE_SINK_HPP 12   #define BOOST_HTTP_TEST_WRITE_SINK_HPP
13 - #include <boost/capy/detail/config.hpp>  
14   13  
15   #include <boost/capy/buffers.hpp> 14   #include <boost/capy/buffers.hpp>
16   #include <boost/capy/buffers/buffer_copy.hpp> 15   #include <boost/capy/buffers/buffer_copy.hpp>
17   #include <boost/capy/buffers/make_buffer.hpp> 16   #include <boost/capy/buffers/make_buffer.hpp>
18   #include <coroutine> 17   #include <coroutine>
19   #include <boost/capy/ex/await_context.hpp> 18   #include <boost/capy/ex/await_context.hpp>
20   #include <boost/capy/results.hpp> 19   #include <boost/capy/results.hpp>
21   #include <boost/capy/error.hpp> 20   #include <boost/capy/error.hpp>
22   #include <boost/capy/test/fuse.hpp> 21   #include <boost/capy/test/fuse.hpp>
23   22  
24   #include <algorithm> 23   #include <algorithm>
25   #include <string> 24   #include <string>
26   #include <string_view> 25   #include <string_view>
27   26  
28   namespace boost { 27   namespace boost {
29   namespace http { 28   namespace http {
30   namespace test { 29   namespace test {
31   30  
32   /** A mock sink for testing write operations. 31   /** A mock sink for testing write operations.
33   32  
34   Use this to verify code that performs complete writes without needing 33   Use this to verify code that performs complete writes without needing
35   real I/O. Call @ref write to write data, then @ref data to retrieve 34   real I/O. Call @ref write to write data, then @ref data to retrieve
36   what was written. The associated @ref capy::test::fuse enables error injection 35   what was written. The associated @ref capy::test::fuse enables error injection
37   at controlled points. 36   at controlled points.
38   37  
39   This class satisfies the @ref WriteSink concept by providing partial 38   This class satisfies the @ref WriteSink concept by providing partial
40   writes via `write_some` (satisfying @ref WriteStream), complete 39   writes via `write_some` (satisfying @ref WriteStream), complete
41   writes via `write`, and EOF signaling via `write_eof`. 40   writes via `write`, and EOF signaling via `write_eof`.
42   41  
43   @par Thread Safety 42   @par Thread Safety
44   Not thread-safe. 43   Not thread-safe.
45   44  
46   @par Example 45   @par Example
47   @code 46   @code
48   capy::test::fuse f; 47   capy::test::fuse f;
49   write_sink ws( f ); 48   write_sink ws( f );
50   49  
51   auto r = f.armed( [&]( capy::test::fuse& ) -> task<void> { 50   auto r = f.armed( [&]( capy::test::fuse& ) -> task<void> {
52   auto [ec, n] = co_await ws.write( 51   auto [ec, n] = co_await ws.write(
53   capy::const_buffer( "Hello", 5 ) ); 52   capy::const_buffer( "Hello", 5 ) );
54   if( ec ) 53   if( ec )
55   co_return; 54   co_return;
56   auto [ec2] = co_await ws.write_eof(); 55   auto [ec2] = co_await ws.write_eof();
57   if( ec2 ) 56   if( ec2 )
58   co_return; 57   co_return;
59   // ws.data() returns "Hello" 58   // ws.data() returns "Hello"
60   } ); 59   } );
61   @endcode 60   @endcode
62   61  
63   @see capy::test::fuse, WriteSink 62   @see capy::test::fuse, WriteSink
64   */ 63   */
65   class write_sink 64   class write_sink
66   { 65   {
67   capy::test::fuse f_; 66   capy::test::fuse f_;
68   std::string data_; 67   std::string data_;
69   std::string expect_; 68   std::string expect_;
70   std::size_t max_write_size_; 69   std::size_t max_write_size_;
71   bool eof_called_ = false; 70   bool eof_called_ = false;
72   71  
73   std::error_code 72   std::error_code
HITCBC 74   1056 consume_match_() noexcept 73   1056 consume_match_() noexcept
75   { 74   {
HITCBC 76   1056 if(data_.empty() || expect_.empty()) 75   1056 if(data_.empty() || expect_.empty())
HITCBC 77   1056 return {}; 76   1056 return {};
MISUBC 78   ✗ std::size_t const n = (std::min)(data_.size(), expect_.size()); 77   ✗ std::size_t const n = (std::min)(data_.size(), expect_.size());
MISUBC 79   ✗ if(std::string_view(data_.data(), n) != 78   ✗ if(std::string_view(data_.data(), n) !=
MISUBC 80   ✗ std::string_view(expect_.data(), n)) 79   ✗ std::string_view(expect_.data(), n))
MISUBC 81   ✗ return capy::error::test_failure; 80   ✗ return capy::error::test_failure;
MISUBC 82   ✗ data_.erase(0, n); 81   ✗ data_.erase(0, n);
MISUBC 83   ✗ expect_.erase(0, n); 82   ✗ expect_.erase(0, n);
MISUBC 84   ✗ return {}; 83   ✗ return {};
85   } 84   }
86   85  
87   public: 86   public:
88   /** Construct a write sink. 87   /** Construct a write sink.
89   88  
90   @param f The capy::test::fuse used to inject errors during writes. 89   @param f The capy::test::fuse used to inject errors during writes.
91   90  
92   @param max_write_size Maximum bytes transferred per write. 91   @param max_write_size Maximum bytes transferred per write.
93   Use to simulate chunked delivery. 92   Use to simulate chunked delivery.
94   */ 93   */
HITCBC 95   402 explicit write_sink( 94   402 explicit write_sink(
96   capy::test::fuse f = {}, 95   capy::test::fuse f = {},
97   std::size_t max_write_size = std::size_t(-1)) noexcept 96   std::size_t max_write_size = std::size_t(-1)) noexcept
HITCBC 98   402 : f_(std::move(f)) 97   402 : f_(std::move(f))
HITCBC 99   402 , max_write_size_(max_write_size) 98   402 , max_write_size_(max_write_size)
100   { 99   {
HITCBC 101   402 } 100   402 }
102   101  
103   /// Return the written data as a string view. 102   /// Return the written data as a string view.
104   std::string_view 103   std::string_view
HITCBC 105   54 data() const noexcept 104   54 data() const noexcept
106   { 105   {
HITCBC 107   54 return data_; 106   54 return data_;
108   } 107   }
109   108  
110   /** Set the expected data for subsequent writes. 109   /** Set the expected data for subsequent writes.
111   110  
112   Stores the expected data and immediately tries to match 111   Stores the expected data and immediately tries to match
113   against any data already written. Matched data is consumed 112   against any data already written. Matched data is consumed
114   from both buffers. 113   from both buffers.
115   114  
116   @param sv The expected data. 115   @param sv The expected data.
117   116  
118   @return An error if existing data does not match. 117   @return An error if existing data does not match.
119   */ 118   */
120   std::error_code 119   std::error_code
121   expect(std::string_view sv) 120   expect(std::string_view sv)
122   { 121   {
123   expect_.assign(sv); 122   expect_.assign(sv);
124   return consume_match_(); 123   return consume_match_();
125   } 124   }
126   125  
127   /// Return the number of bytes written. 126   /// Return the number of bytes written.
128   std::size_t 127   std::size_t
HITCBC 129   2 size() const noexcept 128   2 size() const noexcept
130   { 129   {
HITCBC 131   2 return data_.size(); 130   2 return data_.size();
132   } 131   }
133   132  
134   /// Return whether write_eof has been called. 133   /// Return whether write_eof has been called.
135   bool 134   bool
HITCBC 136   42 eof_called() const noexcept 135   42 eof_called() const noexcept
137   { 136   {
HITCBC 138   42 return eof_called_; 137   42 return eof_called_;
139   } 138   }
140   139  
141   /// Clear all data and reset state. 140   /// Clear all data and reset state.
142   void 141   void
143   clear() noexcept 142   clear() noexcept
144   { 143   {
145   data_.clear(); 144   data_.clear();
146   expect_.clear(); 145   expect_.clear();
147   eof_called_ = false; 146   eof_called_ = false;
148   } 147   }
149   148  
150   /** Asynchronously write some data to the sink. 149   /** Asynchronously write some data to the sink.
151   150  
152   Transfers up to `capy::buffer_size( buffers )` bytes from the provided 151   Transfers up to `capy::buffer_size( buffers )` bytes from the provided
153   const buffer sequence to the internal buffer. Before every write, 152   const buffer sequence to the internal buffer. Before every write,
154   the attached @ref capy::test::fuse is consulted to possibly inject an error. 153   the attached @ref capy::test::fuse is consulted to possibly inject an error.
155   154  
156   @param buffers The const buffer sequence containing data to write. 155   @param buffers The const buffer sequence containing data to write.
157   156  
158   @return An awaitable that await-returns `(error_code,std::size_t)`. 157   @return An awaitable that await-returns `(error_code,std::size_t)`.
159   158  
160   @par Cancellation 159   @par Cancellation
161   If the environment's stop token has been requested, the write 160   If the environment's stop token has been requested, the write
162   completes immediately with `capy::error::canceled` and transfers no 161   completes immediately with `capy::error::canceled` and transfers no
163   data. An empty buffer sequence is a no-op that completes 162   data. An empty buffer sequence is a no-op that completes
164   successfully regardless of the stop token. 163   successfully regardless of the stop token.
165   164  
166   @see capy::test::fuse 165   @see capy::test::fuse
167   */ 166   */
168   template<capy::ConstBufferSequence CB> 167   template<capy::ConstBufferSequence CB>
169   auto 168   auto
HITCBC 170   38 write_some(CB buffers) 169   38 write_some(CB buffers)
171   { 170   {
172   struct awaitable 171   struct awaitable
173   { 172   {
174   write_sink* self_; 173   write_sink* self_;
175   CB buffers_; 174   CB buffers_;
176   bool canceled_ = false; 175   bool canceled_ = false;
177   176  
HITCBC 178   38 bool await_ready() const noexcept { return false; } 177   38 bool await_ready() const noexcept { return false; }
179   178  
180   // The operation completes synchronously, but await_suspend is 179   // The operation completes synchronously, but await_suspend is
181   // the only place capy::await_context is delivered (the promise's 180   // the only place capy::await_context is delivered (the promise's
182 - // transform_awaiter forwards it here). Returning false means 181 + // awaiter forwards it here). Returning false means
183   // the coroutine does not actually suspend; it resumes 182   // the coroutine does not actually suspend; it resumes
184   // immediately, having observed the stop token. See capy::await_context, 183   // immediately, having observed the stop token. See capy::await_context,
185   // ContextAwaitable. 184   // ContextAwaitable.
186   bool 185   bool
HITCBC 187   38 await_suspend( 186   38 await_suspend(
188   std::coroutine_handle<>, 187   std::coroutine_handle<>,
189   capy::await_context const* env) noexcept 188   capy::await_context const* env) noexcept
190   { 189   {
HITCBC 191   38 canceled_ = env->stop_token.stop_requested(); 190   38 canceled_ = env->stop_token.stop_requested();
HITCBC 192   38 return false; 191   38 return false;
193   } 192   }
194   193  
195   capy::results<std::size_t> 194   capy::results<std::size_t>
HITCBC 196   38 await_resume() 195   38 await_resume()
197   { 196   {
HITCBC 198   38 if(capy::buffers_empty(buffers_)) 197   38 if(capy::buffers_empty(buffers_))
MISUBC 199   ✗ return {std::error_code(), 0}; 198   ✗ return {std::error_code(), 0};
200   199  
HITCBC 201   38 if(canceled_) 200   38 if(canceled_)
MISUBC 202   ✗ return {capy::error::canceled, 0}; 201   ✗ return {capy::error::canceled, 0};
203   202  
HITCBC 204   38 auto ec = self_->f_.maybe_fail(); 203   38 auto ec = self_->f_.maybe_fail();
HITCBC 205   28 if(ec) 204   28 if(ec)
HITCBC 206   10 return {ec, 0}; 205   10 return {ec, 0};
207   206  
HITCBC 208   18 std::size_t n = capy::buffer_size(buffers_); 207   18 std::size_t n = capy::buffer_size(buffers_);
HITCBC 209   18 n = (std::min)(n, self_->max_write_size_); 208   18 n = (std::min)(n, self_->max_write_size_);
210   209  
HITCBC 211   18 std::size_t const old_size = self_->data_.size(); 210   18 std::size_t const old_size = self_->data_.size();
HITCBC 212   18 self_->data_.resize(old_size + n); 211   18 self_->data_.resize(old_size + n);
HITCBC 213   18 capy::buffer_copy(capy::make_buffer( 212   18 capy::buffer_copy(capy::make_buffer(
HITCBC 214   18 self_->data_.data() + old_size, n), buffers_, n); 213   18 self_->data_.data() + old_size, n), buffers_, n);
215   214  
HITCBC 216   18 ec = self_->consume_match_(); 215   18 ec = self_->consume_match_();
HITCBC 217   18 if(ec) 216   18 if(ec)
218   { 217   {
MISUBC 219   ✗ self_->data_.resize(old_size); 218   ✗ self_->data_.resize(old_size);
MISUBC 220   ✗ return {ec, 0}; 219   ✗ return {ec, 0};
221   } 220   }
222   221  
HITCBC 223   18 return {std::error_code(), n}; 222   18 return {std::error_code(), n};
224   } 223   }
225   }; 224   };
HITCBC 226   38 return awaitable{this, buffers}; 225   38 return awaitable{this, buffers};
227   } 226   }
228   227  
229   /** Asynchronously write data to the sink. 228   /** Asynchronously write data to the sink.
230   229  
231   Transfers all bytes from the provided const buffer sequence 230   Transfers all bytes from the provided const buffer sequence
232   to the internal buffer. Unlike @ref write_some, this ignores 231   to the internal buffer. Unlike @ref write_some, this ignores
233   `max_write_size` and writes all available data, matching the 232   `max_write_size` and writes all available data, matching the
234   @ref WriteSink semantic contract. 233   @ref WriteSink semantic contract.
235   234  
236   @par Exception Safety 235   @par Exception Safety
237   Injected I/O conditions are reported via the `error_code` 236   Injected I/O conditions are reported via the `error_code`
238   component of the result. Throws `std::system_error` only when 237   component of the result. Throws `std::system_error` only when
239   the attached @ref capy::test::fuse is in exception mode and reaches its 238   the attached @ref capy::test::fuse is in exception mode and reaches its
240   failure point; no-throw otherwise. 239   failure point; no-throw otherwise.
241   240  
242   @param buffers The const buffer sequence containing data to write. 241   @param buffers The const buffer sequence containing data to write.
243   242  
244   @return An awaitable that await-returns `(error_code,std::size_t)`. 243   @return An awaitable that await-returns `(error_code,std::size_t)`.
245   244  
246   @par Cancellation 245   @par Cancellation
247   If the environment's stop token has been requested, the write 246   If the environment's stop token has been requested, the write
248   completes immediately with `capy::error::canceled` and transfers no 247   completes immediately with `capy::error::canceled` and transfers no
249   data. 248   data.
250   249  
251   @throws std::system_error When the attached @ref capy::test::fuse is in 250   @throws std::system_error When the attached @ref capy::test::fuse is in
252   exception mode and reaches its failure point. 251   exception mode and reaches its failure point.
253   252  
254   @see capy::test::fuse 253   @see capy::test::fuse
255   */ 254   */
256   template<capy::ConstBufferSequence CB> 255   template<capy::ConstBufferSequence CB>
257   auto 256   auto
HITCBC 258   1150 write(CB buffers) 257   1150 write(CB buffers)
259   { 258   {
260   struct awaitable 259   struct awaitable
261   { 260   {
262   write_sink* self_; 261   write_sink* self_;
263   CB buffers_; 262   CB buffers_;
264   bool canceled_ = false; 263   bool canceled_ = false;
265   264  
HITCBC 266   1150 bool await_ready() const noexcept { return false; } 265   1150 bool await_ready() const noexcept { return false; }
267   266  
268   // Reads the stop token without suspending; see the comment 267   // Reads the stop token without suspending; see the comment
269   // on write_some() for details. 268   // on write_some() for details.
270   bool 269   bool
HITCBC 271   1150 await_suspend( 270   1150 await_suspend(
272   std::coroutine_handle<>, 271   std::coroutine_handle<>,
273   capy::await_context const* env) noexcept 272   capy::await_context const* env) noexcept
274   { 273   {
HITCBC 275   1150 canceled_ = env->stop_token.stop_requested(); 274   1150 canceled_ = env->stop_token.stop_requested();
HITCBC 276   1150 return false; 275   1150 return false;
277   } 276   }
278   277  
279   capy::results<std::size_t> 278   capy::results<std::size_t>
HITCBC 280   1150 await_resume() 279   1150 await_resume()
281   { 280   {
HITCBC 282   1150 if(canceled_) 281   1150 if(canceled_)
MISUBC 283   ✗ return {capy::error::canceled, 0}; 282   ✗ return {capy::error::canceled, 0};
284   283  
HITCBC 285   1150 auto ec = self_->f_.maybe_fail(); 284   1150 auto ec = self_->f_.maybe_fail();
HITCBC 286   1091 if(ec) 285   1091 if(ec)
HITCBC 287   59 return {ec, 0}; 286   59 return {ec, 0};
288   287  
HITCBC 289   1032 std::size_t n = capy::buffer_size(buffers_); 288   1032 std::size_t n = capy::buffer_size(buffers_);
HITCBC 290   1032 if(n == 0) 289   1032 if(n == 0)
MISUBC 291   ✗ return {std::error_code(), 0}; 290   ✗ return {std::error_code(), 0};
292   291  
HITCBC 293   1032 std::size_t const old_size = self_->data_.size(); 292   1032 std::size_t const old_size = self_->data_.size();
HITCBC 294   1032 self_->data_.resize(old_size + n); 293   1032 self_->data_.resize(old_size + n);
HITCBC 295   1032 capy::buffer_copy(capy::make_buffer( 294   1032 capy::buffer_copy(capy::make_buffer(
HITCBC 296   1032 self_->data_.data() + old_size, n), buffers_); 295   1032 self_->data_.data() + old_size, n), buffers_);
297   296  
HITCBC 298   1032 ec = self_->consume_match_(); 297   1032 ec = self_->consume_match_();
HITCBC 299   1032 if(ec) 298   1032 if(ec)
MISUBC 300   ✗ return {ec, n}; 299   ✗ return {ec, n};
301   300  
HITCBC 302   1032 return {std::error_code(), n}; 301   1032 return {std::error_code(), n};
303   } 302   }
304   }; 303   };
HITCBC 305   1150 return awaitable{this, buffers}; 304   1150 return awaitable{this, buffers};
306   } 305   }
307   306  
308   /** Atomically write data and signal end-of-stream. 307   /** Atomically write data and signal end-of-stream.
309   308  
310   Transfers all bytes from the provided const buffer sequence to 309   Transfers all bytes from the provided const buffer sequence to
311   the internal buffer and signals end-of-stream. Before the write, 310   the internal buffer and signals end-of-stream. Before the write,
312   the attached @ref capy::test::fuse is consulted to possibly inject an error 311   the attached @ref capy::test::fuse is consulted to possibly inject an error
313   for testing fault scenarios. 312   for testing fault scenarios.
314   313  
315   @par Effects 314   @par Effects
316   On success, appends the written bytes to the internal buffer 315   On success, appends the written bytes to the internal buffer
317   and marks the sink as finalized. 316   and marks the sink as finalized.
318   If an error is injected by the capy::test::fuse, the internal buffer remains 317   If an error is injected by the capy::test::fuse, the internal buffer remains
319   unchanged. 318   unchanged.
320   319  
321   @par Exception Safety 320   @par Exception Safety
322   Injected I/O conditions are reported via the `error_code` 321   Injected I/O conditions are reported via the `error_code`
323   component of the result. Throws `std::system_error` only when 322   component of the result. Throws `std::system_error` only when
324   the attached @ref capy::test::fuse is in exception mode and reaches its 323   the attached @ref capy::test::fuse is in exception mode and reaches its
325   failure point; no-throw otherwise. 324   failure point; no-throw otherwise.
326   325  
327   @par Cancellation 326   @par Cancellation
328   If the environment's stop token has been requested, the operation 327   If the environment's stop token has been requested, the operation
329   completes immediately with `capy::error::canceled`, transfers no data, 328   completes immediately with `capy::error::canceled`, transfers no data,
330   and does not signal end-of-stream. 329   and does not signal end-of-stream.
331   330  
332   @param buffers The const buffer sequence containing data to write. 331   @param buffers The const buffer sequence containing data to write.
333   332  
334   @return An awaitable that await-returns `(error_code,std::size_t)`. 333   @return An awaitable that await-returns `(error_code,std::size_t)`.
335   334  
336   @throws std::system_error When the attached @ref capy::test::fuse is in 335   @throws std::system_error When the attached @ref capy::test::fuse is in
337   exception mode and reaches its failure point. 336   exception mode and reaches its failure point.
338   337  
339   @see capy::test::fuse 338   @see capy::test::fuse
340   */ 339   */
341   template<capy::ConstBufferSequence CB> 340   template<capy::ConstBufferSequence CB>
342   auto 341   auto
HITCBC 343   16 write_eof(CB buffers) 342   16 write_eof(CB buffers)
344   { 343   {
345   struct awaitable 344   struct awaitable
346   { 345   {
347   write_sink* self_; 346   write_sink* self_;
348   CB buffers_; 347   CB buffers_;
349   bool canceled_ = false; 348   bool canceled_ = false;
350   349  
HITCBC 351   16 bool await_ready() const noexcept { return false; } 350   16 bool await_ready() const noexcept { return false; }
352   351  
353   // Reads the stop token without suspending; see the comment 352   // Reads the stop token without suspending; see the comment
354   // on write_some() for details. 353   // on write_some() for details.
355   bool 354   bool
HITCBC 356   16 await_suspend( 355   16 await_suspend(
357   std::coroutine_handle<>, 356   std::coroutine_handle<>,
358   capy::await_context const* env) noexcept 357   capy::await_context const* env) noexcept
359   { 358   {
HITCBC 360   16 canceled_ = env->stop_token.stop_requested(); 359   16 canceled_ = env->stop_token.stop_requested();
HITCBC 361   16 return false; 360   16 return false;
362   } 361   }
363   362  
364   capy::results<std::size_t> 363   capy::results<std::size_t>
HITCBC 365   16 await_resume() 364   16 await_resume()
366   { 365   {
HITCBC 367   16 if(canceled_) 366   16 if(canceled_)
MISUBC 368   ✗ return {capy::error::canceled, 0}; 367   ✗ return {capy::error::canceled, 0};
369   368  
HITCBC 370   16 auto ec = self_->f_.maybe_fail(); 369   16 auto ec = self_->f_.maybe_fail();
HITCBC 371   11 if(ec) 370   11 if(ec)
HITCBC 372   5 return {ec, 0}; 371   5 return {ec, 0};
373   372  
HITCBC 374   6 std::size_t n = capy::buffer_size(buffers_); 373   6 std::size_t n = capy::buffer_size(buffers_);
HITCBC 375   6 if(n > 0) 374   6 if(n > 0)
376   { 375   {
HITCBC 377   6 std::size_t const old_size = self_->data_.size(); 376   6 std::size_t const old_size = self_->data_.size();
HITCBC 378   6 self_->data_.resize(old_size + n); 377   6 self_->data_.resize(old_size + n);
HITCBC 379   6 capy::buffer_copy(capy::make_buffer( 378   6 capy::buffer_copy(capy::make_buffer(
HITCBC 380   6 self_->data_.data() + old_size, n), buffers_); 379   6 self_->data_.data() + old_size, n), buffers_);
381   380  
HITCBC 382   6 ec = self_->consume_match_(); 381   6 ec = self_->consume_match_();
HITCBC 383   6 if(ec) 382   6 if(ec)
MISUBC 384   ✗ return {ec, n}; 383   ✗ return {ec, n};
385   } 384   }
386   385  
HITCBC 387   6 self_->eof_called_ = true; 386   6 self_->eof_called_ = true;
388   387  
HITCBC 389   6 return {std::error_code(), n}; 388   6 return {std::error_code(), n};
390   } 389   }
391   }; 390   };
HITCBC 392   16 return awaitable{this, buffers}; 391   16 return awaitable{this, buffers};
393   } 392   }
394   393  
395   /** Signal end-of-stream. 394   /** Signal end-of-stream.
396   395  
397   Marks the sink as finalized, indicating no more data will be 396   Marks the sink as finalized, indicating no more data will be
398   written. Before signaling, the attached @ref capy::test::fuse is consulted 397   written. Before signaling, the attached @ref capy::test::fuse is consulted
399   to possibly inject an error for testing fault scenarios. 398   to possibly inject an error for testing fault scenarios.
400   399  
401   @par Effects 400   @par Effects
402   On success, marks the sink as finalized. 401   On success, marks the sink as finalized.
403   If an error is injected by the capy::test::fuse, the state remains unchanged. 402   If an error is injected by the capy::test::fuse, the state remains unchanged.
404   403  
405   @par Exception Safety 404   @par Exception Safety
406   Injected I/O conditions are reported via the `error_code` 405   Injected I/O conditions are reported via the `error_code`
407   component of the result. Throws `std::system_error` only when 406   component of the result. Throws `std::system_error` only when
408   the attached @ref capy::test::fuse is in exception mode and reaches its 407   the attached @ref capy::test::fuse is in exception mode and reaches its
409   failure point; no-throw otherwise. 408   failure point; no-throw otherwise.
410   409  
411   @par Cancellation 410   @par Cancellation
412   If the environment's stop token has been requested, the operation 411   If the environment's stop token has been requested, the operation
413   completes immediately with `capy::error::canceled` and does not signal 412   completes immediately with `capy::error::canceled` and does not signal
414   end-of-stream. 413   end-of-stream.
415   414  
416   @return An awaitable that await-returns `(error_code)`. 415   @return An awaitable that await-returns `(error_code)`.
417   416  
418   @throws std::system_error When the attached @ref capy::test::fuse is in 417   @throws std::system_error When the attached @ref capy::test::fuse is in
419   exception mode and reaches its failure point. 418   exception mode and reaches its failure point.
420   419  
421   @see capy::test::fuse 420   @see capy::test::fuse
422   */ 421   */
423   auto 422   auto
HITCBC 424   68 write_eof() 423   68 write_eof()
425   { 424   {
426   struct awaitable 425   struct awaitable
427   { 426   {
428   write_sink* self_; 427   write_sink* self_;
429   bool canceled_ = false; 428   bool canceled_ = false;
430   429  
HITCBC 431   68 bool await_ready() const noexcept { return false; } 430   68 bool await_ready() const noexcept { return false; }
432   431  
433   // Reads the stop token without suspending; see the comment 432   // Reads the stop token without suspending; see the comment
434   // on write_some() for details. 433   // on write_some() for details.
435   bool 434   bool
HITCBC 436   68 await_suspend( 435   68 await_suspend(
437   std::coroutine_handle<>, 436   std::coroutine_handle<>,
438   capy::await_context const* env) noexcept 437   capy::await_context const* env) noexcept
439   { 438   {
HITCBC 440   68 canceled_ = env->stop_token.stop_requested(); 439   68 canceled_ = env->stop_token.stop_requested();
HITCBC 441   68 return false; 440   68 return false;
442   } 441   }
443   442  
444   capy::results<> 443   capy::results<>
HITCBC 445   68 await_resume() 444   68 await_resume()
446   { 445   {
HITCBC 447   68 if(canceled_) 446   68 if(canceled_)
MISUBC 448   ✗ return {capy::error::canceled}; 447   ✗ return {capy::error::canceled};
449   448  
HITCBC 450   68 auto ec = self_->f_.maybe_fail(); 449   68 auto ec = self_->f_.maybe_fail();
HITCBC 451   50 if(ec) 450   50 if(ec)
HITCBC 452   18 return {ec}; 451   18 return {ec};
453   452  
HITCBC 454   32 self_->eof_called_ = true; 453   32 self_->eof_called_ = true;
HITCBC 455   32 return {}; 454   32 return {};
456   } 455   }
457   }; 456   };
HITCBC 458   68 return awaitable{this}; 457   68 return awaitable{this};
459   } 458   }
460   }; 459   };
461   460  
462   } // test 461   } // test
463   } // capy 462   } // capy
464   } // boost 463   } // boost
465   464  
466   #endif 465   #endif