mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 06:15:24 +02:00
Add write limit to test::string_ostream
This commit is contained in:
@@ -3,6 +3,7 @@ Version 43
|
|||||||
* Require Boost 1.64.0
|
* Require Boost 1.64.0
|
||||||
* Fix strict aliasing warnings in buffers_view
|
* Fix strict aliasing warnings in buffers_view
|
||||||
* Tidy up buffer_prefix overloads and test
|
* Tidy up buffer_prefix overloads and test
|
||||||
|
* Add write limit to test::string_ostream
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <beast/core/async_result.hpp>
|
#include <beast/core/async_result.hpp>
|
||||||
#include <beast/core/bind_handler.hpp>
|
#include <beast/core/bind_handler.hpp>
|
||||||
|
#include <beast/core/buffer_prefix.hpp>
|
||||||
#include <beast/core/error.hpp>
|
#include <beast/core/error.hpp>
|
||||||
#include <beast/websocket/teardown.hpp>
|
#include <beast/websocket/teardown.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
@@ -22,13 +23,17 @@ namespace test {
|
|||||||
class string_ostream
|
class string_ostream
|
||||||
{
|
{
|
||||||
boost::asio::io_service& ios_;
|
boost::asio::io_service& ios_;
|
||||||
|
std::size_t write_max_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
string_ostream(boost::asio::io_service& ios)
|
string_ostream(boost::asio::io_service& ios,
|
||||||
|
std::size_t write_max =
|
||||||
|
(std::numeric_limits<std::size_t>::max)())
|
||||||
: ios_(ios)
|
: ios_(ios)
|
||||||
|
, write_max_(write_max)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,11 +92,12 @@ public:
|
|||||||
write_some(
|
write_some(
|
||||||
ConstBufferSequence const& buffers, error_code&)
|
ConstBufferSequence const& buffers, error_code&)
|
||||||
{
|
{
|
||||||
auto const n = buffer_size(buffers);
|
|
||||||
using boost::asio::buffer_size;
|
using boost::asio::buffer_size;
|
||||||
using boost::asio::buffer_cast;
|
using boost::asio::buffer_cast;
|
||||||
|
auto const n =
|
||||||
|
(std::min)(buffer_size(buffers), write_max_);
|
||||||
str.reserve(str.size() + n);
|
str.reserve(str.size() + n);
|
||||||
for(auto const& buffer : buffers)
|
for(auto const& buffer : buffer_prefix(n, buffers))
|
||||||
str.append(buffer_cast<char const*>(buffer),
|
str.append(buffer_cast<char const*>(buffer),
|
||||||
buffer_size(buffer));
|
buffer_size(buffer));
|
||||||
return n;
|
return n;
|
||||||
|
Reference in New Issue
Block a user