Skip to content

Commit 66792f8

Browse files
committed
sync with boost.buffers changes
1 parent 28a1461 commit 66792f8

9 files changed

Lines changed: 94 additions & 41 deletions

File tree

‎example/client/burl/any_stream.hpp‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include <boost/asio/coroutine.hpp>
1717
#include <boost/asio/immediate.hpp>
1818
#include <boost/asio/steady_timer.hpp>
19-
#include <boost/buffers/prefix.hpp>
19+
#include <boost/buffers/slice.hpp>
20+
#include <boost/core/span.hpp>
2021
#include <boost/http_proto/parser.hpp>
2122
#include <boost/http_proto/serializer.hpp>
2223

@@ -55,7 +56,7 @@ class any_stream
5556

5657
virtual void
5758
async_write_some(
58-
const buffers::const_buffer_subspan& buffers,
59+
const buffers::slice_of<boost::span<buffers::const_buffer const>>& buffers,
5960
asio::any_completion_handler<void(error_code, std::size_t)>
6061
handler) override
6162
{
@@ -64,7 +65,7 @@ class any_stream
6465

6566
virtual void
6667
async_read_some(
67-
const buffers::mutable_buffer_subspan& buffers,
68+
const buffers::slice_of<boost::span<buffers::mutable_buffer const>>& buffers,
6869
asio::any_completion_handler<void(error_code, std::size_t)>
6970
handler) override
7071
{
@@ -152,7 +153,7 @@ class any_stream
152153
}
153154
BOOST_ASIO_CORO_YIELD
154155
stream_->async_write_some(
155-
buffers::prefix(buffers, wr_remain_),
156+
prefix(buffers, wr_remain_),
156157
std::move(self));
157158
wr_remain_ -= n;
158159
self.complete(ec, n);
@@ -190,7 +191,7 @@ class any_stream
190191
}
191192
BOOST_ASIO_CORO_YIELD
192193
stream_->async_read_some(
193-
buffers::prefix(buffers, rd_remain_),
194+
prefix(buffers, rd_remain_),
194195
std::move(self));
195196
rd_remain_ -= n;
196197
self.complete(ec, n);
@@ -225,12 +226,12 @@ class any_stream
225226

226227
virtual void
227228
async_write_some(
228-
const buffers::const_buffer_subspan&,
229+
const buffers::slice_of<boost::span<buffers::const_buffer const>>&,
229230
asio::any_completion_handler<void(error_code, std::size_t)>) = 0;
230231

231232
virtual void
232233
async_read_some(
233-
const buffers::mutable_buffer_subspan&,
234+
const buffers::slice_of<boost::span<buffers::mutable_buffer const>>&,
234235
asio::any_completion_handler<void(error_code, std::size_t)>) = 0;
235236

236237
virtual void async_shutdown(
@@ -239,6 +240,30 @@ class any_stream
239240
virtual ~base() = default;
240241
};
241242

243+
static
244+
buffers::slice_of<
245+
boost::span<buffers::const_buffer const>>
246+
prefix(
247+
buffers::slice_of<
248+
boost::span<buffers::const_buffer const>> bs,
249+
std::size_t n)
250+
{
251+
buffers::keep_front(bs, n);
252+
return bs;
253+
}
254+
255+
static
256+
buffers::slice_of<
257+
boost::span<buffers::mutable_buffer const>>
258+
prefix(
259+
buffers::slice_of<boost::span<
260+
buffers::mutable_buffer const>> bs,
261+
std::size_t n)
262+
{
263+
buffers::keep_front(bs, n);
264+
return bs;
265+
}
266+
242267
std::unique_ptr<base> stream_;
243268
asio::steady_timer rd_timer;
244269
asio::steady_timer wr_timer;

‎example/client/burl/multipart_form.cpp‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "multipart_form.hpp"
1111

1212
#include <boost/buffers/copy.hpp>
13-
#include <boost/buffers/prefix.hpp>
13+
#include <boost/buffers/slice.hpp>
1414
#include <boost/http_proto/file.hpp>
1515
#include <boost/system/system_error.hpp>
1616

