diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c4ce4d9..f66aa954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ API Changes: * Refactor http::header contents * New ostream() returns dynamic buffer output stream * New buffers() replaces to_string() +* Rename to multi_buffer, basic_multi_buffer -------------------------------------------------------------------------------- diff --git a/doc/design.qbk b/doc/design.qbk index ff925b4a..7fba64ba 100644 --- a/doc/design.qbk +++ b/doc/design.qbk @@ -419,7 +419,7 @@ start. Other design goals: [``` beast::async_completion completion(handler); read_op{ - completion.handler, *this, op, streambuf}; + completion.handler, *this, op, buffer}; return completion.result.get(); ```] [ @@ -442,13 +442,13 @@ start. Other design goals: or frame data, which is of any type meeting the requirements of __DynamicBuffer__ (modeled after `boost::asio::streambuf`). - Beast comes with the class __basic_streambuf__, an efficient + Beast comes with the class __basic_multi_buffer__, an efficient implementation of the __DynamicBuffer__ concept which makes use of multiple allocated octet arrays. If an incoming message is broken up into multiple pieces, no reallocation occurs. Instead, new allocations are appended to the sequence when existing allocations are filled. Beast does not impose any particular memory management model on callers. The - __basic_streambuf__ provided by beast supports standard allocators through + __basic_multi_buffer__ provided by beast supports standard allocators through a template argument. Use the __DynamicBuffer__ that comes with beast, customize the allocator if you desire, or provide your own type that meets the requirements. diff --git a/doc/examples.qbk b/doc/examples.qbk index 5276e2b1..b7d51d0a 100644 --- a/doc/examples.qbk +++ b/doc/examples.qbk @@ -45,17 +45,17 @@ int main() beast::http::write(sock, req); // Receive and print HTTP response using beast - beast::streambuf sb; - beast::http::response resp; - beast::http::read(sock, sb, resp); - std::cout << resp; + beast::multi_buffer b; + beast::http::response res; + beast::http::read(sock, b, res); + std::cout << res; } ``` [heading WebSocket] Establish a WebSocket connection, send a message and receive the reply: ``` -#include +#include #include #include #include @@ -77,11 +77,11 @@ int main() ws.write(boost::asio::buffer(std::string("Hello, world!"))); // Receive WebSocket message, print and close using beast - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::opcode op; - ws.read(op, sb); + ws.read(op, b); ws.close(beast::websocket::close_code::normal); - std::cout << beast::to_string(sb.data()) << "\n"; + std::cout << beast::buffers(b.data()) << "\n"; } ``` diff --git a/doc/master.qbk b/doc/master.qbk index 90b697c3..9064ee4e 100644 --- a/doc/master.qbk +++ b/doc/master.qbk @@ -40,17 +40,17 @@ [def __SyncReadStream__ [@http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/SyncReadStream.html [*SyncReadStream]]] [def __SyncWriteStream__ [@http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/SyncWriteStream.html [*SyncWriteStream]]] -[def __Body__ [link beast.ref.Body [*`Body`]]] -[def __DynamicBuffer__ [link beast.ref.DynamicBuffer [*DynamicBuffer]]] -[def __FieldSequence__ [link beast.ref.FieldSequence [*FieldSequence]]] -[def __Parser__ [link beast.ref.Parser [*`Parser`]]] +[def __Body__ [link beast.ref.Body [*`Body`]]] +[def __DynamicBuffer__ [link beast.ref.DynamicBuffer [*DynamicBuffer]]] +[def __FieldSequence__ [link beast.ref.FieldSequence [*FieldSequence]]] +[def __Parser__ [link beast.ref.Parser [*`Parser`]]] -[def __basic_fields__ [link beast.ref.http__basic_fields `basic_fields`]] -[def __fields__ [link beast.ref.http__fields `fields`]] -[def __header__ [link beast.ref.http__header `header`]] -[def __message__ [link beast.ref.http__message `message`]] -[def __streambuf__ [link beast.ref.streambuf `streambuf`]] -[def __basic_streambuf__ [link beast.ref.basic_streambuf `basic_streambuf`]] +[def __basic_fields__ [link beast.ref.http__basic_fields `basic_fields`]] +[def __fields__ [link beast.ref.http__fields `fields`]] +[def __header__ [link beast.ref.http__header `header`]] +[def __message__ [link beast.ref.http__message `message`]] +[def __streambuf__ [link beast.ref.streambuf `streambuf`]] +[def __basic_multi_buffer__ [link beast.ref.basic_multi_buffer `basic_multi_buffer`]] Beast is a cross-platform, header-only C++ library built on Boost.Asio that provides implementations of the HTTP and WebSocket protocols. diff --git a/doc/quickref.xml b/doc/quickref.xml index 3c8c7f8a..8df34ed0 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -153,7 +153,7 @@ async_completion basic_flat_streambuf - basic_streambuf + basic_multi_buffer buffers_adapter consuming_buffers dynabuf_readstream @@ -164,10 +164,10 @@ flat_streambuf handler_alloc handler_ptr + multi_buffer static_streambuf static_streambuf_n static_string - streambuf system_error diff --git a/doc/websocket.qbk b/doc/websocket.qbk index b4544c24..e22bb8e3 100644 --- a/doc/websocket.qbk +++ b/doc/websocket.qbk @@ -294,13 +294,13 @@ all of the buffers representing the message are known ahead of time: ``` void echo(beast::websocket::stream& ws) { - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::opcode::value op; - ws.read(op, sb); + ws.read(op, b); ws.set_option(beast::websocket::message_type{op}); - ws.write(sb.data()); - sb.consume(sb.size()); + ws.write(b.data()); + sb.consume(b.size()); } ``` @@ -328,17 +328,17 @@ example reads and echoes a complete message using this interface: ``` void echo(beast::websocket::stream& ws) { - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::frame_info fi; for(;;) { - ws.read_frame(fi, sb); + ws.read_frame(fi, b); if(fi.fin) break; } ws.set_option(beast::websocket::message_type{fi.op}); beast::consuming_buffers< - beast::streambuf::const_buffers_type> cb{sb.data()}; + beast::streambuf::const_buffers_type> cb{b.data()}; for(;;) { using boost::asio::buffer_size; diff --git a/examples/http_async_server.hpp b/examples/http_async_server.hpp index ade2d16a..5be89d0f 100644 --- a/examples/http_async_server.hpp +++ b/examples/http_async_server.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -181,7 +181,7 @@ private: class peer : public std::enable_shared_from_this { int id_; - streambuf sb_; + multi_buffer sb_; socket_type sock_; http_async_server& server_; boost::asio::io_service::strand strand_; diff --git a/examples/http_crawl.cpp b/examples/http_crawl.cpp index 6f4a02d5..b483da36 100644 --- a/examples/http_crawl.cpp +++ b/examples/http_crawl.cpp @@ -7,7 +7,7 @@ #include "urls_large_data.hpp" -#include +#include #include #include #include @@ -46,8 +46,8 @@ int main(int, char const*[]) prepare(req); write(sock, req); response res; - streambuf sb; - beast::http::read(sock, sb, res); + beast::multi_buffer b; + beast::http::read(sock, b, res); std::cout << res; } catch(beast::system_error const& ec) diff --git a/examples/http_example.cpp b/examples/http_example.cpp index 1eccff54..6ef4e924 100644 --- a/examples/http_example.cpp +++ b/examples/http_example.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include #include #include #include @@ -33,8 +34,8 @@ int main() beast::http::write(sock, req); // Receive and print HTTP response using beast - beast::streambuf sb; - beast::http::response resp; - beast::http::read(sock, sb, resp); - std::cout << resp; + beast::multi_buffer b; + beast::http::response res; + beast::http::read(sock, b, res); + std::cout << res; } diff --git a/examples/http_sync_server.hpp b/examples/http_sync_server.hpp index 26f1b997..bbc43fad 100644 --- a/examples/http_sync_server.hpp +++ b/examples/http_sync_server.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -150,12 +150,12 @@ private: do_peer(int id, socket_type&& sock0) { socket_type sock(std::move(sock0)); - streambuf sb; + multi_buffer b; error_code ec; for(;;) { req_type req; - http::read(sock, sb, req, ec); + http::read(sock, b, req, ec); if(ec) break; auto path = req.target().to_string(); diff --git a/examples/ssl/http_ssl_example.cpp b/examples/ssl/http_ssl_example.cpp index 86005604..6ea542bd 100644 --- a/examples/ssl/http_ssl_example.cpp +++ b/examples/ssl/http_ssl_example.cpp @@ -45,9 +45,9 @@ int main() beast::http::write(stream, req); // Receive and print HTTP response using Beast - beast::streambuf sb; + beast::multi_buffer b; beast::http::response resp; - beast::http::read(stream, sb, resp); + beast::http::read(stream, b, resp); std::cout << resp; // Shut down SSL on the stream diff --git a/examples/ssl/websocket_ssl_example.cpp b/examples/ssl/websocket_ssl_example.cpp index 214d1833..466758c9 100644 --- a/examples/ssl/websocket_ssl_example.cpp +++ b/examples/ssl/websocket_ssl_example.cpp @@ -41,9 +41,9 @@ int main() ws.write(boost::asio::buffer("Hello, world!")); // Receive Secure WebSocket message, print and close using Beast - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::opcode op; - ws.read(op, sb); + ws.read(op, b); ws.close(beast::websocket::close_code::normal); - std::cout << beast::buffers(sb.data()) << "\n"; + std::cout << beast::buffers(b.data()) << "\n"; } diff --git a/examples/websocket_async_echo_server.hpp b/examples/websocket_async_echo_server.hpp index e6ed81ef..e7fda7c2 100644 --- a/examples/websocket_async_echo_server.hpp +++ b/examples/websocket_async_echo_server.hpp @@ -9,7 +9,7 @@ #define WEBSOCKET_ASYNC_ECHO_SERVER_HPP #include -#include +#include #include #include #include @@ -216,7 +216,7 @@ private: beast::websocket::stream ws; boost::asio::io_service::strand strand; beast::websocket::opcode op; - beast::streambuf db; + beast::multi_buffer db; std::size_t id; data(async_echo_server& server_, diff --git a/examples/websocket_example.cpp b/examples/websocket_example.cpp index 3d7547f6..7d69e614 100644 --- a/examples/websocket_example.cpp +++ b/examples/websocket_example.cpp @@ -5,7 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include +#include #include #include #include @@ -27,9 +27,9 @@ int main() ws.write(boost::asio::buffer(std::string("Hello, world!"))); // Receive WebSocket message, print and close using beast - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::opcode op; - ws.read(op, sb); + ws.read(op, b); ws.close(beast::websocket::close_code::normal); - std::cout << beast::buffers(sb.data()) << "\n"; + std::cout << beast::buffers(b.data()) << "\n"; } diff --git a/examples/websocket_sync_echo_server.hpp b/examples/websocket_sync_echo_server.hpp index ab8bd5d5..7ffdc358 100644 --- a/examples/websocket_sync_echo_server.hpp +++ b/examples/websocket_sync_echo_server.hpp @@ -9,7 +9,7 @@ #define WEBSOCKET_SYNC_ECHO_SERVER_HPP #include -#include +#include #include #include #include @@ -287,15 +287,15 @@ private: for(;;) { beast::websocket::opcode op; - beast::streambuf sb; - ws.read(op, sb, ec); + beast::multi_buffer b; + ws.read(op, b, ec); if(ec) { auto const s = ec.message(); break; } ws.set_option(beast::websocket::message_type{op}); - ws.write(sb.data(), ec); + ws.write(b.data(), ec); if(ec) break; } diff --git a/include/beast/core.hpp b/include/beast/core.hpp index 75c27f07..7f7f369f 100644 --- a/include/beast/core.hpp +++ b/include/beast/core.hpp @@ -23,12 +23,12 @@ #include #include #include +#include #include #include #include #include #include #include -#include #endif diff --git a/include/beast/core/dynabuf_readstream.hpp b/include/beast/core/dynabuf_readstream.hpp index e749ba01..eb34c01c 100644 --- a/include/beast/core/dynabuf_readstream.hpp +++ b/include/beast/core/dynabuf_readstream.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/beast/core/impl/streambuf.ipp b/include/beast/core/impl/multi_buffer.ipp similarity index 83% rename from include/beast/core/impl/streambuf.ipp rename to include/beast/core/impl/multi_buffer.ipp index ec51615f..a2860090 100644 --- a/include/beast/core/impl/streambuf.ipp +++ b/include/beast/core/impl/multi_buffer.ipp @@ -5,8 +5,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BEAST_IMPL_STREAMBUF_IPP -#define BEAST_IMPL_STREAMBUF_IPP +#ifndef BEAST_IMPL_MULTI_BUFFER_IPP +#define BEAST_IMPL_MULTI_BUFFER_IPP #include #include @@ -83,7 +83,7 @@ namespace beast { */ template -class basic_streambuf::element +class basic_multi_buffer::element : public boost::intrusive::list_base_hook< boost::intrusive::link_mode< boost::intrusive::normal_link>> @@ -117,14 +117,14 @@ public: }; template -class basic_streambuf::const_buffers_type +class basic_multi_buffer::const_buffers_type { - basic_streambuf const* sb_; + basic_multi_buffer const* sb_; - friend class basic_streambuf; + friend class basic_multi_buffer; explicit - const_buffers_type(basic_streambuf const& sb); + const_buffers_type(basic_multi_buffer const& b); public: // Why? @@ -144,14 +144,14 @@ public: }; template -class basic_streambuf::mutable_buffers_type +class basic_multi_buffer::mutable_buffers_type { - basic_streambuf const* sb_; + basic_multi_buffer const* sb_; - friend class basic_streambuf; + friend class basic_multi_buffer; explicit - mutable_buffers_type(basic_streambuf const& sb); + mutable_buffers_type(basic_multi_buffer const& b); public: using value_type = mutable_buffer; @@ -172,9 +172,9 @@ public: //------------------------------------------------------------------------------ template -class basic_streambuf::const_buffers_type::const_iterator +class basic_multi_buffer::const_buffers_type::const_iterator { - basic_streambuf const* sb_ = nullptr; + basic_multi_buffer const* sb_ = nullptr; typename list_type::const_iterator it_; public: @@ -192,9 +192,9 @@ public: const_iterator& operator=(const_iterator&& other) = default; const_iterator& operator=(const_iterator const& other) = default; - const_iterator(basic_streambuf const& sb, + const_iterator(basic_multi_buffer const& b, typename list_type::const_iterator const& it) - : sb_(&sb) + : sb_(&b) , it_(it) { } @@ -256,15 +256,15 @@ public: }; template -basic_streambuf::const_buffers_type::const_buffers_type( - basic_streambuf const& sb) - : sb_(&sb) +basic_multi_buffer::const_buffers_type::const_buffers_type( + basic_multi_buffer const& b) + : sb_(&b) { } template auto -basic_streambuf::const_buffers_type::begin() const -> +basic_multi_buffer::const_buffers_type::begin() const -> const_iterator { return const_iterator{*sb_, sb_->list_.begin()}; @@ -272,7 +272,7 @@ basic_streambuf::const_buffers_type::begin() const -> template auto -basic_streambuf::const_buffers_type::end() const -> +basic_multi_buffer::const_buffers_type::end() const -> const_iterator { return const_iterator{*sb_, sb_->out_ == @@ -283,9 +283,9 @@ basic_streambuf::const_buffers_type::end() const -> //------------------------------------------------------------------------------ template -class basic_streambuf::mutable_buffers_type::const_iterator +class basic_multi_buffer::mutable_buffers_type::const_iterator { - basic_streambuf const* sb_ = nullptr; + basic_multi_buffer const* sb_ = nullptr; typename list_type::const_iterator it_; public: @@ -303,9 +303,9 @@ public: const_iterator& operator=(const_iterator&& other) = default; const_iterator& operator=(const_iterator const& other) = default; - const_iterator(basic_streambuf const& sb, + const_iterator(basic_multi_buffer const& b, typename list_type::const_iterator const& it) - : sb_(&sb) + : sb_(&b) , it_(it) { } @@ -367,15 +367,15 @@ public: }; template -basic_streambuf::mutable_buffers_type::mutable_buffers_type( - basic_streambuf const& sb) - : sb_(&sb) +basic_multi_buffer::mutable_buffers_type::mutable_buffers_type( + basic_multi_buffer const& b) + : sb_(&b) { } template auto -basic_streambuf::mutable_buffers_type::begin() const -> +basic_multi_buffer::mutable_buffers_type::begin() const -> const_iterator { return const_iterator{*sb_, sb_->out_}; @@ -383,7 +383,7 @@ basic_streambuf::mutable_buffers_type::begin() const -> template auto -basic_streambuf::mutable_buffers_type::end() const -> +basic_multi_buffer::mutable_buffers_type::end() const -> const_iterator { return const_iterator{*sb_, sb_->list_.end()}; @@ -392,14 +392,14 @@ basic_streambuf::mutable_buffers_type::end() const -> //------------------------------------------------------------------------------ template -basic_streambuf::~basic_streambuf() +basic_multi_buffer::~basic_multi_buffer() { delete_list(); } template -basic_streambuf:: -basic_streambuf(basic_streambuf&& other) +basic_multi_buffer:: +basic_multi_buffer(basic_multi_buffer&& other) : detail::empty_base_optimization( std::move(other.member())) , alloc_size_(other.alloc_size_) @@ -420,10 +420,10 @@ basic_streambuf(basic_streambuf&& other) } template -basic_streambuf:: -basic_streambuf(basic_streambuf&& other, +basic_multi_buffer:: +basic_multi_buffer(basic_multi_buffer&& other, allocator_type const& alloc) - : basic_streambuf(other.alloc_size_, alloc) + : basic_multi_buffer(other.alloc_size_, alloc) { using boost::asio::buffer_copy; if(this->member() != other.member()) @@ -434,8 +434,8 @@ basic_streambuf(basic_streambuf&& other, template auto -basic_streambuf::operator=( - basic_streambuf&& other) -> basic_streambuf& +basic_multi_buffer::operator=( + basic_multi_buffer&& other) -> basic_multi_buffer& { if(this == &other) return *this; @@ -448,28 +448,28 @@ basic_streambuf::operator=( } template -basic_streambuf:: -basic_streambuf(basic_streambuf const& other) - : basic_streambuf(other.alloc_size_, +basic_multi_buffer:: +basic_multi_buffer(basic_multi_buffer const& other) + : basic_multi_buffer(other.alloc_size_, alloc_traits::select_on_container_copy_construction(other.member())) { commit(boost::asio::buffer_copy(prepare(other.size()), other.data())); } template -basic_streambuf:: -basic_streambuf(basic_streambuf const& other, +basic_multi_buffer:: +basic_multi_buffer(basic_multi_buffer const& other, allocator_type const& alloc) - : basic_streambuf(other.alloc_size_, alloc) + : basic_multi_buffer(other.alloc_size_, alloc) { commit(boost::asio::buffer_copy(prepare(other.size()), other.data())); } template auto -basic_streambuf::operator=( - basic_streambuf const& other) -> - basic_streambuf& +basic_multi_buffer::operator=( + basic_multi_buffer const& other) -> + basic_multi_buffer& { if(this == &other) return *this; @@ -483,9 +483,9 @@ basic_streambuf::operator=( template template -basic_streambuf::basic_streambuf( - basic_streambuf const& other) - : basic_streambuf(other.alloc_size_) +basic_multi_buffer::basic_multi_buffer( + basic_multi_buffer const& other) + : basic_multi_buffer(other.alloc_size_) { using boost::asio::buffer_copy; commit(buffer_copy(prepare(other.size()), other.data())); @@ -493,10 +493,10 @@ basic_streambuf::basic_streambuf( template template -basic_streambuf::basic_streambuf( - basic_streambuf const& other, +basic_multi_buffer::basic_multi_buffer( + basic_multi_buffer const& other, allocator_type const& alloc) - : basic_streambuf(other.alloc_size_, alloc) + : basic_multi_buffer(other.alloc_size_, alloc) { using boost::asio::buffer_copy; commit(buffer_copy(prepare(other.size()), other.data())); @@ -505,9 +505,9 @@ basic_streambuf::basic_streambuf( template template auto -basic_streambuf::operator=( - basic_streambuf const& other) -> - basic_streambuf& +basic_multi_buffer::operator=( + basic_multi_buffer const& other) -> + basic_multi_buffer& { using boost::asio::buffer_copy; clear(); @@ -516,7 +516,7 @@ basic_streambuf::operator=( } template -basic_streambuf::basic_streambuf( +basic_multi_buffer::basic_multi_buffer( std::size_t alloc_size, Allocator const& alloc) : detail::empty_base_optimization(alloc) , out_(list_.end()) @@ -529,7 +529,7 @@ basic_streambuf::basic_streambuf( template std::size_t -basic_streambuf::capacity() const +basic_multi_buffer::capacity() const { auto pos = out_; if(pos == list_.end()) @@ -542,7 +542,7 @@ basic_streambuf::capacity() const template auto -basic_streambuf:: +basic_multi_buffer:: data() const -> const_buffers_type { @@ -551,7 +551,7 @@ data() const -> template auto -basic_streambuf::prepare(size_type n) -> +basic_multi_buffer::prepare(size_type n) -> mutable_buffers_type { list_type reuse; @@ -630,7 +630,7 @@ basic_streambuf::prepare(size_type n) -> template void -basic_streambuf::commit(size_type n) +basic_multi_buffer::commit(size_type n) { if(list_.empty()) return; @@ -670,7 +670,7 @@ basic_streambuf::commit(size_type n) template void -basic_streambuf::consume(size_type n) +basic_multi_buffer::consume(size_type n) { if(list_.empty()) return; @@ -731,7 +731,7 @@ basic_streambuf::consume(size_type n) template void -basic_streambuf:: +basic_multi_buffer:: clear() { delete_list(); @@ -745,8 +745,8 @@ clear() template void -basic_streambuf:: -move_assign(basic_streambuf& other, std::false_type) +basic_multi_buffer:: +move_assign(basic_multi_buffer& other, std::false_type) { using boost::asio::buffer_copy; if(this->member() != other.member()) @@ -760,8 +760,8 @@ move_assign(basic_streambuf& other, std::false_type) template void -basic_streambuf:: -move_assign(basic_streambuf& other, std::true_type) +basic_multi_buffer:: +move_assign(basic_multi_buffer& other, std::true_type) { this->member() = std::move(other.member()); auto const at_end = @@ -783,23 +783,23 @@ move_assign(basic_streambuf& other, std::true_type) template void -basic_streambuf:: -copy_assign(basic_streambuf const& other, std::false_type) +basic_multi_buffer:: +copy_assign(basic_multi_buffer const& other, std::false_type) { beast::detail::ignore_unused(other); } template void -basic_streambuf:: -copy_assign(basic_streambuf const& other, std::true_type) +basic_multi_buffer:: +copy_assign(basic_multi_buffer const& other, std::true_type) { this->member() = other.member(); } template void -basic_streambuf::delete_list() +basic_multi_buffer::delete_list() { for(auto iter = list_.begin(); iter != list_.end();) { @@ -813,7 +813,7 @@ basic_streambuf::delete_list() template void -basic_streambuf::debug_check() const +basic_multi_buffer::debug_check() const { #ifndef NDEBUG using boost::asio::buffer_size; @@ -853,19 +853,19 @@ basic_streambuf::debug_check() const template std::size_t -read_size_helper(basic_streambuf< - Allocator> const& streambuf, std::size_t max_size) +read_size_helper(basic_multi_buffer< + Allocator> const& multi_buffer, std::size_t max_size) { BOOST_ASSERT(max_size >= 1); // If we already have an allocated // buffer, try to fill that up first - auto const avail = streambuf.capacity() - streambuf.size(); + auto const avail = multi_buffer.capacity() - multi_buffer.size(); if (avail > 0) return (std::min)(avail, max_size); // Try to have just one new block allocated constexpr std::size_t low = 512; - if (streambuf.alloc_size_ > low) - return (std::min)(max_size, streambuf.alloc_size_); + if (multi_buffer.alloc_size_ > low) + return (std::min)(max_size, multi_buffer.alloc_size_); // ...but enforce a 512 byte minimum. return (std::min)(max_size, low); } diff --git a/include/beast/core/impl/static_streambuf.ipp b/include/beast/core/impl/static_streambuf.ipp index 90a48346..3ea097e1 100644 --- a/include/beast/core/impl/static_streambuf.ipp +++ b/include/beast/core/impl/static_streambuf.ipp @@ -297,7 +297,7 @@ static_streambuf::prepare(std::size_t n) -> { if(n > static_cast(end_ - out_)) throw detail::make_exception( - "no space in streambuf", __FILE__, __LINE__); + "no space in static_buffer", __FILE__, __LINE__); last_ = out_ + n; return mutable_buffers_type{out_, n}; } diff --git a/include/beast/core/streambuf.hpp b/include/beast/core/multi_buffer.hpp similarity index 88% rename from include/beast/core/streambuf.hpp rename to include/beast/core/multi_buffer.hpp index 26809043..55a2c04b 100644 --- a/include/beast/core/streambuf.hpp +++ b/include/beast/core/multi_buffer.hpp @@ -5,8 +5,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BEAST_STREAMBUF_HPP -#define BEAST_STREAMBUF_HPP +#ifndef BEAST_MULTI_BUFFER_HPP +#define BEAST_MULTI_BUFFER_HPP #include #include @@ -31,7 +31,7 @@ namespace beast { @tparam Allocator The allocator to use for managing memory. */ template -class basic_streambuf +class basic_multi_buffer #if ! BEAST_DOXYGEN : private detail::empty_base_optimization< typename std::allocator_traits:: @@ -96,7 +96,7 @@ public: #endif /// Destructor. - ~basic_streambuf(); + ~basic_multi_buffer(); /** Move constructor. @@ -107,7 +107,7 @@ public: an empty input and output sequence, with no internal buffers allocated. */ - basic_streambuf(basic_streambuf&&); + basic_multi_buffer(basic_multi_buffer&&); /** Move constructor. @@ -121,7 +121,7 @@ public: @param alloc The allocator to associate with the stream buffer. */ - basic_streambuf(basic_streambuf&&, + basic_multi_buffer(basic_multi_buffer&&, allocator_type const& alloc); /** Move assignment. @@ -133,15 +133,15 @@ public: an empty input and output sequence, with no internal buffers allocated. */ - basic_streambuf& - operator=(basic_streambuf&&); + basic_multi_buffer& + operator=(basic_multi_buffer&&); /** Copy constructor. This object will have a copy of the other stream buffer's input sequence, and an empty output sequence. */ - basic_streambuf(basic_streambuf const&); + basic_multi_buffer(basic_multi_buffer const&); /** Copy constructor. @@ -151,7 +151,7 @@ public: @param alloc The allocator to associate with the stream buffer. */ - basic_streambuf(basic_streambuf const&, + basic_multi_buffer(basic_multi_buffer const&, allocator_type const& alloc); /** Copy assignment. @@ -159,7 +159,7 @@ public: This object will have a copy of the other stream buffer's input sequence, and an empty output sequence. */ - basic_streambuf& operator=(basic_streambuf const&); + basic_multi_buffer& operator=(basic_multi_buffer const&); /** Copy constructor. @@ -167,7 +167,7 @@ public: buffer's input sequence, and an empty output sequence. */ template - basic_streambuf(basic_streambuf const&); + basic_multi_buffer(basic_multi_buffer const&); /** Copy constructor. @@ -178,7 +178,7 @@ public: stream buffer. */ template - basic_streambuf(basic_streambuf const&, + basic_multi_buffer(basic_multi_buffer const&, allocator_type const& alloc); /** Copy assignment. @@ -187,7 +187,7 @@ public: buffer's input sequence, and an empty output sequence. */ template - basic_streambuf& operator=(basic_streambuf const&); + basic_multi_buffer& operator=(basic_multi_buffer const&); /** Construct a stream buffer. @@ -200,7 +200,7 @@ public: unspecified, a default constructed allocator will be used. */ explicit - basic_streambuf(std::size_t alloc_size = 1024, + basic_multi_buffer(std::size_t alloc_size = 1024, Allocator const& alloc = allocator_type{}); /// Returns a copy of the associated allocator. @@ -289,24 +289,24 @@ public: template friend std::size_t - read_size_helper(basic_streambuf< - OtherAllocator> const& streambuf, std::size_t max_size); + read_size_helper(basic_multi_buffer< + OtherAllocator> const& multi_buffer, std::size_t max_size); private: void clear(); void - move_assign(basic_streambuf& other, std::false_type); + move_assign(basic_multi_buffer& other, std::false_type); void - move_assign(basic_streambuf& other, std::true_type); + move_assign(basic_multi_buffer& other, std::true_type); void - copy_assign(basic_streambuf const& other, std::false_type); + copy_assign(basic_multi_buffer const& other, std::false_type); void - copy_assign(basic_streambuf const& other, std::true_type); + copy_assign(basic_multi_buffer const& other, std::true_type); void delete_list(); @@ -324,10 +324,10 @@ private: @note Meets the requirements of @b `DynamicBuffer`. */ -using streambuf = basic_streambuf>; +using multi_buffer = basic_multi_buffer>; } // beast -#include +#include #endif diff --git a/include/beast/core/ostream.hpp b/include/beast/core/ostream.hpp index e991f5e7..634caa50 100644 --- a/include/beast/core/ostream.hpp +++ b/include/beast/core/ostream.hpp @@ -28,9 +28,9 @@ namespace beast { @par Example @code - streambuf sb; + multi_buffer b; ... - std::cout << buffers(sb.data()) << std::endl; + std::cout << buffers(b.data()) << std::endl; @endcode @param b An object meeting the requirements of @b ConstBufferSequence diff --git a/include/beast/http/dynamic_body.hpp b/include/beast/http/dynamic_body.hpp index caead1cd..452b763a 100644 --- a/include/beast/http/dynamic_body.hpp +++ b/include/beast/http/dynamic_body.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include namespace beast { @@ -111,11 +111,11 @@ private: }; }; -/** A dynamic message body represented by a @ref streambuf +/** A dynamic message body represented by a @ref multi_buffer Meets the requirements of @b `Body`. */ -using dynamic_body = basic_dynamic_body; +using dynamic_body = basic_dynamic_body; } // http } // beast diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index 66db1648..d995cb0f 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -89,15 +89,15 @@ class write_streambuf_op { bool cont; Stream& s; - streambuf sb; + multi_buffer b; int state = 0; data(Handler& handler, Stream& s_, - streambuf&& sb_) + multi_buffer&& sb_) : cont(beast_asio_helpers:: is_continuation(handler)) , s(s_) - , sb(std::move(sb_)) + , b(std::move(sb_)) { } }; @@ -167,7 +167,7 @@ operator()(error_code ec, std::size_t, bool again) { d.state = 99; boost::asio::async_write(d.s, - d.sb.data(), std::move(*this)); + d.b.data(), std::move(*this)); return; } } @@ -200,14 +200,14 @@ write(SyncWriteStream& stream, { static_assert(is_SyncWriteStream::value, "SyncWriteStream requirements not met"); - streambuf sb; + multi_buffer b; { - auto os = ostream(sb); + auto os = ostream(b); detail::write_start_line(os, msg); detail::write_fields(os, msg.fields); os << "\r\n"; } - boost::asio::write(stream, sb.data(), ec); + boost::asio::write(stream, b.data(), ec); } template completion{handler}; - streambuf sb; + multi_buffer b; { - auto os = ostream(sb); + auto os = ostream(b); detail::write_start_line(os, msg); detail::write_fields(os, msg.fields); os << "\r\n"; } detail::write_streambuf_op{ - completion.handler, stream, std::move(sb)}; + completion.handler, stream, std::move(b)}; return completion.result.get(); } @@ -245,7 +245,7 @@ struct write_preparation { message const& msg; typename Body::writer w; - streambuf sb; + multi_buffer b; bool chunked; bool close; @@ -270,7 +270,7 @@ struct write_preparation if(ec) return; - auto os = ostream(sb); + auto os = ostream(b); write_start_line(os, msg); write_fields(os, msg.fields); os << "\r\n"; @@ -318,12 +318,12 @@ class write_op // write header and body if(d.wp.chunked) boost::asio::async_write(d.s, - buffer_cat(d.wp.sb.data(), + buffer_cat(d.wp.b.data(), chunk_encode(false, buffers)), std::move(self_)); else boost::asio::async_write(d.s, - buffer_cat(d.wp.sb.data(), + buffer_cat(d.wp.b.data(), buffers), std::move(self_)); } }; @@ -452,7 +452,7 @@ operator()(error_code ec, std::size_t, bool again) // sent header and body case 2: - d.wp.sb.consume(d.wp.sb.size()); + d.wp.b.consume(d.wp.b.size()); d.state = 3; break; @@ -508,8 +508,8 @@ class writef0_lambda public: writef0_lambda(SyncWriteStream& stream, - DynamicBuffer const& sb, bool chunked, error_code& ec) - : sb_(sb) + DynamicBuffer const& b, bool chunked, error_code& ec) + : sb_(b) , stream_(stream) , chunked_(chunked) , ec_(ec) @@ -602,11 +602,11 @@ write(SyncWriteStream& stream, return; auto result = wp.w.write( ec, detail::writef0_lambda< - SyncWriteStream, decltype(wp.sb)>{ - stream, wp.sb, wp.chunked, ec}); + SyncWriteStream, decltype(wp.b)>{ + stream, wp.b, wp.chunked, ec}); if(ec) return; - wp.sb.consume(wp.sb.size()); + wp.b.consume(wp.b.size()); if(! result) { detail::writef_lambda wf{ diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 28d38b4a..f03e8e3a 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -98,7 +98,7 @@ class stream : public detail::stream_base { friend class stream_test; - dynabuf_readstream stream_; + dynabuf_readstream stream_; public: /// The type of the next layer. diff --git a/test/Jamfile b/test/Jamfile index bf5a2b0b..360de803 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -29,6 +29,7 @@ unit-test core-tests : core/handler_alloc.cpp core/handler_concepts.cpp core/handler_ptr.cpp + core/multi_buffer.cpp core/ostream.cpp core/placeholders.cpp core/prepare_buffer.cpp @@ -36,7 +37,6 @@ unit-test core-tests : core/static_streambuf.cpp core/static_string.cpp core/stream_concepts.cpp - core/streambuf.cpp core/base64.cpp core/empty_base_optimization.cpp core/get_lowest_layer.cpp diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index f1f654a6..988f7203 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable (core-tests handler_alloc.cpp handler_concepts.cpp handler_ptr.cpp + multi_buffer.cpp ostream.cpp placeholders.cpp prepare_buffer.cpp @@ -29,7 +30,6 @@ add_executable (core-tests static_streambuf.cpp static_string.cpp stream_concepts.cpp - streambuf.cpp base64.cpp empty_base_optimization.cpp get_lowest_layer.cpp diff --git a/test/core/buffers_adapter.cpp b/test/core/buffers_adapter.cpp index b14dc676..c1c2fc7f 100644 --- a/test/core/buffers_adapter.cpp +++ b/test/core/buffers_adapter.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -151,19 +151,19 @@ public: using boost::asio::buffer_size; { using sb_type = boost::asio::streambuf; - sb_type sb; + sb_type b; buffers_adapter< - sb_type::mutable_buffers_type> ba(sb.prepare(3)); + sb_type::mutable_buffers_type> ba(b.prepare(3)); BEAST_EXPECT(buffer_size(ba.prepare(3)) == 3); ba.commit(2); BEAST_EXPECT(buffer_size(ba.data()) == 2); } { - using sb_type = beast::streambuf; - sb_type sb(2); - sb.prepare(3); + using sb_type = beast::multi_buffer; + sb_type b(2); + b.prepare(3); buffers_adapter< - sb_type::mutable_buffers_type> ba(sb.prepare(8)); + sb_type::mutable_buffers_type> ba(b.prepare(8)); BEAST_EXPECT(buffer_size(ba.prepare(8)) == 8); ba.commit(2); BEAST_EXPECT(buffer_size(ba.data()) == 2); diff --git a/test/core/dynabuf_readstream.cpp b/test/core/dynabuf_readstream.cpp index 1293e523..54327522 100644 --- a/test/core/dynabuf_readstream.cpp +++ b/test/core/dynabuf_readstream.cpp @@ -8,7 +8,7 @@ // Test that header file is self-contained. #include -#include +#include #include #include #include @@ -29,16 +29,16 @@ public: using socket_type = boost::asio::ip::tcp::socket; boost::asio::io_service ios; { - dynabuf_readstream srs(ios); - dynabuf_readstream srs2(std::move(srs)); + dynabuf_readstream srs(ios); + dynabuf_readstream srs2(std::move(srs)); srs = std::move(srs2); BEAST_EXPECT(&srs.get_io_service() == &ios); BEAST_EXPECT(&srs.get_io_service() == &srs2.get_io_service()); } { socket_type sock(ios); - dynabuf_readstream srs(sock); - dynabuf_readstream srs2(std::move(srs)); + dynabuf_readstream srs(sock); + dynabuf_readstream srs2(std::move(srs)); } } @@ -56,7 +56,7 @@ public: test::fail_stream< test::string_istream> fs(n, ios_, ", world!"); dynabuf_readstream< - decltype(fs)&, streambuf> srs(fs); + decltype(fs)&, multi_buffer> srs(fs); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); error_code ec; @@ -74,7 +74,7 @@ public: test::fail_stream< test::string_istream> fs(n, ios_, ", world!"); dynabuf_readstream< - decltype(fs)&, streambuf> srs(fs); + decltype(fs)&, multi_buffer> srs(fs); srs.capacity(3); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); @@ -93,7 +93,7 @@ public: test::fail_stream< test::string_istream> fs(n, ios_, ", world!"); dynabuf_readstream< - decltype(fs)&, streambuf> srs(fs); + decltype(fs)&, multi_buffer> srs(fs); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); error_code ec; @@ -112,7 +112,7 @@ public: test::fail_stream< test::string_istream> fs(n, ios_, ", world!"); dynabuf_readstream< - decltype(fs)&, streambuf> srs(fs); + decltype(fs)&, multi_buffer> srs(fs); srs.capacity(3); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); diff --git a/test/core/multi_buffer.cpp b/test/core/multi_buffer.cpp new file mode 100644 index 00000000..61419549 --- /dev/null +++ b/test/core/multi_buffer.cpp @@ -0,0 +1,361 @@ +// +// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +// Test that header file is self-contained. +#include + +#include "buffer_test.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace beast { + +static_assert(is_DynamicBuffer::value, ""); + +class multi_buffer_test : public beast::unit_test::suite +{ +public: + template + static + std::string + to_string(ConstBufferSequence const& bs) + { + return boost::lexical_cast< + std::string>(buffers(bs)); + } + + template + static + bool + eq(basic_multi_buffer const& sb1, + basic_multi_buffer const& sb2) + { + return to_string(sb1.data()) == to_string(sb2.data()); + } + + template + void + expect_size(std::size_t n, ConstBufferSequence const& buffers) + { + BEAST_EXPECT(test::size_pre(buffers) == n); + BEAST_EXPECT(test::size_post(buffers) == n); + BEAST_EXPECT(test::size_rev_pre(buffers) == n); + BEAST_EXPECT(test::size_rev_post(buffers) == n); + } + + template + static + void + self_assign(U& u, V&& v) + { + u = std::forward(v); + } + + void testSpecialMembers() + { + using boost::asio::buffer; + std::string const s = "Hello, world"; + BEAST_EXPECT(s.size() == 12); + for(std::size_t i = 1; i < 12; ++i) { + for(std::size_t x = 1; x < 4; ++x) { + for(std::size_t y = 1; y < 4; ++y) { + std::size_t z = s.size() - (x + y); + { + multi_buffer b(i); + b.commit(buffer_copy(b.prepare(x), buffer(s.data(), x))); + b.commit(buffer_copy(b.prepare(y), buffer(s.data()+x, y))); + b.commit(buffer_copy(b.prepare(z), buffer(s.data()+x+y, z))); + BEAST_EXPECT(to_string(b.data()) == s); + { + multi_buffer sb2(b); + BEAST_EXPECT(eq(b, sb2)); + } + { + multi_buffer sb2; + sb2 = b; + BEAST_EXPECT(eq(b, sb2)); + } + { + multi_buffer sb2(std::move(b)); + BEAST_EXPECT(to_string(sb2.data()) == s); + expect_size(0, b.data()); + b = std::move(sb2); + BEAST_EXPECT(to_string(b.data()) == s); + expect_size(0, sb2.data()); + } + self_assign(b, b); + BEAST_EXPECT(to_string(b.data()) == s); + self_assign(b, std::move(b)); + BEAST_EXPECT(to_string(b.data()) == s); + } + }}} + try + { + multi_buffer sb0(0); + fail(); + } + catch(std::exception const&) + { + pass(); + } + } + + void + testAllocator() + { + using test::test_allocator; + // VFALCO This needs work + { + using alloc_type = + test_allocator; + using type = basic_multi_buffer; + type b; + } + { + using alloc_type = + test_allocator; + using type = basic_multi_buffer; + type b; + type b2(b); + type b3(b, alloc_type{}); + } + } + + void + testPrepare() + { + using boost::asio::buffer_size; + { + multi_buffer b(2); + BEAST_EXPECT(buffer_size(b.prepare(5)) == 5); + BEAST_EXPECT(buffer_size(b.prepare(8)) == 8); + BEAST_EXPECT(buffer_size(b.prepare(7)) == 7); + } + { + multi_buffer b(2); + b.prepare(2); + BEAST_EXPECT(test::buffer_count(b.prepare(5)) == 2); + BEAST_EXPECT(test::buffer_count(b.prepare(8)) == 3); + BEAST_EXPECT(test::buffer_count(b.prepare(4)) == 2); + } + } + + void testCommit() + { + multi_buffer b(2); + b.prepare(2); + b.prepare(5); + b.commit(1); + expect_size(1, b.data()); + } + + void testConsume() + { + multi_buffer b(1); + expect_size(5, b.prepare(5)); + b.commit(3); + expect_size(3, b.data()); + b.consume(1); + expect_size(2, b.data()); + } + + void testMatrix() + { + using boost::asio::buffer; + using boost::asio::buffer_size; + std::string const s = "Hello, world"; + BEAST_EXPECT(s.size() == 12); + for(std::size_t i = 1; i < 12; ++i) { + for(std::size_t x = 1; x < 4; ++x) { + for(std::size_t y = 1; y < 4; ++y) { + for(std::size_t t = 1; t < 4; ++ t) { + for(std::size_t u = 1; u < 4; ++ u) { + std::size_t z = s.size() - (x + y); + std::size_t v = s.size() - (t + u); + { + multi_buffer b(i); + { + auto d = b.prepare(z); + BEAST_EXPECT(buffer_size(d) == z); + } + { + auto d = b.prepare(0); + BEAST_EXPECT(buffer_size(d) == 0); + } + { + auto d = b.prepare(y); + BEAST_EXPECT(buffer_size(d) == y); + } + { + auto d = b.prepare(x); + BEAST_EXPECT(buffer_size(d) == x); + b.commit(buffer_copy(d, buffer(s.data(), x))); + } + BEAST_EXPECT(b.size() == x); + BEAST_EXPECT(buffer_size(b.data()) == b.size()); + { + auto d = b.prepare(x); + BEAST_EXPECT(buffer_size(d) == x); + } + { + auto d = b.prepare(0); + BEAST_EXPECT(buffer_size(d) == 0); + } + { + auto d = b.prepare(z); + BEAST_EXPECT(buffer_size(d) == z); + } + { + auto d = b.prepare(y); + BEAST_EXPECT(buffer_size(d) == y); + b.commit(buffer_copy(d, buffer(s.data()+x, y))); + } + b.commit(1); + BEAST_EXPECT(b.size() == x + y); + BEAST_EXPECT(buffer_size(b.data()) == b.size()); + { + auto d = b.prepare(x); + BEAST_EXPECT(buffer_size(d) == x); + } + { + auto d = b.prepare(y); + BEAST_EXPECT(buffer_size(d) == y); + } + { + auto d = b.prepare(0); + BEAST_EXPECT(buffer_size(d) == 0); + } + { + auto d = b.prepare(z); + BEAST_EXPECT(buffer_size(d) == z); + b.commit(buffer_copy(d, buffer(s.data()+x+y, z))); + } + b.commit(2); + BEAST_EXPECT(b.size() == x + y + z); + BEAST_EXPECT(buffer_size(b.data()) == b.size()); + BEAST_EXPECT(to_string(b.data()) == s); + b.consume(t); + { + auto d = b.prepare(0); + BEAST_EXPECT(buffer_size(d) == 0); + } + BEAST_EXPECT(to_string(b.data()) == s.substr(t, std::string::npos)); + b.consume(u); + BEAST_EXPECT(to_string(b.data()) == s.substr(t + u, std::string::npos)); + b.consume(v); + BEAST_EXPECT(to_string(b.data()) == ""); + b.consume(1); + { + auto d = b.prepare(0); + BEAST_EXPECT(buffer_size(d) == 0); + } + } + }}}}} + } + + void testIterators() + { + using boost::asio::buffer_size; + multi_buffer b(1); + b.prepare(1); + b.commit(1); + b.prepare(2); + b.commit(2); + expect_size(3, b.data()); + b.prepare(1); + expect_size(3, b.prepare(3)); + b.commit(2); + BEAST_EXPECT(test::buffer_count(b.data()) == 4); + } + + void testCapacity() + { + using boost::asio::buffer_size; + { + multi_buffer b{10}; + BEAST_EXPECT(b.alloc_size() == 10); + BEAST_EXPECT(read_size_helper(b, 1) == 1); + BEAST_EXPECT(read_size_helper(b, 10) == 10); + BEAST_EXPECT(read_size_helper(b, 20) == 20); + BEAST_EXPECT(read_size_helper(b, 1000) == 512); + b.prepare(3); + b.commit(3); + BEAST_EXPECT(read_size_helper(b, 10) == 7); + BEAST_EXPECT(read_size_helper(b, 1000) == 7); + } + { + multi_buffer b(1000); + BEAST_EXPECT(b.alloc_size() == 1000); + BEAST_EXPECT(read_size_helper(b, 1) == 1); + BEAST_EXPECT(read_size_helper(b, 1000) == 1000); + BEAST_EXPECT(read_size_helper(b, 2000) == 1000); + b.prepare(3); + BEAST_EXPECT(read_size_helper(b, 1) == 1); + BEAST_EXPECT(read_size_helper(b, 1000) == 1000); + BEAST_EXPECT(read_size_helper(b, 2000) == 1000); + b.commit(3); + BEAST_EXPECT(read_size_helper(b, 1) == 1); + BEAST_EXPECT(read_size_helper(b, 1000) == 997); + BEAST_EXPECT(read_size_helper(b, 2000) == 997); + b.consume(2); + BEAST_EXPECT(read_size_helper(b, 1) == 1); + BEAST_EXPECT(read_size_helper(b, 1000) == 997); + BEAST_EXPECT(read_size_helper(b, 2000) == 997); + } + { + multi_buffer b{2}; + BEAST_EXPECT(b.alloc_size() == 2); + BEAST_EXPECT(test::buffer_count(b.prepare(2)) == 1); + BEAST_EXPECT(test::buffer_count(b.prepare(3)) == 2); + BEAST_EXPECT(buffer_size(b.prepare(5)) == 5); + BEAST_EXPECT(read_size_helper(b, 10) == 6); + } + { + auto avail = + [](multi_buffer const& b) + { + return b.capacity() - b.size(); + }; + multi_buffer b{100}; + BEAST_EXPECT(b.alloc_size() == 100); + BEAST_EXPECT(avail(b) == 0); + b.prepare(100); + BEAST_EXPECT(avail(b) == 100); + b.commit(100); + BEAST_EXPECT(avail(b) == 0); + b.consume(100); + BEAST_EXPECT(avail(b) == 0); + b.alloc_size(200); + BEAST_EXPECT(b.alloc_size() == 200); + b.prepare(1); + BEAST_EXPECT(avail(b) == 200); + } + } + + void run() override + { + testSpecialMembers(); + testAllocator(); + testPrepare(); + testCommit(); + testConsume(); + testMatrix(); + testIterators(); + testCapacity(); + } +}; + +BEAST_DEFINE_TESTSUITE(multi_buffer,core,beast); + +} // beast diff --git a/test/core/ostream.cpp b/test/core/ostream.cpp index f96fd8b7..db4922bd 100644 --- a/test/core/ostream.cpp +++ b/test/core/ostream.cpp @@ -8,7 +8,7 @@ // Test that header file is self-contained. #include -#include +#include #include #include #include @@ -20,10 +20,10 @@ class ostream_test : public beast::unit_test::suite public: void run() override { - streambuf sb; - ostream(sb) << "Hello, world!\n"; + multi_buffer b; + ostream(b) << "Hello, world!\n"; BEAST_EXPECT(boost::lexical_cast( - buffers(sb.data())) == "Hello, world!\n"); + buffers(b.data())) == "Hello, world!\n"); } }; diff --git a/test/core/streambuf.cpp b/test/core/streambuf.cpp deleted file mode 100644 index 892aabd6..00000000 --- a/test/core/streambuf.cpp +++ /dev/null @@ -1,364 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -static_assert(is_DynamicBuffer::value, ""); - -class basic_streambuf_test : public beast::unit_test::suite -{ -public: - template - static - std::string - to_string(ConstBufferSequence const& bs) - { - return boost::lexical_cast< - std::string>(buffers(bs)); - } - - template - static - bool - eq(basic_streambuf const& sb1, - basic_streambuf const& sb2) - { - return to_string(sb1.data()) == to_string(sb2.data()); - } - - template - void - expect_size(std::size_t n, ConstBufferSequence const& buffers) - { - BEAST_EXPECT(test::size_pre(buffers) == n); - BEAST_EXPECT(test::size_post(buffers) == n); - BEAST_EXPECT(test::size_rev_pre(buffers) == n); - BEAST_EXPECT(test::size_rev_post(buffers) == n); - } - - template - static - void - self_assign(U& u, V&& v) - { - u = std::forward(v); - } - - void testSpecialMembers() - { - using boost::asio::buffer; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == 12); - for(std::size_t i = 1; i < 12; ++i) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - std::size_t z = s.size() - (x + y); - { - streambuf sb(i); - sb.commit(buffer_copy(sb.prepare(x), buffer(s.data(), x))); - sb.commit(buffer_copy(sb.prepare(y), buffer(s.data()+x, y))); - sb.commit(buffer_copy(sb.prepare(z), buffer(s.data()+x+y, z))); - BEAST_EXPECT(to_string(sb.data()) == s); - { - streambuf sb2(sb); - BEAST_EXPECT(eq(sb, sb2)); - } - { - streambuf sb2; - sb2 = sb; - BEAST_EXPECT(eq(sb, sb2)); - } - { - streambuf sb2(std::move(sb)); - BEAST_EXPECT(to_string(sb2.data()) == s); - expect_size(0, sb.data()); - sb = std::move(sb2); - BEAST_EXPECT(to_string(sb.data()) == s); - expect_size(0, sb2.data()); - } - self_assign(sb, sb); - BEAST_EXPECT(to_string(sb.data()) == s); - self_assign(sb, std::move(sb)); - BEAST_EXPECT(to_string(sb.data()) == s); - } - }}} - try - { - streambuf sb0(0); - fail(); - } - catch(std::exception const&) - { - pass(); - } - } - - void - testAllocator() - { - using test::test_allocator; - // VFALCO This needs work - { - using alloc_type = - test_allocator; - using sb_type = basic_streambuf; - sb_type sb; - BEAST_EXPECT(sb.get_allocator().id() == 1); - } - { - using alloc_type = - test_allocator; - using sb_type = basic_streambuf; - sb_type sb; - BEAST_EXPECT(sb.get_allocator().id() == 2); - sb_type sb2(sb); - BEAST_EXPECT(sb2.get_allocator().id() == 2); - sb_type sb3(sb, alloc_type{}); - } - } - - void - testPrepare() - { - using boost::asio::buffer_size; - { - streambuf sb(2); - BEAST_EXPECT(buffer_size(sb.prepare(5)) == 5); - BEAST_EXPECT(buffer_size(sb.prepare(8)) == 8); - BEAST_EXPECT(buffer_size(sb.prepare(7)) == 7); - } - { - streambuf sb(2); - sb.prepare(2); - BEAST_EXPECT(test::buffer_count(sb.prepare(5)) == 2); - BEAST_EXPECT(test::buffer_count(sb.prepare(8)) == 3); - BEAST_EXPECT(test::buffer_count(sb.prepare(4)) == 2); - } - } - - void testCommit() - { - streambuf sb(2); - sb.prepare(2); - sb.prepare(5); - sb.commit(1); - expect_size(1, sb.data()); - } - - void testConsume() - { - streambuf sb(1); - expect_size(5, sb.prepare(5)); - sb.commit(3); - expect_size(3, sb.data()); - sb.consume(1); - expect_size(2, sb.data()); - } - - void testMatrix() - { - using boost::asio::buffer; - using boost::asio::buffer_size; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == 12); - for(std::size_t i = 1; i < 12; ++i) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - for(std::size_t t = 1; t < 4; ++ t) { - for(std::size_t u = 1; u < 4; ++ u) { - std::size_t z = s.size() - (x + y); - std::size_t v = s.size() - (t + u); - { - streambuf sb(i); - { - auto d = sb.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = sb.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = sb.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = sb.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - sb.commit(buffer_copy(d, buffer(s.data(), x))); - } - BEAST_EXPECT(sb.size() == x); - BEAST_EXPECT(buffer_size(sb.data()) == sb.size()); - { - auto d = sb.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = sb.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = sb.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = sb.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - sb.commit(buffer_copy(d, buffer(s.data()+x, y))); - } - sb.commit(1); - BEAST_EXPECT(sb.size() == x + y); - BEAST_EXPECT(buffer_size(sb.data()) == sb.size()); - { - auto d = sb.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = sb.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = sb.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = sb.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - sb.commit(buffer_copy(d, buffer(s.data()+x+y, z))); - } - sb.commit(2); - BEAST_EXPECT(sb.size() == x + y + z); - BEAST_EXPECT(buffer_size(sb.data()) == sb.size()); - BEAST_EXPECT(to_string(sb.data()) == s); - sb.consume(t); - { - auto d = sb.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - BEAST_EXPECT(to_string(sb.data()) == s.substr(t, std::string::npos)); - sb.consume(u); - BEAST_EXPECT(to_string(sb.data()) == s.substr(t + u, std::string::npos)); - sb.consume(v); - BEAST_EXPECT(to_string(sb.data()) == ""); - sb.consume(1); - { - auto d = sb.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - } - }}}}} - } - - void testIterators() - { - using boost::asio::buffer_size; - streambuf sb(1); - sb.prepare(1); - sb.commit(1); - sb.prepare(2); - sb.commit(2); - expect_size(3, sb.data()); - sb.prepare(1); - expect_size(3, sb.prepare(3)); - sb.commit(2); - BEAST_EXPECT(test::buffer_count(sb.data()) == 4); - } - - void testCapacity() - { - using boost::asio::buffer_size; - { - streambuf sb{10}; - BEAST_EXPECT(sb.alloc_size() == 10); - BEAST_EXPECT(read_size_helper(sb, 1) == 1); - BEAST_EXPECT(read_size_helper(sb, 10) == 10); - BEAST_EXPECT(read_size_helper(sb, 20) == 20); - BEAST_EXPECT(read_size_helper(sb, 1000) == 512); - sb.prepare(3); - sb.commit(3); - BEAST_EXPECT(read_size_helper(sb, 10) == 7); - BEAST_EXPECT(read_size_helper(sb, 1000) == 7); - } - { - streambuf sb(1000); - BEAST_EXPECT(sb.alloc_size() == 1000); - BEAST_EXPECT(read_size_helper(sb, 1) == 1); - BEAST_EXPECT(read_size_helper(sb, 1000) == 1000); - BEAST_EXPECT(read_size_helper(sb, 2000) == 1000); - sb.prepare(3); - BEAST_EXPECT(read_size_helper(sb, 1) == 1); - BEAST_EXPECT(read_size_helper(sb, 1000) == 1000); - BEAST_EXPECT(read_size_helper(sb, 2000) == 1000); - sb.commit(3); - BEAST_EXPECT(read_size_helper(sb, 1) == 1); - BEAST_EXPECT(read_size_helper(sb, 1000) == 997); - BEAST_EXPECT(read_size_helper(sb, 2000) == 997); - sb.consume(2); - BEAST_EXPECT(read_size_helper(sb, 1) == 1); - BEAST_EXPECT(read_size_helper(sb, 1000) == 997); - BEAST_EXPECT(read_size_helper(sb, 2000) == 997); - } - { - streambuf sb{2}; - BEAST_EXPECT(sb.alloc_size() == 2); - BEAST_EXPECT(test::buffer_count(sb.prepare(2)) == 1); - BEAST_EXPECT(test::buffer_count(sb.prepare(3)) == 2); - BEAST_EXPECT(buffer_size(sb.prepare(5)) == 5); - BEAST_EXPECT(read_size_helper(sb, 10) == 6); - } - { - auto avail = - [](streambuf const& sb) - { - return sb.capacity() - sb.size(); - }; - streambuf sb{100}; - BEAST_EXPECT(sb.alloc_size() == 100); - BEAST_EXPECT(avail(sb) == 0); - sb.prepare(100); - BEAST_EXPECT(avail(sb) == 100); - sb.commit(100); - BEAST_EXPECT(avail(sb) == 0); - sb.consume(100); - BEAST_EXPECT(avail(sb) == 0); - sb.alloc_size(200); - BEAST_EXPECT(sb.alloc_size() == 200); - sb.prepare(1); - BEAST_EXPECT(avail(sb) == 200); - } - } - - void run() override - { - testSpecialMembers(); - testAllocator(); - testPrepare(); - testCommit(); - testConsume(); - testMatrix(); - testIterators(); - testCapacity(); - } -}; - -BEAST_DEFINE_TESTSUITE(basic_streambuf,core,beast); - -} // beast diff --git a/test/http/basic_parser.cpp b/test/http/basic_parser.cpp index 9c73f318..86fa7163 100644 --- a/test/http/basic_parser.cpp +++ b/test/http/basic_parser.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include namespace beast { @@ -902,8 +902,8 @@ public: testSplit() { #if 0 - streambuf sb; - sb << + multi_buffer b; + b << "POST / HTTP/1.1\r\n" "Content-Length: 5\r\n" "\r\n" @@ -911,7 +911,7 @@ public: error_code ec; test_parser p; p.pause(); - auto n = feed(sb.data(), p, ec); + auto n = feed(b.data(), p, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p.got_on_begin); BEAST_EXPECT(p.got_on_field); @@ -922,9 +922,9 @@ public: BEAST_EXPECT(p.state() != parse_state::header); BEAST_EXPECT(! p.is_complete()); BEAST_EXPECT(p.body.empty()); - sb.consume(n); + b.consume(n); p.resume(); - n = feed(sb.data(), p, ec); + n = feed(b.data(), p, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p.got_on_begin); BEAST_EXPECT(p.got_on_field); diff --git a/test/http/design.cpp b/test/http/design.cpp index 70908ed3..2afafcd7 100644 --- a/test/http/design.cpp +++ b/test/http/design.cpp @@ -104,8 +104,8 @@ public: "*" }; message m; - flat_streambuf sb{1024}; - read(is, sb, m); + flat_streambuf b{1024}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } @@ -117,8 +117,8 @@ public: "*" }; message m; - flat_streambuf sb{20}; - read(is, sb, m); + flat_streambuf b{20}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } @@ -133,8 +133,8 @@ public: "0\r\n\r\n" }; message m; - flat_streambuf sb{100}; - read(is, sb, m); + flat_streambuf b{100}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } } @@ -201,8 +201,8 @@ public: "*" }; message m; - flat_streambuf sb{1024}; - read(is, sb, m); + flat_streambuf b{1024}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } @@ -214,8 +214,8 @@ public: "*" }; message m; - flat_streambuf sb{20}; - read(is, sb, m); + flat_streambuf b{20}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } @@ -231,8 +231,8 @@ public: "0\r\n\r\n" }; message m; - flat_streambuf sb{1024}; - read(is, sb, m); + flat_streambuf b{1024}; + read(is, b, m); BEAST_EXPECT(m.body == "*"); } } @@ -253,15 +253,15 @@ public: "*****" }; header_parser p; - flat_streambuf sb{38}; + flat_streambuf b{38}; auto const bytes_used = - read_some(is, sb, p); - sb.consume(bytes_used); + read_some(is, b, p); + b.consume(bytes_used); BEAST_EXPECT(p.size() == 5); - BEAST_EXPECT(sb.size() < 5); - sb.commit(boost::asio::read( - is, sb.prepare(5 - sb.size()))); - BEAST_EXPECT(sb.size() == 5); + BEAST_EXPECT(b.size() < 5); + b.commit(boost::asio::read( + is, b.prepare(5 - b.size()))); + BEAST_EXPECT(b.size() == 5); } // end of file @@ -272,16 +272,16 @@ public: "*****" }; header_parser p; - flat_streambuf sb{20}; + flat_streambuf b{20}; auto const bytes_used = - read_some(is, sb, p); - sb.consume(bytes_used); + read_some(is, b, p); + b.consume(bytes_used); BEAST_EXPECT(p.state() == parse_state::body_to_eof); - BEAST_EXPECT(sb.size() < 5); - sb.commit(boost::asio::read( - is, sb.prepare(5 - sb.size()))); - BEAST_EXPECT(sb.size() == 5); + BEAST_EXPECT(b.size() < 5); + b.commit(boost::asio::read( + is, b.prepare(5 - b.size()))); + BEAST_EXPECT(b.size() == 5); } } @@ -303,10 +303,10 @@ public: }; header_parser p; - flat_streambuf sb{128}; + flat_streambuf b{128}; auto const bytes_used = - read_some(is, sb, p); - sb.consume(bytes_used); + read_some(is, b, p); + b.consume(bytes_used); BEAST_EXPECT(p.got_header()); BEAST_EXPECT( p.get().fields["Expect"] == @@ -314,7 +314,7 @@ public: message_parser< true, string_body, fields> p1{ std::move(p)}; - read(is, sb, p1); + read(is, b, p1); BEAST_EXPECT( p1.get().body == "*****"); } @@ -332,7 +332,7 @@ public: void relay( SyncWriteStream& out, - DynamicBuffer& sb, + DynamicBuffer& b, SyncReadStream& in) { flat_streambuf buffer{4096}; // 4K limit @@ -397,8 +397,8 @@ public: 3 // max_read }; test::string_ostream os{ios_}; - flat_streambuf sb{16}; - relay(os, sb, is); + flat_streambuf b{16}; + relay(os, b, is); } // end of file @@ -410,8 +410,8 @@ public: 3 // max_read }; test::string_ostream os{ios_}; - flat_streambuf sb{16}; - relay(os, sb, is); + flat_streambuf b{16}; + relay(os, b, is); } // chunked @@ -427,8 +427,8 @@ public: 2 // max_read }; test::string_ostream os{ios_}; - flat_streambuf sb{16}; - relay(os, sb, is); + flat_streambuf b{16}; + relay(os, b, is); } } diff --git a/test/http/dynamic_body.cpp b/test/http/dynamic_body.cpp index 5b06e030..9a455ec1 100644 --- a/test/http/dynamic_body.cpp +++ b/test/http/dynamic_body.cpp @@ -36,8 +36,8 @@ public: "xyz"; test::string_istream ss(ios_, s); message_parser p; - streambuf sb; - read(ss, sb, p); + multi_buffer b; + read(ss, b, p); auto const& m = p.get(); BEAST_EXPECT(boost::lexical_cast( buffers(m.body.data())) == "xyz"); diff --git a/test/http/message_parser.cpp b/test/http/message_parser.cpp index 41bbbd2c..b06d7ea9 100644 --- a/test/http/message_parser.cpp +++ b/test/http/message_parser.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ public: beast::test::string_istream ss{get_io_service(), s}; error_code ec; #if 0 - streambuf dynabuf; + multi_buffer dynabuf; #else flat_streambuf dynabuf{1024}; #endif @@ -124,9 +124,9 @@ public: "Content-Length: 1\r\n" "\r\n" "*"}; - flat_streambuf sb{1024}; + flat_streambuf b{1024}; message_parser p; - read(is, sb, p, ec); + read(is, b, p, ec); auto const& m = p.get(); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p.is_complete()); @@ -142,8 +142,8 @@ public: // parse through the chunk body beast::test::string_istream is{ get_io_service(), ""}; - streambuf sb; - sb << + multi_buffer b; + b << "PUT / HTTP/1.1\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" @@ -151,20 +151,20 @@ public: "*"; error_code ec; message_parser p; - read(is, sb, p, ec); - BEAST_EXPECT(sb.size() == 0); + read(is, b, p, ec); + BEAST_EXPECT(b.size() == 0); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(!p.is_complete()); BEAST_EXPECT(p.get().body == "*"); - sb << "\r\n0;d;e=3;f=\"4\"\r\n" + b << "\r\n0;d;e=3;f=\"4\"\r\n" "Expires: never\r\n" "MD5-Fingerprint: -\r\n"; // incomplete parse, missing the final crlf - BEAST_EXPECT(p.write(sb.data(), ec) == 0); + BEAST_EXPECT(p.write(b.data(), ec) == 0); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(!p.is_complete()); - sb << "\r\n"; // final crlf to end message - BEAST_EXPECT(p.write(sb.data(), ec) == sb.size()); + b << "\r\n"; // final crlf to end message + BEAST_EXPECT(p.write(b.data(), ec) == b.size()); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p.is_complete()); } @@ -212,18 +212,18 @@ public: "Content-Length: 5\r\n" "\r\n" "*****"}; - streambuf sb; + multi_buffer b; error_code ec; header_parser p0; auto const bytes_used = - read_some(ss, sb, p0, ec); - sb.consume(bytes_used); + read_some(ss, b, p0, ec); + b.consume(bytes_used); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p0.state() != parse_state::header); BEAST_EXPECT(! p0.is_complete()); message_parser p1{std::move(p0)}; - read(ss, sb, p1, ec); + read(ss, b, p1, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p1.get().body == "*****"); } diff --git a/test/http/parser_bench.cpp b/test/http/parser_bench.cpp index 9344411b..ea2d1f53 100644 --- a/test/http/parser_bench.cpp +++ b/test/http/parser_bench.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,7 +26,7 @@ class parser_bench_test : public beast::unit_test::suite public: static std::size_t constexpr N = 2000; - using corpus = std::vector; + using corpus = std::vector; corpus creq_; corpus cres_; @@ -110,13 +110,13 @@ public: testParser1(std::size_t repeat, corpus const& v) { while(repeat--) - for(auto const& sb : v) + for(auto const& b : v) { Parser p; error_code ec; - p.write(sb.data(), ec); + p.write(b.data(), ec); if(! BEAST_EXPECTS(! ec, ec.message())) - log << to_string(sb.data()) << std::endl; + log << to_string(b.data()) << std::endl; } } @@ -125,13 +125,13 @@ public: testParser2(std::size_t repeat, corpus const& v) { while(repeat--) - for(auto const& sb : v) + for(auto const& b : v) { Parser p; error_code ec; - feed(sb.data(), p, ec); + feed(b.data(), p, ec); if(! BEAST_EXPECTS(! ec, ec.message())) - log << to_string(sb.data()) << std::endl; + log << to_string(b.data()) << std::endl; } } diff --git a/test/http/read.cpp b/test/http/read.cpp index a03f1f3b..bad11351 100644 --- a/test/http/read.cpp +++ b/test/http/read.cpp @@ -40,15 +40,15 @@ public: auto const len = strlen(s); for(n = 0; n < limit; ++n) { - streambuf sb; - sb.commit(buffer_copy( - sb.prepare(len), buffer(s, len))); + multi_buffer b; + b.commit(buffer_copy( + b.prepare(len), buffer(s, len))); test::fail_counter fc(n); test::fail_stream< test::string_istream> fs{fc, ios_, ""}; test_parser p(fc); error_code ec; - read(fs, sb, p, ec); + read(fs, b, p, ec); if(! ec) break; } @@ -56,30 +56,30 @@ public: for(n = 0; n < limit; ++n) { static std::size_t constexpr pre = 10; - streambuf sb; - sb.commit(buffer_copy( - sb.prepare(pre), buffer(s, pre))); + multi_buffer b; + b.commit(buffer_copy( + b.prepare(pre), buffer(s, pre))); test::fail_counter fc(n); test::fail_stream fs{ fc, ios_, std::string{s + pre, len - pre}}; test_parser p(fc); error_code ec; - read(fs, sb, p, ec); + read(fs, b, p, ec); if(! ec) break; } BEAST_EXPECT(n < limit); for(n = 0; n < limit; ++n) { - streambuf sb; - sb.commit(buffer_copy( - sb.prepare(len), buffer(s, len))); + multi_buffer b; + b.commit(buffer_copy( + b.prepare(len), buffer(s, len))); test::fail_counter fc(n); test::fail_stream< test::string_istream> fs{fc, ios_, ""}; test_parser p(fc); error_code ec; - async_read(fs, sb, p, do_yield[ec]); + async_read(fs, b, p, do_yield[ec]); if(! ec) break; } @@ -87,15 +87,15 @@ public: for(n = 0; n < limit; ++n) { static std::size_t constexpr pre = 10; - streambuf sb; - sb.commit(buffer_copy( - sb.prepare(pre), buffer(s, pre))); + multi_buffer b; + b.commit(buffer_copy( + b.prepare(pre), buffer(s, pre))); test::fail_counter fc(n); test::fail_stream fs{ fc, ios_, std::string{s + pre, len - pre}}; test_parser p(fc); error_code ec; - async_read(fs, sb, p, do_yield[ec]); + async_read(fs, b, p, do_yield[ec]); if(! ec) break; } @@ -106,10 +106,10 @@ public: { try { - streambuf sb; + multi_buffer b; test::string_istream ss(ios_, "GET / X"); message_parser p; - read(ss, sb, p); + read(ss, b, p); fail(); } catch(std::exception const&) @@ -197,8 +197,8 @@ public: request m; try { - streambuf sb; - read(fs, sb, m); + multi_buffer b; + read(fs, b, m); break; } catch(std::exception const&) @@ -218,8 +218,8 @@ public: ); request m; error_code ec; - streambuf sb; - read(fs, sb, m, ec); + multi_buffer b; + read(fs, b, m, ec); if(! ec) break; } @@ -236,8 +236,8 @@ public: ); request m; error_code ec; - streambuf sb; - async_read(fs, sb, m, do_yield[ec]); + multi_buffer b; + async_read(fs, b, m, do_yield[ec]); if(! ec) break; } @@ -248,19 +248,19 @@ public: testEof(yield_context do_yield) { { - streambuf sb; + multi_buffer b; test::string_istream ss(ios_, ""); message_parser p; error_code ec; - read(ss, sb, p, ec); + read(ss, b, p, ec); BEAST_EXPECT(ec == boost::asio::error::eof); } { - streambuf sb; + multi_buffer b; test::string_istream ss(ios_, ""); message_parser p; error_code ec; - async_read(ss, sb, p, do_yield[ec]); + async_read(ss, b, p, do_yield[ec]); BEAST_EXPECT(ec == boost::asio::error::eof); } } @@ -286,9 +286,9 @@ public: test::string_istream is{ios, "GET / HTTP/1.1\r\n\r\n"}; BEAST_EXPECT(handler::count() == 0); - streambuf sb; + multi_buffer b; message m; - async_read(is, sb, m, handler{}); + async_read(is, b, m, handler{}); BEAST_EXPECT(handler::count() > 0); ios.stop(); BEAST_EXPECT(handler::count() > 0); @@ -305,9 +305,9 @@ public: test::string_istream is{ios, "GET / HTTP/1.1\r\n\r\n"}; BEAST_EXPECT(handler::count() == 0); - streambuf sb; + multi_buffer b; message m; - async_read(is, sb, m, handler{}); + async_read(is, b, m, handler{}); BEAST_EXPECT(handler::count() > 0); } BEAST_EXPECT(handler::count() == 0); diff --git a/test/http/write.cpp b/test/http/write.cpp index 656e59e6..9cb37f8f 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/test/websocket/frame.cpp b/test/websocket/frame.cpp index 550a49a5..d7c7a691 100644 --- a/test/websocket/frame.cpp +++ b/test/websocket/frame.cpp @@ -75,22 +75,22 @@ public: auto check = [&](frame_header const& fh) { - fh_streambuf sb; - write(sb, fh); + fh_streambuf b; + write(b, fh); close_code code; stream_base stream; stream.open(role); detail::frame_header fh1; auto const n = - stream.read_fh1(fh1, sb, code); + stream.read_fh1(fh1, b, code); if(! BEAST_EXPECT(! code)) return; - if(! BEAST_EXPECT(sb.size() == n)) + if(! BEAST_EXPECT(b.size() == n)) return; - stream.read_fh2(fh1, sb, code); + stream.read_fh2(fh1, b, code); if(! BEAST_EXPECT(! code)) return; - if(! BEAST_EXPECT(sb.size() == 0)) + if(! BEAST_EXPECT(b.size() == 0)) return; BEAST_EXPECT(fh1 == fh); }; @@ -127,25 +127,25 @@ public: auto check = [&](frame_header const& fh) { - fh_streambuf sb; - write(sb, fh); + fh_streambuf b; + write(b, fh); close_code code; stream_base stream; stream.open(role); detail::frame_header fh1; auto const n = - stream.read_fh1(fh1, sb, code); + stream.read_fh1(fh1, b, code); if(code) { pass(); return; } - if(! BEAST_EXPECT(sb.size() == n)) + if(! BEAST_EXPECT(b.size() == n)) return; - stream.read_fh2(fh1, sb, code); + stream.read_fh2(fh1, b, code); if(! BEAST_EXPECT(code)) return; - if(! BEAST_EXPECT(sb.size() == 0)) + if(! BEAST_EXPECT(b.size() == 0)) return; }; @@ -193,25 +193,25 @@ public: using boost::asio::buffer_copy; static role_type constexpr role = role_type::client; std::vector v{bs}; - fh_streambuf sb; - sb.commit(buffer_copy(sb.prepare(v.size()), buffer(v))); + fh_streambuf b; + b.commit(buffer_copy(b.prepare(v.size()), buffer(v))); stream_base stream; stream.open(role); close_code code; detail::frame_header fh; auto const n = - stream.read_fh1(fh, sb, code); + stream.read_fh1(fh, b, code); if(code) { pass(); return; } - if(! BEAST_EXPECT(sb.size() == n)) + if(! BEAST_EXPECT(b.size() == n)) return; - stream.read_fh2(fh, sb, code); + stream.read_fh2(fh, b, code); if(! BEAST_EXPECT(code)) return; - if(! BEAST_EXPECT(sb.size() == 0)) + if(! BEAST_EXPECT(b.size() == 0)) return; } diff --git a/test/websocket/ssl/ssl_server.cpp b/test/websocket/ssl/ssl_server.cpp index cb6896c1..7b3612c0 100644 --- a/test/websocket/ssl/ssl_server.cpp +++ b/test/websocket/ssl/ssl_server.cpp @@ -129,16 +129,16 @@ public: ws.write(boost::asio::buffer("Hello, world!", 13)); // Receive Secure WebSocket message, print and close using Beast - beast::streambuf sb; + beast::multi_buffer b; beast::websocket::opcode op; - ws.read(op, sb); + ws.read(op, b); ws.close(beast::websocket::close_code::normal); try { for(;;) { - ws.read(op, sb); - sb.consume(sb.size()); + ws.read(op, b); + b.consume(b.size()); } } catch(system_error const& se) @@ -147,7 +147,7 @@ public: throw; } BEAST_EXPECT(boost::lexical_cast( - buffers(sb.data())) == "Hello, world!"); + buffers(b.data())) == "Hello, world!"); } }; diff --git a/test/websocket/ssl/websocket_async_ssl_echo_server.hpp b/test/websocket/ssl/websocket_async_ssl_echo_server.hpp index 7e605f87..d4586210 100644 --- a/test/websocket/ssl/websocket_async_ssl_echo_server.hpp +++ b/test/websocket/ssl/websocket_async_ssl_echo_server.hpp @@ -9,7 +9,7 @@ #define WEBSOCKET_ASYNC_SSL_ECHO_SERVER_HPP #include -#include +#include #include #include #include @@ -156,7 +156,7 @@ private: boost::asio::ssl::stream> ws; boost::asio::io_service::strand strand; beast::websocket::opcode op; - beast::streambuf db; + beast::multi_buffer db; std::size_t id; data(async_ssl_echo_server& server_, diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 0a1e4254..08a85531 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -12,7 +12,7 @@ #include "websocket_sync_echo_server.hpp" #include -#include +#include #include #include #include @@ -747,8 +747,8 @@ public: try { opcode op; - streambuf sb; - c.read(ws, op, sb); + multi_buffer b; + c.read(ws, op, b); fail("success", __FILE__, __LINE__); } catch(system_error const& e) @@ -777,8 +777,8 @@ public: try { opcode op; - streambuf sb; - c.read(ws, op, sb); + multi_buffer b; + c.read(ws, op, b); fail("success", __FILE__, __LINE__); } catch(system_error const& e) @@ -805,8 +805,8 @@ public: try { opcode op; - streambuf sb; - c.read(ws, op, sb); + multi_buffer b; + c.read(ws, op, b); fail("success", __FILE__, __LINE__); } catch(system_error const& e) @@ -834,8 +834,8 @@ public: try { opcode op; - streambuf sb; - c.read(ws, op, sb); + multi_buffer b; + c.read(ws, op, b); fail("success", __FILE__, __LINE__); } catch(system_error const& e) @@ -1199,7 +1199,7 @@ public: if(! BEAST_EXPECTS(! ec, ec.message())) break; opcode op; - streambuf db; + multi_buffer db; ws.read(op, db, ec); if(! BEAST_EXPECTS(! ec, ec.message())) break; @@ -1225,7 +1225,7 @@ public: if(! BEAST_EXPECTS(! ec, ec.message())) break; opcode op; - streambuf db; + multi_buffer db; ws.async_read(op, db, do_yield[ec]); if(! BEAST_EXPECTS(! ec, ec.message())) break; @@ -1290,7 +1290,7 @@ public: // Read opcode op; - streambuf db; + multi_buffer db; ++count; ws.async_read(op, db, [&](error_code ec) @@ -1346,7 +1346,7 @@ public: ws.write(buffer_cat(sbuf("TEXT"), cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc))); opcode op; - streambuf db; + multi_buffer db; std::size_t count = 0; // Read text message with bad utf8. // Causes a close to be sent, blocking writes. @@ -1414,7 +1414,7 @@ public: ws.set_option(message_type(opcode::binary)); ws.write(sbuf("CLOSE")); opcode op; - streambuf db; + multi_buffer db; std::size_t count = 0; // Read a close frame. // Sends a close frame, blocking writes. @@ -1480,7 +1480,7 @@ public: ws.set_option(message_type(opcode::binary)); ws.write(sbuf("CLOSE")); opcode op; - streambuf db; + multi_buffer db; std::size_t count = 0; ws.async_read(op, db, [&](error_code ec) @@ -1531,7 +1531,7 @@ public: }); }); opcode op; - streambuf db; + multi_buffer db; ws.async_read(op, db, [&](error_code ec) { @@ -1562,9 +1562,9 @@ public: return; ws.write_frame(false, sbuf("u")); ws.write_frame(true, sbuf("v")); - streambuf sb; + multi_buffer b; opcode op; - ws.read(op, sb, ec); + ws.read(op, b, ec); if(! BEAST_EXPECTS(! ec, ec.message())) return; } @@ -1623,7 +1623,7 @@ public: try { opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); fail(); throw abort_test{}; @@ -1657,7 +1657,7 @@ public: { // receive echoed message opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); BEAST_EXPECT(op == opcode::text); BEAST_EXPECT(to_string(db.data()) == "Hello"); @@ -1691,7 +1691,7 @@ public: { // receive echoed message opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); BEAST_EXPECT(pong == 1); BEAST_EXPECT(op == opcode::binary); @@ -1713,7 +1713,7 @@ public: { // receive echoed message opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); BEAST_EXPECT(pong == 1); BEAST_EXPECT(to_string(db.data()) == "Hello, World!"); @@ -1730,9 +1730,9 @@ public: { // receive echoed message opcode op; - streambuf sb; - c.read(ws, op, sb); - BEAST_EXPECT(to_string(sb.data()) == "Now is the time for all good men"); + multi_buffer b; + c.read(ws, op, b); + BEAST_EXPECT(to_string(b.data()) == "Now is the time for all good men"); } ws.set_option(auto_fragment{false}); ws.set_option(write_buffer_size{4096}); @@ -1745,7 +1745,7 @@ public: { // receive echoed message opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); BEAST_EXPECT(to_string(db.data()) == s); } @@ -1759,7 +1759,7 @@ public: { // receive echoed message opcode op; - streambuf db; + multi_buffer db; c.read(ws, op, db); BEAST_EXPECT(op == opcode::text); BEAST_EXPECT(to_string(db.data()) == "Hello"); diff --git a/test/websocket/utf8_checker.cpp b/test/websocket/utf8_checker.cpp index 20dc3f37..ea210271 100644 --- a/test/websocket/utf8_checker.cpp +++ b/test/websocket/utf8_checker.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -379,15 +379,15 @@ public: consuming_buffers< boost::asio::const_buffers_1> cb{ boost::asio::const_buffers_1(s.data(), n)}; - streambuf sb{size}; + multi_buffer b{size}; while(n) { auto const amount = (std::min)(n, size); - sb.commit(buffer_copy(sb.prepare(amount), cb)); + b.commit(buffer_copy(b.prepare(amount), cb)); cb.consume(amount); n -= amount; } - BEAST_EXPECT(utf8.write(sb.data())); + BEAST_EXPECT(utf8.write(b.data())); BEAST_EXPECT(utf8.finish()); } } diff --git a/test/websocket/websocket_async_echo_server.hpp b/test/websocket/websocket_async_echo_server.hpp index ebbada11..14342150 100644 --- a/test/websocket/websocket_async_echo_server.hpp +++ b/test/websocket/websocket_async_echo_server.hpp @@ -9,7 +9,7 @@ #define BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP #include -#include +#include #include #include #include @@ -216,7 +216,7 @@ private: beast::websocket::stream ws; boost::asio::io_service::strand strand; beast::websocket::opcode op; - beast::streambuf db; + beast::multi_buffer db; std::size_t id; data(async_echo_server& server_, diff --git a/test/websocket/websocket_sync_echo_server.hpp b/test/websocket/websocket_sync_echo_server.hpp index 3c3ab4de..b454ffcb 100644 --- a/test/websocket/websocket_sync_echo_server.hpp +++ b/test/websocket/websocket_sync_echo_server.hpp @@ -9,7 +9,7 @@ #define BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP #include -#include +#include #include #include #include @@ -306,41 +306,41 @@ private: for(;;) { beast::websocket::opcode op; - beast::streambuf sb; - ws.read(op, sb, ec); + beast::multi_buffer b; + ws.read(op, b, ec); if(ec) { auto const s = ec.message(); break; } ws.set_option(beast::websocket::message_type{op}); - if(match(sb, "RAW")) + if(match(b, "RAW")) { boost::asio::write( - ws.next_layer(), sb.data(), ec); + ws.next_layer(), b.data(), ec); } - else if(match(sb, "TEXT")) + else if(match(b, "TEXT")) { ws.set_option( beast::websocket::message_type{ beast::websocket::opcode::text}); - ws.write(sb.data(), ec); + ws.write(b.data(), ec); } - else if(match(sb, "PING")) + else if(match(b, "PING")) { beast::websocket::ping_data payload; - sb.consume(buffer_copy( + b.consume(buffer_copy( buffer(payload.data(), payload.size()), - sb.data())); + b.data())); ws.ping(payload, ec); } - else if(match(sb, "CLOSE")) + else if(match(b, "CLOSE")) { ws.close({}, ec); } else { - ws.write(sb.data(), ec); + ws.write(b.data(), ec); } if(ec) break;