diff --git a/CHANGELOG.md b/CHANGELOG.md index 55906cfa..e52e7ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 43 * Require Boost 1.64.0 * Fix strict aliasing warnings in buffers_view * Tidy up buffer_prefix overloads and test +* Add write limit to test::string_ostream -------------------------------------------------------------------------------- diff --git a/extras/beast/test/string_ostream.hpp b/extras/beast/test/string_ostream.hpp index 4c08bd21..591d35b6 100644 --- a/extras/beast/test/string_ostream.hpp +++ b/extras/beast/test/string_ostream.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -22,13 +23,17 @@ namespace test { class string_ostream { boost::asio::io_service& ios_; + std::size_t write_max_; public: std::string str; explicit - string_ostream(boost::asio::io_service& ios) + string_ostream(boost::asio::io_service& ios, + std::size_t write_max = + (std::numeric_limits::max)()) : ios_(ios) + , write_max_(write_max) { } @@ -87,11 +92,12 @@ public: write_some( ConstBufferSequence const& buffers, error_code&) { - auto const n = buffer_size(buffers); using boost::asio::buffer_size; using boost::asio::buffer_cast; + auto const n = + (std::min)(buffer_size(buffers), write_max_); str.reserve(str.size() + n); - for(auto const& buffer : buffers) + for(auto const& buffer : buffer_prefix(n, buffers)) str.append(buffer_cast(buffer), buffer_size(buffer)); return n;