@@ -153,13 +153,12 @@ multipart_form::source::on_read(buffers::mutable_buffer mb)
153153

154154
auto copy = [&](core::string_view sv)
155155
{
156-
auto copied = buffers::copy(
157-
mb,
158-
buffers::sans_prefix(
159-
buffers::const_buffer{ sv.data(), sv.size() },
160-
static_cast<std::size_t>(skip_)));
156+
buffers::const_buffer source(sv.data(), sv.size());
157+
buffers::trim_front(mb, static_cast<std::size_t>(skip_));
161158

162-
mb = buffers::sans_prefix(mb, copied);
159+
auto copied = buffers::copy(mb, source);
160+
161+
buffers::trim_front(mb, copied);
163162
rs.bytes += copied;
164163
skip_ += copied;
165164

@@ -189,7 +188,7 @@ multipart_form::source::on_read(buffers::mutable_buffer mb)
189188
if(rs.ec)
190189
return false;
191190

192-
mb = buffers::sans_prefix(mb, read);
191+
buffers::trim_front(mb, read);
193192
rs.bytes += read;
194193
skip_ += read;
195194

‎example/client/burl/multipart_form.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef BURL_MULTIPART_FORM_HPP
1111
#define BURL_MULTIPART_FORM_HPP
1212

13-
#include <boost/buffers/mutable_buffer.hpp>
13+
#include <boost/buffers/buffer.hpp>
1414
#include <boost/core/detail/string_view.hpp>
1515
#include <boost/http_proto/method.hpp>
1616
#include <boost/http_proto/source.hpp>

‎example/client/jsonrpc/jsonrpc/any_stream.hpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#define JSONRPC_ANY_STREAM_HPP
1212

1313
#include <boost/asio/any_completion_handler.hpp>
14-
#include <boost/buffers/const_buffer_span.hpp>
15-
#include <boost/buffers/mutable_buffer_span.hpp>
14+
#include <boost/buffers/buffer.hpp>
15+
#include <boost/core/span.hpp>
1616
#include <boost/url/url_view.hpp>
1717

1818
namespace jsonrpc {
@@ -33,12 +33,12 @@ class any_stream
3333

3434
virtual void
3535
async_write_some(
36-
const boost::buffers::const_buffer_subspan&,
36+
const boost::span<boost::buffers::const_buffer const>&,
3737
boost::asio::any_completion_handler<void(boost::system::error_code, std::size_t)>) = 0;
3838

3939
virtual void
4040
async_read_some(
41-
const boost::buffers::mutable_buffer_subspan&,
41+
const boost::span<boost::buffers::mutable_buffer const>&,
4242
boost::asio::any_completion_handler<void(boost::system::error_code, std::size_t)>) = 0;
4343

4444
virtual void

‎example/client/jsonrpc/jsonrpc/client.cpp‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class stream_impl : public any_stream
8484

8585
void
8686
async_write_some(
87-
const buffers::const_buffer_subspan& buffers,
87+
const boost::span<boost::buffers::const_buffer const>& buffers,
8888
asio::any_completion_handler<void(system::error_code, std::size_t)>
8989
handler) override
9090
{
@@ -96,7 +96,7 @@ class stream_impl : public any_stream
9696

9797
void
9898
async_read_some(
99-
const buffers::mutable_buffer_subspan& buffers,
99+
const boost::span<boost::buffers::mutable_buffer const>& buffers,
100100
asio::any_completion_handler<void(system::error_code, std::size_t)>
101101
handler) override
102102
{
@@ -250,6 +250,33 @@ class json_sink : public http_proto::sink
250250
}
251251
};
252252

253+
class json_source : public http_proto::source
254+
{
255+
json::serializer& jsr_;
256+
json::value v_;
257+
258+
public:
259+
json_source(json::serializer& jsr, json::value v)
260+
: jsr_(jsr)
261+
, v_(std::move(v))
262+
{
263+
jsr_.reset(&v_);
264+
}
265+
266+
private:
267+
results
268+
on_read(
269+
buffers::mutable_buffer b) override
270+
{
271+
results ret;
272+
ret.bytes = jsr_.read(
273+
static_cast<char*>(b.data()),
274+
b.size()).size();
275+
ret.finished = jsr_.done();
276+
return ret;
277+
}
278+
};
279+
253280
} //namespace
254281

255282
// ----------------------------------------------
@@ -288,21 +315,17 @@ class client::request_op
288315
{
289316
{
290317
auto sp = params_.storage();
291-
auto body = json::serialize(
292-
json::object
318+
json::object value(
293319
{
294-
{
295-
{ "jsonrpc", "2.0" },
296-
{ "method", method_ },
297-
{ "params", std::move(params_)},
298-
{ "id", id_ }
299-
},
300-
sp
301-
});
302-
c_.req_.set_payload_size(body.size());
303-
c_.sr_.template start<
304-
http_proto::string_body>(
305-
c_.req_, std::move(body));
320+
{ "jsonrpc", "2.0" },
321+
{ "method", method_ },
322+
{ "params", std::move(params_)},
323+
{ "id", id_ }
324+
},
325+
sp);
326+
c_.req_.set_chunked(true);
327+
c_.sr_.template start<json_source>(
328+
c_.req_, c_.jsr_, std::move(value));
306329
}
307330

308331
BOOST_ASIO_CORO_YIELD
@@ -330,8 +353,6 @@ class client::request_op
330353
auto* id = obj.if_contains("id");
331354
if(!ver || *ver != "2.0")
332355
return self.complete({ errc::version_error }, {});
333-
if(!id || *id != id_)
334-
return self.complete({ errc::id_mismatch }, {});
335356
if(err && err->is_object())
336357
{
337358
auto* code = err->get_object().if_contains("code");
@@ -350,6 +371,9 @@ class client::request_op
350371
}
351372
else if(res)
352373
{
374+
if(!id || *id != id_)
375+
return self.complete({ errc::id_mismatch }, {});
376+
353377
return self.complete({}, std::move(*res));
354378
}
355379
self.complete({ errc::invalid_response }, {});

‎example/client/jsonrpc/jsonrpc/client.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <boost/http_proto/request.hpp>
2323
#include <boost/http_proto/response_parser.hpp>
2424
#include <boost/http_proto/serializer.hpp>
25+
#include <boost/json/serializer.hpp>
2526
#include <boost/json/stream_parser.hpp>
2627
#include <boost/json/value_to.hpp>
2728
#include <boost/rts/context_fwd.hpp>
@@ -38,6 +39,7 @@ class client
3839
boost::http_proto::response_parser pr_;
3940
boost::http_proto::request req_;
4041
boost::json::stream_parser jpr_;
42+
boost::json::serializer jsr_;
4143
std::uint64_t id_ = 0;
4244

4345
public:

‎example/client/visit/CMakeLists.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES})
1616
add_executable(http_io_example_client_visit ${PFILES})
1717

1818
target_compile_definitions(http_io_example_client_visit
19-
PRIVATE BOOST_ASIO_NO_DEPRECATED)
19+
PRIVATE
20+
BOOST_ASIO_NO_DEPRECATED
21+
BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW)
2022

2123
set_property(TARGET http_io_example_client_visit
2224
PROPERTY FOLDER "examples")

‎example/client/visit/Jamfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ project
1313
<library>/boost/http_io//boost_http_io
1414
<library>/boost/url//boost_url
1515
<include>.
16+
<define>BOOST_ASIO_NO_DEPRECATED
17+
<define>BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW
1618
;
1719

1820
exe visit :

‎test/unit/buffer.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// Official repository: https://github.com/vinniefalco/http_io
88
//
99

10-
#include <boost/buffers/const_buffer.hpp>
11-
#include <boost/buffers/mutable_buffer.hpp>
10+
#include <boost/buffers/buffer.hpp>
1211
#include <boost/asio/buffer.hpp>
1312
#include <boost/static_assert.hpp>
1413

0 commit comments

Comments
 (0)