diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a21492d..0c8b9752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 68: API Changes: * Change BodyReader, BodyWriter requirements +* Remove BodyReader::is_deferred Actions Required: diff --git a/doc/concept/BodyReader.qbk b/doc/concept/BodyReader.qbk index f1ee27f8..693fab35 100644 --- a/doc/concept/BodyReader.qbk +++ b/doc/concept/BodyReader.qbk @@ -45,22 +45,6 @@ In this table: A type which meets the requirements of __ConstBufferSequence__. This is the type of buffer returned by `X::get`. ] -][ - [`X::is_deferred`] - [] - [ - The type `std::true_type` if the serialization implementation - should only attempt to retrieve buffers from the reader after - the header has been serialized. Otherwise, if this type is - `std::false_type` the implementation will activate an - optimization: the first buffer produced during serialization - will contain both the header and some or all of this body. - - Implementations of [*BodyReader] for which initialization is - expensive, should use `std::false_type` here, to reduce the - latency experienced by the remote host when expecting to read - the HTTP header. - ] ][ [`X(m,ec);`] [] diff --git a/example/common/file_body.hpp b/example/common/file_body.hpp index f643061d..ca32ae35 100644 --- a/example/common/file_body.hpp +++ b/example/common/file_body.hpp @@ -98,14 +98,6 @@ class file_body::reader char buf_[4096]; // Small buffer for reading public: - // This nested type informs the serializer that it should - // wait until after sending the header to initialize the - // reader. We set this to true, otherwise opening the file - // during `init` could introduce latency which delays - // the remote endpoint from receiving the header quickly. - // - using is_deferred = std::true_type; - // The type of buffer sequence returned by `get`. // using const_buffers_type = @@ -113,8 +105,6 @@ public: // Constructor. // - // This is called after the header is serialized, because - // we declared `is_deferred` to be `std::true_type`. // `m` holds the message we are sending, which will // always have the `file_body` as the body type. // diff --git a/include/beast/http/buffer_body.hpp b/include/beast/http/buffer_body.hpp index 139f5b50..0f7a816a 100644 --- a/include/beast/http/buffer_body.hpp +++ b/include/beast/http/buffer_body.hpp @@ -96,8 +96,6 @@ struct buffer_body value_type const& body_; public: - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::const_buffers_1; diff --git a/include/beast/http/dynamic_body.hpp b/include/beast/http/dynamic_body.hpp index 501b5cd7..d4bed218 100644 --- a/include/beast/http/dynamic_body.hpp +++ b/include/beast/http/dynamic_body.hpp @@ -45,8 +45,6 @@ struct basic_dynamic_body DynamicBuffer const& body_; public: - using is_deferred = std::false_type; - using const_buffers_type = typename DynamicBuffer::const_buffers_type; diff --git a/include/beast/http/empty_body.hpp b/include/beast/http/empty_body.hpp index 35632ac9..1a109f8f 100644 --- a/include/beast/http/empty_body.hpp +++ b/include/beast/http/empty_body.hpp @@ -49,8 +49,6 @@ struct empty_body #else struct reader { - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::null_buffers; diff --git a/include/beast/http/impl/serializer.ipp b/include/beast/http/impl/serializer.ipp index 7094537a..a7768da3 100644 --- a/include/beast/http/impl/serializer.ipp +++ b/include/beast/http/impl/serializer.ipp @@ -74,12 +74,10 @@ get(error_code& ec, Visit&& visit) if(ec) return; auto result = rd_->get(ec); + if(ec == error::need_more) + goto go_header_only; if(ec) - { - // Can't use need_more when ! is_deferred - BOOST_ASSERT(ec != error::need_more); return; - } if(! result) goto go_header_only; more_ = result->second; @@ -103,10 +101,12 @@ get(error_code& ec, Visit&& visit) break; case do_body: - BOOST_ASSERT(! rd_); - rd_.emplace(m_, ec); - if(ec) - return; + if(! rd_) + { + rd_.emplace(m_, ec); + if(ec) + return; + } s_ = do_body + 1; BOOST_FALLTHROUGH; @@ -139,12 +139,10 @@ get(error_code& ec, Visit&& visit) if(ec) return; auto result = rd_->get(ec); + if(ec == error::need_more) + goto go_header_only_c; if(ec) - { - // Can't use need_more when ! is_deferred - BOOST_ASSERT(ec != error::need_more); return; - } if(! result) goto go_header_only_c; more_ = result->second; @@ -179,10 +177,12 @@ get(error_code& ec, Visit&& visit) break; case do_body_c: - BOOST_ASSERT(! rd_); - rd_.emplace(m_, ec); - if(ec) - return; + if(! rd_) + { + rd_.emplace(m_, ec); + if(ec) + return; + } s_ = do_body_c + 1; BOOST_FALLTHROUGH; diff --git a/include/beast/http/serializer.hpp b/include/beast/http/serializer.hpp index 9a6faacd..cbec4304 100644 --- a/include/beast/http/serializer.hpp +++ b/include/beast/http/serializer.hpp @@ -144,16 +144,11 @@ class serializer do_complete = 110 }; - void split(bool, std::true_type) {} - void split(bool v, std::false_type) { split_ = v; } void frdinit(std::true_type); void frdinit(std::false_type); using reader = typename Body::reader; - using is_deferred = - typename reader::is_deferred; - using ch_t = consuming_buffers; // header @@ -190,7 +185,7 @@ class serializer boost::variant v_; int s_ = do_construct; - bool split_ = is_deferred::value; + bool split_ = false; bool header_done_ = false; bool chunked_; bool close_; @@ -227,14 +222,12 @@ public: When the split feature is enabled, the implementation will write only the octets corresponding to the serialized header first. If the header has already been written, this function - will have no effect on output. This function should be called - before retrieving any buffers using @ref get, otherwise the - behavior is undefined. + will have no effect on output. */ void split(bool v) { - split(v, is_deferred{}); + split_ = v; } /** Return `true` if serialization of the header is complete. diff --git a/include/beast/http/string_body.hpp b/include/beast/http/string_body.hpp index 41df300c..7b69a654 100644 --- a/include/beast/http/string_body.hpp +++ b/include/beast/http/string_body.hpp @@ -47,8 +47,6 @@ struct string_body value_type const& body_; public: - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::const_buffers_1; diff --git a/include/beast/http/string_view_body.hpp b/include/beast/http/string_view_body.hpp index 2a37f75c..eb5960de 100644 --- a/include/beast/http/string_view_body.hpp +++ b/include/beast/http/string_view_body.hpp @@ -48,8 +48,6 @@ struct string_view_body string_view body_; public: - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::const_buffers_1; diff --git a/test/exemplars.cpp b/test/exemplars.cpp index 304d3b71..569b1176 100644 --- a/test/exemplars.cpp +++ b/test/exemplars.cpp @@ -48,14 +48,6 @@ struct Body_BodyReader { struct BodyReader { public: - /** Controls when the implementation requests buffers. - - If false, the implementation will request the first buffer - immediately and try to serialize both the header and some - or all of the body in a single buffer. - */ - using is_deferred = std::false_type; - /// The type of buffer returned by `get`. using const_buffers_type = boost::asio::const_buffers_1; diff --git a/test/http/write.cpp b/test/http/write.cpp index 6ab516ae..c36352b4 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -42,8 +42,6 @@ public: value_type const& body_; public: - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::const_buffers_1; @@ -67,7 +65,6 @@ public: }; template< - bool isDeferred, bool isSplit, bool isFinalEmpty > @@ -85,9 +82,6 @@ public: value_type const& body_; public: - using is_deferred = - std::integral_constant; - using const_buffers_type = boost::asio::const_buffers_1; @@ -220,8 +214,6 @@ public: value_type const& body_; public: - using is_deferred = std::false_type; - using const_buffers_type = boost::asio::const_buffers_1; @@ -844,14 +836,10 @@ public: yield_to( [&](yield_context yield) { - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); + testWriteStream>(yield); + testWriteStream>(yield); + testWriteStream>(yield); + testWriteStream>(yield); }); } };