GCC Code Coverage Report


Directory: ./
File: libs/beast2/include/boost/beast2/impl/write.hpp
Date: 2025-12-24 17:07:59
Exec Total Coverage
Lines: 43 51 84.3%
Functions: 17 23 73.9%
Branches: 28 67 41.8%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/cppalliance/beast2
8 //
9
10 #ifndef BOOST_BEAST2_IMPL_WRITE_HPP
11 #define BOOST_BEAST2_IMPL_WRITE_HPP
12
13 #include <boost/asio/append.hpp>
14 #include <boost/asio/buffer.hpp>
15 #include <boost/asio/compose.hpp>
16 #include <boost/asio/coroutine.hpp>
17 #include <boost/asio/immediate.hpp>
18 #include <boost/system/error_code.hpp>
19 #include <boost/system/result.hpp>
20 #include <boost/http_proto/serializer.hpp>
21
22 namespace boost {
23 namespace beast2 {
24
25 namespace detail {
26
27 template<class WriteStream>
28 class write_some_op
29 : public asio::coroutine
30 {
31 using buffers_type =
32 http::serializer::const_buffers_type;
33
34 WriteStream& dest_;
35 http::serializer& sr_;
36
37 public:
38 94 write_some_op(
39 WriteStream& dest,
40 http::serializer& sr) noexcept
41 94 : dest_(dest)
42 94 , sr_(sr)
43 {
44 94 }
45
46 template<class Self>
47 void
48 376 operator()(
49 Self& self,
50 system::error_code ec = {},
51 std::size_t bytes_transferred = {})
52 {
53 376 system::result<buffers_type> rv;
54
55
3/9
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 94 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 94 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
752 BOOST_ASIO_CORO_REENTER(*this)
56 {
57
1/1
✓ Branch 1 taken 94 times.
188 self.reset_cancellation_state(
58 asio::enable_total_cancellation());
59
60
1/1
✓ Branch 1 taken 94 times.
188 rv = sr_.prepare();
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
188 if(! rv)
62 {
63 ec = rv.error();
64 BOOST_ASIO_CORO_YIELD
65 {
66 BOOST_ASIO_HANDLER_LOCATION((
67 __FILE__, __LINE__,
68 "immediate"));
69 auto io_ex = self.get_io_executor();
70 asio::async_immediate(
71 io_ex,
72 asio::append(std::move(self), ec));
73 }
74 goto upcall;
75 }
76
77
3/10
✗ Branch 3 not taken.
✓ Branch 4 taken 94 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 94 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 14 taken 94 times.
✗ Branch 15 not taken.
564 BOOST_ASIO_CORO_YIELD
78 {
79 BOOST_ASIO_HANDLER_LOCATION((
80 __FILE__, __LINE__,
81 "beast2::write_some_op"));
82
1/1
✓ Branch 1 taken 94 times.
188 dest_.async_write_some(
83 188 *rv,
84 188 std::move(self));
85 }
86
1/1
✓ Branch 1 taken 94 times.
188 sr_.consume(bytes_transferred);
87
88 188 upcall:
89
1/1
✓ Branch 1 taken 94 times.
188 self.complete(
90 ec, bytes_transferred );
91 }
92 376 }
93 };
94
95 //------------------------------------------------
96
97 template<class WriteStream>
98 class write_op
99 : public asio::coroutine
100 {
101 WriteStream& dest_;
102 http::serializer& sr_;
103 std::size_t n_ = 0;
104
105 public:
106 5 write_op(
107 WriteStream& dest,
108 http::serializer& sr) noexcept
109 5 : dest_(dest)
110 5 , sr_(sr)
111 {
112 5 }
113
114 template<class Self>
115 void
116 104 operator()(
117 Self& self,
118 system::error_code ec = {},
119 std::size_t bytes_transferred = 0)
120 {
121
3/8
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 47 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
208 BOOST_ASIO_CORO_REENTER(*this)
122 {
123
1/1
✓ Branch 1 taken 5 times.
10 self.reset_cancellation_state(asio::enable_total_cancellation());
124
125 do
126 {
127
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 47 times.
100 if(!!self.cancelled())
128 {
129 6 ec = asio::error::operation_aborted;
130
131 6 break; // goto upcall
132 }
133
134
3/10
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 47 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 14 taken 47 times.
✗ Branch 15 not taken.
282 BOOST_ASIO_CORO_YIELD
135 {
136 BOOST_ASIO_HANDLER_LOCATION((
137 __FILE__, __LINE__,
138 "beast2::write_op"));
139
1/1
✓ Branch 1 taken 47 times.
94 async_write_some(
140 94 dest_, sr_, std::move(self));
141 }
142 94 n_ += bytes_transferred;
143
144
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 46 times.
94 if(ec.failed())
145 2 break; // goto upcall
146 }
147
2/2
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 1 times.
92 while(! sr_.is_done());
148
149 // upcall:
150
1/1
✓ Branch 1 taken 5 times.
10 self.complete(ec, n_ );
151 }
152 104 }
153 };
154
155 //------------------------------------------------
156
157 #if 0
158 template<
159 class WriteStream,
160 class ReadStream,
161 class CompletionCondition>
162 class relay_some_op
163 : public asio::coroutine
164 {
165 WriteStream& dest_;
166 ReadStream& src_;
167 CompletionCondition cond_;
168 http::serializer& sr_;
169 std::size_t bytes_read_ = 0;
170
171 public:
172 relay_some_op(
173 WriteStream& dest,
174 ReadStream& src,
175 CompletionCondition const& cond,
176 http::serializer& sr) noexcept
177 : dest_(dest)
178 , src_(src)
179 , cond_(cond)
180 , sr_(sr)
181 {
182 }
183
184 template<class Self>
185 void
186 operator()(
187 Self& self,
188 system::error_code ec = {},
189 std::size_t bytes_transferred = 0)
190 {
191 urls::result<
192 http::serializer::buffers> rv;
193
194 BOOST_ASIO_CORO_REENTER(*this)
195 {
196 // Nothing to do
197 BOOST_ASSERT(! sr_.is_complete());
198
199 rv = sr_.prepare();
200 if(! rv)
201 {
202 ec = rv.error();
203 BOOST_ASIO_CORO_YIELD
204 {
205 BOOST_ASIO_HANDLER_LOCATION((
206 __FILE__, __LINE__,
207 "beast2::relay_some_op"));
208 asio::post(std::move(self));
209 }
210 goto upcall;
211 }
212
213 BOOST_ASIO_CORO_YIELD
214 {
215 BOOST_ASIO_HANDLER_LOCATION((
216 __FILE__, __LINE__,
217 "beast2::relay_some_op"));
218 dest_.async_write_some(
219 write_buffers(*rv),
220 std::move(self));
221 }
222 sr_.consume(bytes_transferred);
223
224 upcall:
225 self.complete(
226 ec, bytes_transferred );
227 }
228 }
229 };
230 #endif
231
232 } // detail
233
234 //------------------------------------------------
235
236 template<
237 class AsyncWriteStream,
238 BOOST_ASIO_COMPLETION_TOKEN_FOR(
239 void(system::error_code, std::size_t)) CompletionToken>
240 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
241 void (system::error_code, std::size_t))
242 188 async_write_some(
243 AsyncWriteStream& dest,
244 http::serializer& sr,
245 CompletionToken&& token)
246 {
247 return asio::async_compose<
248 CompletionToken,
249
1/1
✓ Branch 2 taken 94 times.
188 void(system::error_code, std::size_t)>(
250 detail::write_some_op<
251 AsyncWriteStream>{dest, sr},
252 188 token, dest);
253 }
254
255 template<
256 class AsyncWriteStream,
257 BOOST_ASIO_COMPLETION_TOKEN_FOR(
258 void(system::error_code, std::size_t)) CompletionToken>
259 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
260 void (system::error_code, std::size_t))
261 5 async_write(
262 AsyncWriteStream& dest,
263 http::serializer& sr,
264 CompletionToken&& token)
265 {
266 return asio::async_compose<
267 CompletionToken,
268
0/1
✗ Branch 2 not taken.
5 void(system::error_code, std::size_t)>(
269 detail::write_op<
270 AsyncWriteStream>{dest, sr},
271 token,
272 5 dest);
273 }
274
275 #if 0
276 template<
277 class AsyncWriteStream,
278 class AsyncReadStream,
279 class CompletionCondition,
280 BOOST_ASIO_COMPLETION_TOKEN_FOR(
281 void(system::error_code, std::size_t)) CompletionToken>
282 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
283 void (system::error_code, std::size_t))
284 async_relay_some(
285 AsyncWriteStream& dest,
286 AsyncReadStream& src,
287 CompletionCondition const& cond,
288 http::serializer& sr,
289 CompletionToken&& token)
290 {
291 return asio::async_compose<
292 CompletionToken,
293 void(system::error_code, std::size_t)>(
294 detail::relay_some_op<
295 AsyncWriteStream,
296 AsyncReadStream,
297 CompletionCondition>{
298 dest, src, cond, sr},
299 token,
300 dest,
301 src);
302 }
303 #endif
304
305 } // beast2
306 } // boost
307
308 #endif
309