From e54626fd4e147a7ec4ee231fb520f9207689fecd Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Wed, 10 Sep 2025 09:14:07 +0000 Subject: [PATCH] sync with boost.buffers changes --- example/client/burl/any_stream.hpp | 39 +++++++++--- example/client/burl/multipart_form.cpp | 15 +++-- example/client/burl/multipart_form.hpp | 2 +- example/client/jsonrpc/jsonrpc/any_stream.hpp | 8 +-- example/client/jsonrpc/jsonrpc/client.cpp | 60 +++++++++++++------ example/client/jsonrpc/jsonrpc/client.hpp | 2 + example/client/visit/CMakeLists.txt | 3 +- example/client/visit/Jamfile | 1 + example/client/visit/main.cpp | 7 ++- test/unit/buffer.cpp | 3 +- 10 files changed, 98 insertions(+), 42 deletions(-) diff --git a/example/client/burl/any_stream.hpp b/example/client/burl/any_stream.hpp index a2ebdf6e..4bc0ee53 100644 --- a/example/client/burl/any_stream.hpp +++ b/example/client/burl/any_stream.hpp @@ -16,7 +16,8 @@ #include #include #include -#include +#include +#include #include #include @@ -55,7 +56,7 @@ class any_stream virtual void async_write_some( - const buffers::const_buffer_subspan& buffers, + const buffers::slice_of>& buffers, asio::any_completion_handler handler) override { @@ -64,7 +65,7 @@ class any_stream virtual void async_read_some( - const buffers::mutable_buffer_subspan& buffers, + const buffers::slice_of>& buffers, asio::any_completion_handler handler) override { @@ -152,7 +153,7 @@ class any_stream } BOOST_ASIO_CORO_YIELD stream_->async_write_some( - buffers::prefix(buffers, wr_remain_), + prefix(buffers, wr_remain_), std::move(self)); wr_remain_ -= n; self.complete(ec, n); @@ -190,7 +191,7 @@ class any_stream } BOOST_ASIO_CORO_YIELD stream_->async_read_some( - buffers::prefix(buffers, rd_remain_), + prefix(buffers, rd_remain_), std::move(self)); rd_remain_ -= n; self.complete(ec, n); @@ -225,12 +226,12 @@ class any_stream virtual void async_write_some( - const buffers::const_buffer_subspan&, + const buffers::slice_of>&, asio::any_completion_handler) = 0; virtual void async_read_some( - const buffers::mutable_buffer_subspan&, + const buffers::slice_of>&, asio::any_completion_handler) = 0; virtual void async_shutdown( @@ -239,6 +240,30 @@ class any_stream virtual ~base() = default; }; + static + buffers::slice_of< + boost::span> + prefix( + buffers::slice_of< + boost::span> bs, + std::size_t n) + { + buffers::keep_front(bs, n); + return bs; + } + + static + buffers::slice_of< + boost::span> + prefix( + buffers::slice_of> bs, + std::size_t n) + { + buffers::keep_front(bs, n); + return bs; + } + std::unique_ptr stream_; asio::steady_timer rd_timer; asio::steady_timer wr_timer; diff --git a/example/client/burl/multipart_form.cpp b/example/client/burl/multipart_form.cpp index 1dc59d80..61bd6a00 100644 --- a/example/client/burl/multipart_form.cpp +++ b/example/client/burl/multipart_form.cpp @@ -10,7 +10,7 @@ #include "multipart_form.hpp" #include -#include +#include #include #include @@ -153,13 +153,12 @@ multipart_form::source::on_read(buffers::mutable_buffer mb) auto copy = [&](core::string_view sv) { - auto copied = buffers::copy( - mb, - buffers::sans_prefix( - buffers::const_buffer{ sv.data(), sv.size() }, - static_cast(skip_))); + buffers::const_buffer source(sv.data(), sv.size()); + buffers::trim_front(mb, static_cast(skip_)); - mb = buffers::sans_prefix(mb, copied); + auto copied = buffers::copy(mb, source); + + buffers::trim_front(mb, copied); rs.bytes += copied; skip_ += copied; @@ -189,7 +188,7 @@ multipart_form::source::on_read(buffers::mutable_buffer mb) if(rs.ec) return false; - mb = buffers::sans_prefix(mb, read); + buffers::trim_front(mb, read); rs.bytes += read; skip_ += read; diff --git a/example/client/burl/multipart_form.hpp b/example/client/burl/multipart_form.hpp index cd92553b..e34180ea 100644 --- a/example/client/burl/multipart_form.hpp +++ b/example/client/burl/multipart_form.hpp @@ -10,7 +10,7 @@ #ifndef BURL_MULTIPART_FORM_HPP #define BURL_MULTIPART_FORM_HPP -#include +#include #include #include #include diff --git a/example/client/jsonrpc/jsonrpc/any_stream.hpp b/example/client/jsonrpc/jsonrpc/any_stream.hpp index adf9c064..bdca05a9 100644 --- a/example/client/jsonrpc/jsonrpc/any_stream.hpp +++ b/example/client/jsonrpc/jsonrpc/any_stream.hpp @@ -11,8 +11,8 @@ #define JSONRPC_ANY_STREAM_HPP #include -#include -#include +#include +#include #include namespace jsonrpc { @@ -33,12 +33,12 @@ class any_stream virtual void async_write_some( - const boost::buffers::const_buffer_subspan&, + const boost::span&, boost::asio::any_completion_handler) = 0; virtual void async_read_some( - const boost::buffers::mutable_buffer_subspan&, + const boost::span&, boost::asio::any_completion_handler) = 0; virtual void diff --git a/example/client/jsonrpc/jsonrpc/client.cpp b/example/client/jsonrpc/jsonrpc/client.cpp index 7a87bd27..284dbefd 100644 --- a/example/client/jsonrpc/jsonrpc/client.cpp +++ b/example/client/jsonrpc/jsonrpc/client.cpp @@ -84,7 +84,7 @@ class stream_impl : public any_stream void async_write_some( - const buffers::const_buffer_subspan& buffers, + const boost::span& buffers, asio::any_completion_handler handler) override { @@ -96,7 +96,7 @@ class stream_impl : public any_stream void async_read_some( - const buffers::mutable_buffer_subspan& buffers, + const boost::span& buffers, asio::any_completion_handler handler) override { @@ -250,6 +250,33 @@ class json_sink : public http_proto::sink } }; +class json_source : public http_proto::source +{ + json::serializer& jsr_; + json::value v_; + +public: + json_source(json::serializer& jsr, json::value v) + : jsr_(jsr) + , v_(std::move(v)) + { + jsr_.reset(&v_); + } + +private: + results + on_read( + buffers::mutable_buffer b) override + { + results ret; + ret.bytes = jsr_.read( + static_cast(b.data()), + b.size()).size(); + ret.finished = jsr_.done(); + return ret; + } +}; + } //namespace // ---------------------------------------------- @@ -288,21 +315,17 @@ class client::request_op { { auto sp = params_.storage(); - auto body = json::serialize( - json::object + json::object value( { - { - { "jsonrpc", "2.0" }, - { "method", method_ }, - { "params", std::move(params_)}, - { "id", id_ } - }, - sp - }); - c_.req_.set_payload_size(body.size()); - c_.sr_.template start< - http_proto::string_body>( - c_.req_, std::move(body)); + { "jsonrpc", "2.0" }, + { "method", method_ }, + { "params", std::move(params_)}, + { "id", id_ } + }, + sp); + c_.req_.set_chunked(true); + c_.sr_.template start( + c_.req_, c_.jsr_, std::move(value)); } BOOST_ASIO_CORO_YIELD @@ -330,8 +353,6 @@ class client::request_op auto* id = obj.if_contains("id"); if(!ver || *ver != "2.0") return self.complete({ errc::version_error }, {}); - if(!id || *id != id_) - return self.complete({ errc::id_mismatch }, {}); if(err && err->is_object()) { auto* code = err->get_object().if_contains("code"); @@ -350,6 +371,9 @@ class client::request_op } else if(res) { + if(!id || *id != id_) + return self.complete({ errc::id_mismatch }, {}); + return self.complete({}, std::move(*res)); } self.complete({ errc::invalid_response }, {}); diff --git a/example/client/jsonrpc/jsonrpc/client.hpp b/example/client/jsonrpc/jsonrpc/client.hpp index a61cd3db..36c7cb7c 100644 --- a/example/client/jsonrpc/jsonrpc/client.hpp +++ b/example/client/jsonrpc/jsonrpc/client.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ class client boost::http_proto::response_parser pr_; boost::http_proto::request req_; boost::json::stream_parser jpr_; + boost::json::serializer jsr_; std::uint64_t id_ = 0; public: diff --git a/example/client/visit/CMakeLists.txt b/example/client/visit/CMakeLists.txt index d4fd4e28..05fa5171 100644 --- a/example/client/visit/CMakeLists.txt +++ b/example/client/visit/CMakeLists.txt @@ -16,7 +16,8 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES}) add_executable(http_io_example_client_visit ${PFILES}) target_compile_definitions(http_io_example_client_visit - PRIVATE BOOST_ASIO_NO_DEPRECATED) + PRIVATE + BOOST_ASIO_NO_DEPRECATED) set_property(TARGET http_io_example_client_visit PROPERTY FOLDER "examples") diff --git a/example/client/visit/Jamfile b/example/client/visit/Jamfile index 63ddcf0d..d10b7625 100644 --- a/example/client/visit/Jamfile +++ b/example/client/visit/Jamfile @@ -13,6 +13,7 @@ project /boost/http_io//boost_http_io /boost/url//boost_url . + BOOST_ASIO_NO_DEPRECATED ; exe visit : diff --git a/example/client/visit/main.cpp b/example/client/visit/main.cpp index 35ea9b90..274ac1ca 100644 --- a/example/client/visit/main.cpp +++ b/example/client/visit/main.cpp @@ -61,8 +61,13 @@ struct worker do_resolve() { resolver.async_resolve( - boost::core::string_view(url.encoded_host()), + #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + url.encoded_host(), url.scheme(), + #else + static_cast(url.encoded_host()), + static_cast(url.scheme()), + #endif [&]( boost::system::error_code ec, resolver_type::results_type results) diff --git a/test/unit/buffer.cpp b/test/unit/buffer.cpp index 9bbed4ef..dd464fbd 100644 --- a/test/unit/buffer.cpp +++ b/test/unit/buffer.cpp @@ -7,8 +7,7 @@ // Official repository: https://github.com/vinniefalco/http_io // -#include -#include +#include #include #include