mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Rename to multi_buffer, basic_multi_buffer (API Change):
These classes are renamed: * streambuf to multi_buffer * basic_streambuf to basic_multi_buffer
This commit is contained in:
@ -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
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -419,7 +419,7 @@ start. Other design goals:
|
||||
[```
|
||||
beast::async_completion<ReadHandler, void(error_code)> completion(handler);
|
||||
read_op<DynamicBuffer, decltype(completion.handler)>{
|
||||
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.
|
||||
|
@ -45,17 +45,17 @@ int main()
|
||||
beast::http::write(sock, req);
|
||||
|
||||
// Receive and print HTTP response using beast
|
||||
beast::streambuf sb;
|
||||
beast::http::response<beast::http::dynamic_body> resp;
|
||||
beast::http::read(sock, sb, resp);
|
||||
std::cout << resp;
|
||||
beast::multi_buffer b;
|
||||
beast::http::response<beast::http::dynamic_body> res;
|
||||
beast::http::read(sock, b, res);
|
||||
std::cout << res;
|
||||
}
|
||||
```
|
||||
[heading WebSocket]
|
||||
|
||||
Establish a WebSocket connection, send a message and receive the reply:
|
||||
```
|
||||
#include <beast/core/to_string.hpp>
|
||||
#include <beast/core.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <iostream>
|
||||
@ -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";
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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.
|
||||
|
@ -153,7 +153,7 @@
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="beast.ref.async_completion">async_completion</link></member>
|
||||
<member><link linkend="beast.ref.basic_flat_streambuf">basic_flat_streambuf</link></member>
|
||||
<member><link linkend="beast.ref.basic_streambuf">basic_streambuf</link></member>
|
||||
<member><link linkend="beast.ref.basic_multi_buffer">basic_multi_buffer</link></member>
|
||||
<member><link linkend="beast.ref.buffers_adapter">buffers_adapter</link></member>
|
||||
<member><link linkend="beast.ref.consuming_buffers">consuming_buffers</link></member>
|
||||
<member><link linkend="beast.ref.dynabuf_readstream">dynabuf_readstream</link></member>
|
||||
@ -164,10 +164,10 @@
|
||||
<member><link linkend="beast.ref.flat_streambuf">flat_streambuf</link></member>
|
||||
<member><link linkend="beast.ref.handler_alloc">handler_alloc</link></member>
|
||||
<member><link linkend="beast.ref.handler_ptr">handler_ptr</link></member>
|
||||
<member><link linkend="beast.ref.multi_buffer">multi_buffer</link></member>
|
||||
<member><link linkend="beast.ref.static_streambuf">static_streambuf</link></member>
|
||||
<member><link linkend="beast.ref.static_streambuf_n">static_streambuf_n</link></member>
|
||||
<member><link linkend="beast.ref.static_string">static_string</link></member>
|
||||
<member><link linkend="beast.ref.streambuf">streambuf</link></member>
|
||||
<member><link linkend="beast.ref.system_error">system_error</link></member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
@ -294,13 +294,13 @@ all of the buffers representing the message are known ahead of time:
|
||||
```
|
||||
void echo(beast::websocket::stream<boost::asio::ip::tcp::socket>& 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<boost::asio::ip::tcp::socket>& 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;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <beast/core/handler_helpers.hpp>
|
||||
#include <beast/core/handler_ptr.hpp>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
@ -181,7 +181,7 @@ private:
|
||||
class peer : public std::enable_shared_from_this<peer>
|
||||
{
|
||||
int id_;
|
||||
streambuf sb_;
|
||||
multi_buffer sb_;
|
||||
socket_type sock_;
|
||||
http_async_server& server_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "urls_large_data.hpp"
|
||||
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
@ -46,8 +46,8 @@ int main(int, char const*[])
|
||||
prepare(req);
|
||||
write(sock, req);
|
||||
response<string_body> 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)
|
||||
|
@ -5,6 +5,7 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <beast/core.hpp>
|
||||
#include <beast/http.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
@ -33,8 +34,8 @@ int main()
|
||||
beast::http::write(sock, req);
|
||||
|
||||
// Receive and print HTTP response using beast
|
||||
beast::streambuf sb;
|
||||
beast::http::response<beast::http::dynamic_body> resp;
|
||||
beast::http::read(sock, sb, resp);
|
||||
std::cout << resp;
|
||||
beast::multi_buffer b;
|
||||
beast::http::response<beast::http::dynamic_body> res;
|
||||
beast::http::read(sock, b, res);
|
||||
std::cout << res;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <beast/http.hpp>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@ -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();
|
||||
|
@ -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<beast::http::dynamic_body> resp;
|
||||
beast::http::read(stream, sb, resp);
|
||||
beast::http::read(stream, b, resp);
|
||||
std::cout << resp;
|
||||
|
||||
// Shut down SSL on the stream
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define WEBSOCKET_ASYNC_ECHO_SERVER_HPP
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket/stream.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -216,7 +216,7 @@ private:
|
||||
beast::websocket::stream<socket_type> 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_,
|
||||
|
@ -5,7 +5,7 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <iostream>
|
||||
@ -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";
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define WEBSOCKET_SYNC_ECHO_SERVER_HPP
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -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;
|
||||
}
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include <beast/core/handler_concepts.hpp>
|
||||
#include <beast/core/handler_helpers.hpp>
|
||||
#include <beast/core/handler_ptr.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/prepare_buffers.hpp>
|
||||
#include <beast/core/static_streambuf.hpp>
|
||||
#include <beast/core/static_string.hpp>
|
||||
#include <beast/core/stream_concepts.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <beast/core/buffer_concepts.hpp>
|
||||
#include <beast/core/error.hpp>
|
||||
#include <beast/core/stream_concepts.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/core/detail/get_lowest_layer.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
@ -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 <beast/core/detail/type_traits.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
@ -83,7 +83,7 @@ namespace beast {
|
||||
*/
|
||||
|
||||
template<class Allocator>
|
||||
class basic_streambuf<Allocator>::element
|
||||
class basic_multi_buffer<Allocator>::element
|
||||
: public boost::intrusive::list_base_hook<
|
||||
boost::intrusive::link_mode<
|
||||
boost::intrusive::normal_link>>
|
||||
@ -117,14 +117,14 @@ public:
|
||||
};
|
||||
|
||||
template<class Allocator>
|
||||
class basic_streambuf<Allocator>::const_buffers_type
|
||||
class basic_multi_buffer<Allocator>::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 Allocator>
|
||||
class basic_streambuf<Allocator>::mutable_buffers_type
|
||||
class basic_multi_buffer<Allocator>::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 Allocator>
|
||||
class basic_streambuf<Allocator>::const_buffers_type::const_iterator
|
||||
class basic_multi_buffer<Allocator>::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<class Allocator>
|
||||
basic_streambuf<Allocator>::const_buffers_type::const_buffers_type(
|
||||
basic_streambuf const& sb)
|
||||
: sb_(&sb)
|
||||
basic_multi_buffer<Allocator>::const_buffers_type::const_buffers_type(
|
||||
basic_multi_buffer const& b)
|
||||
: sb_(&b)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::const_buffers_type::begin() const ->
|
||||
basic_multi_buffer<Allocator>::const_buffers_type::begin() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*sb_, sb_->list_.begin()};
|
||||
@ -272,7 +272,7 @@ basic_streambuf<Allocator>::const_buffers_type::begin() const ->
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::const_buffers_type::end() const ->
|
||||
basic_multi_buffer<Allocator>::const_buffers_type::end() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*sb_, sb_->out_ ==
|
||||
@ -283,9 +283,9 @@ basic_streambuf<Allocator>::const_buffers_type::end() const ->
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<class Allocator>
|
||||
class basic_streambuf<Allocator>::mutable_buffers_type::const_iterator
|
||||
class basic_multi_buffer<Allocator>::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<class Allocator>
|
||||
basic_streambuf<Allocator>::mutable_buffers_type::mutable_buffers_type(
|
||||
basic_streambuf const& sb)
|
||||
: sb_(&sb)
|
||||
basic_multi_buffer<Allocator>::mutable_buffers_type::mutable_buffers_type(
|
||||
basic_multi_buffer const& b)
|
||||
: sb_(&b)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::mutable_buffers_type::begin() const ->
|
||||
basic_multi_buffer<Allocator>::mutable_buffers_type::begin() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*sb_, sb_->out_};
|
||||
@ -383,7 +383,7 @@ basic_streambuf<Allocator>::mutable_buffers_type::begin() const ->
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::mutable_buffers_type::end() const ->
|
||||
basic_multi_buffer<Allocator>::mutable_buffers_type::end() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*sb_, sb_->list_.end()};
|
||||
@ -392,14 +392,14 @@ basic_streambuf<Allocator>::mutable_buffers_type::end() const ->
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<class Allocator>
|
||||
basic_streambuf<Allocator>::~basic_streambuf()
|
||||
basic_multi_buffer<Allocator>::~basic_multi_buffer()
|
||||
{
|
||||
delete_list();
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
basic_streambuf<Allocator>::
|
||||
basic_streambuf(basic_streambuf&& other)
|
||||
basic_multi_buffer<Allocator>::
|
||||
basic_multi_buffer(basic_multi_buffer&& other)
|
||||
: detail::empty_base_optimization<allocator_type>(
|
||||
std::move(other.member()))
|
||||
, alloc_size_(other.alloc_size_)
|
||||
@ -420,10 +420,10 @@ basic_streambuf(basic_streambuf&& other)
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
basic_streambuf<Allocator>::
|
||||
basic_streambuf(basic_streambuf&& other,
|
||||
basic_multi_buffer<Allocator>::
|
||||
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<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::operator=(
|
||||
basic_streambuf&& other) -> basic_streambuf&
|
||||
basic_multi_buffer<Allocator>::operator=(
|
||||
basic_multi_buffer&& other) -> basic_multi_buffer&
|
||||
{
|
||||
if(this == &other)
|
||||
return *this;
|
||||
@ -448,28 +448,28 @@ basic_streambuf<Allocator>::operator=(
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
basic_streambuf<Allocator>::
|
||||
basic_streambuf(basic_streambuf const& other)
|
||||
: basic_streambuf(other.alloc_size_,
|
||||
basic_multi_buffer<Allocator>::
|
||||
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<class Allocator>
|
||||
basic_streambuf<Allocator>::
|
||||
basic_streambuf(basic_streambuf const& other,
|
||||
basic_multi_buffer<Allocator>::
|
||||
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<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::operator=(
|
||||
basic_streambuf const& other) ->
|
||||
basic_streambuf&
|
||||
basic_multi_buffer<Allocator>::operator=(
|
||||
basic_multi_buffer const& other) ->
|
||||
basic_multi_buffer&
|
||||
{
|
||||
if(this == &other)
|
||||
return *this;
|
||||
@ -483,9 +483,9 @@ basic_streambuf<Allocator>::operator=(
|
||||
|
||||
template<class Allocator>
|
||||
template<class OtherAlloc>
|
||||
basic_streambuf<Allocator>::basic_streambuf(
|
||||
basic_streambuf<OtherAlloc> const& other)
|
||||
: basic_streambuf(other.alloc_size_)
|
||||
basic_multi_buffer<Allocator>::basic_multi_buffer(
|
||||
basic_multi_buffer<OtherAlloc> 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<Allocator>::basic_streambuf(
|
||||
|
||||
template<class Allocator>
|
||||
template<class OtherAlloc>
|
||||
basic_streambuf<Allocator>::basic_streambuf(
|
||||
basic_streambuf<OtherAlloc> const& other,
|
||||
basic_multi_buffer<Allocator>::basic_multi_buffer(
|
||||
basic_multi_buffer<OtherAlloc> 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<Allocator>::basic_streambuf(
|
||||
template<class Allocator>
|
||||
template<class OtherAlloc>
|
||||
auto
|
||||
basic_streambuf<Allocator>::operator=(
|
||||
basic_streambuf<OtherAlloc> const& other) ->
|
||||
basic_streambuf&
|
||||
basic_multi_buffer<Allocator>::operator=(
|
||||
basic_multi_buffer<OtherAlloc> const& other) ->
|
||||
basic_multi_buffer&
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
clear();
|
||||
@ -516,7 +516,7 @@ basic_streambuf<Allocator>::operator=(
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
basic_streambuf<Allocator>::basic_streambuf(
|
||||
basic_multi_buffer<Allocator>::basic_multi_buffer(
|
||||
std::size_t alloc_size, Allocator const& alloc)
|
||||
: detail::empty_base_optimization<allocator_type>(alloc)
|
||||
, out_(list_.end())
|
||||
@ -529,7 +529,7 @@ basic_streambuf<Allocator>::basic_streambuf(
|
||||
|
||||
template<class Allocator>
|
||||
std::size_t
|
||||
basic_streambuf<Allocator>::capacity() const
|
||||
basic_multi_buffer<Allocator>::capacity() const
|
||||
{
|
||||
auto pos = out_;
|
||||
if(pos == list_.end())
|
||||
@ -542,7 +542,7 @@ basic_streambuf<Allocator>::capacity() const
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::
|
||||
basic_multi_buffer<Allocator>::
|
||||
data() const ->
|
||||
const_buffers_type
|
||||
{
|
||||
@ -551,7 +551,7 @@ data() const ->
|
||||
|
||||
template<class Allocator>
|
||||
auto
|
||||
basic_streambuf<Allocator>::prepare(size_type n) ->
|
||||
basic_multi_buffer<Allocator>::prepare(size_type n) ->
|
||||
mutable_buffers_type
|
||||
{
|
||||
list_type reuse;
|
||||
@ -630,7 +630,7 @@ basic_streambuf<Allocator>::prepare(size_type n) ->
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::commit(size_type n)
|
||||
basic_multi_buffer<Allocator>::commit(size_type n)
|
||||
{
|
||||
if(list_.empty())
|
||||
return;
|
||||
@ -670,7 +670,7 @@ basic_streambuf<Allocator>::commit(size_type n)
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::consume(size_type n)
|
||||
basic_multi_buffer<Allocator>::consume(size_type n)
|
||||
{
|
||||
if(list_.empty())
|
||||
return;
|
||||
@ -731,7 +731,7 @@ basic_streambuf<Allocator>::consume(size_type n)
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::
|
||||
basic_multi_buffer<Allocator>::
|
||||
clear()
|
||||
{
|
||||
delete_list();
|
||||
@ -745,8 +745,8 @@ clear()
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::
|
||||
move_assign(basic_streambuf& other, std::false_type)
|
||||
basic_multi_buffer<Allocator>::
|
||||
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<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::
|
||||
move_assign(basic_streambuf& other, std::true_type)
|
||||
basic_multi_buffer<Allocator>::
|
||||
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<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::
|
||||
copy_assign(basic_streambuf const& other, std::false_type)
|
||||
basic_multi_buffer<Allocator>::
|
||||
copy_assign(basic_multi_buffer const& other, std::false_type)
|
||||
{
|
||||
beast::detail::ignore_unused(other);
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::
|
||||
copy_assign(basic_streambuf const& other, std::true_type)
|
||||
basic_multi_buffer<Allocator>::
|
||||
copy_assign(basic_multi_buffer const& other, std::true_type)
|
||||
{
|
||||
this->member() = other.member();
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::delete_list()
|
||||
basic_multi_buffer<Allocator>::delete_list()
|
||||
{
|
||||
for(auto iter = list_.begin(); iter != list_.end();)
|
||||
{
|
||||
@ -813,7 +813,7 @@ basic_streambuf<Allocator>::delete_list()
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_streambuf<Allocator>::debug_check() const
|
||||
basic_multi_buffer<Allocator>::debug_check() const
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
using boost::asio::buffer_size;
|
||||
@ -853,19 +853,19 @@ basic_streambuf<Allocator>::debug_check() const
|
||||
|
||||
template<class Allocator>
|
||||
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);
|
||||
}
|
@ -297,7 +297,7 @@ static_streambuf::prepare(std::size_t n) ->
|
||||
{
|
||||
if(n > static_cast<std::size_t>(end_ - out_))
|
||||
throw detail::make_exception<std::length_error>(
|
||||
"no space in streambuf", __FILE__, __LINE__);
|
||||
"no space in static_buffer", __FILE__, __LINE__);
|
||||
last_ = out_ + n;
|
||||
return mutable_buffers_type{out_, n};
|
||||
}
|
||||
|
@ -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 <beast/config.hpp>
|
||||
#include <beast/core/detail/empty_base_optimization.hpp>
|
||||
@ -31,7 +31,7 @@ namespace beast {
|
||||
@tparam Allocator The allocator to use for managing memory.
|
||||
*/
|
||||
template<class Allocator>
|
||||
class basic_streambuf
|
||||
class basic_multi_buffer
|
||||
#if ! BEAST_DOXYGEN
|
||||
: private detail::empty_base_optimization<
|
||||
typename std::allocator_traits<Allocator>::
|
||||
@ -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<class OtherAlloc>
|
||||
basic_streambuf(basic_streambuf<OtherAlloc> const&);
|
||||
basic_multi_buffer(basic_multi_buffer<OtherAlloc> const&);
|
||||
|
||||
/** Copy constructor.
|
||||
|
||||
@ -178,7 +178,7 @@ public:
|
||||
stream buffer.
|
||||
*/
|
||||
template<class OtherAlloc>
|
||||
basic_streambuf(basic_streambuf<OtherAlloc> const&,
|
||||
basic_multi_buffer(basic_multi_buffer<OtherAlloc> const&,
|
||||
allocator_type const& alloc);
|
||||
|
||||
/** Copy assignment.
|
||||
@ -187,7 +187,7 @@ public:
|
||||
buffer's input sequence, and an empty output sequence.
|
||||
*/
|
||||
template<class OtherAlloc>
|
||||
basic_streambuf& operator=(basic_streambuf<OtherAlloc> const&);
|
||||
basic_multi_buffer& operator=(basic_multi_buffer<OtherAlloc> 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<class OtherAllocator>
|
||||
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<std::allocator<char>>;
|
||||
using multi_buffer = basic_multi_buffer<std::allocator<char>>;
|
||||
|
||||
} // beast
|
||||
|
||||
#include <beast/core/impl/streambuf.ipp>
|
||||
#include <beast/core/impl/multi_buffer.ipp>
|
||||
|
||||
#endif
|
@ -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
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <beast/config.hpp>
|
||||
#include <beast/core/error.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
|
||||
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<streambuf>;
|
||||
using dynamic_body = basic_dynamic_body<multi_buffer>;
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <beast/core/handler_helpers.hpp>
|
||||
#include <beast/core/handler_ptr.hpp>
|
||||
#include <beast/core/stream_concepts.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/core/detail/sync_ostream.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
#include <condition_variable>
|
||||
@ -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<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<class AsyncWriteStream,
|
||||
@ -223,16 +223,16 @@ async_write(AsyncWriteStream& stream,
|
||||
"AsyncWriteStream requirements not met");
|
||||
beast::async_completion<WriteHandler,
|
||||
void(error_code)> 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<AsyncWriteStream,
|
||||
decltype(completion.handler)>{
|
||||
completion.handler, stream, std::move(sb)};
|
||||
completion.handler, stream, std::move(b)};
|
||||
return completion.result.get();
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ struct write_preparation
|
||||
{
|
||||
message<isRequest, Body, Fields> 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<SyncWriteStream> wf{
|
||||
|
@ -98,7 +98,7 @@ class stream : public detail::stream_base
|
||||
{
|
||||
friend class stream_test;
|
||||
|
||||
dynabuf_readstream<NextLayer, streambuf> stream_;
|
||||
dynabuf_readstream<NextLayer, multi_buffer> stream_;
|
||||
|
||||
public:
|
||||
/// The type of the next layer.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <beast/core/buffers_adapter.hpp>
|
||||
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
@ -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);
|
||||
|
@ -8,7 +8,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/core/dynabuf_readstream.hpp>
|
||||
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/test/fail_stream.hpp>
|
||||
#include <beast/test/string_istream.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
@ -29,16 +29,16 @@ public:
|
||||
using socket_type = boost::asio::ip::tcp::socket;
|
||||
boost::asio::io_service ios;
|
||||
{
|
||||
dynabuf_readstream<socket_type, streambuf> srs(ios);
|
||||
dynabuf_readstream<socket_type, streambuf> srs2(std::move(srs));
|
||||
dynabuf_readstream<socket_type, multi_buffer> srs(ios);
|
||||
dynabuf_readstream<socket_type, multi_buffer> 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<socket_type&, streambuf> srs(sock);
|
||||
dynabuf_readstream<socket_type&, streambuf> srs2(std::move(srs));
|
||||
dynabuf_readstream<socket_type&, multi_buffer> srs(sock);
|
||||
dynabuf_readstream<socket_type&, multi_buffer> 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)));
|
||||
|
361
test/core/multi_buffer.cpp
Normal file
361
test/core/multi_buffer.cpp
Normal file
@ -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 <beast/core/multi_buffer.hpp>
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
#include <beast/core/buffer_concepts.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/test/test_allocator.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace beast {
|
||||
|
||||
static_assert(is_DynamicBuffer<multi_buffer>::value, "");
|
||||
|
||||
class multi_buffer_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
return boost::lexical_cast<
|
||||
std::string>(buffers(bs));
|
||||
}
|
||||
|
||||
template<class Alloc1, class Alloc2>
|
||||
static
|
||||
bool
|
||||
eq(basic_multi_buffer<Alloc1> const& sb1,
|
||||
basic_multi_buffer<Alloc2> const& sb2)
|
||||
{
|
||||
return to_string(sb1.data()) == to_string(sb2.data());
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
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<class U, class V>
|
||||
static
|
||||
void
|
||||
self_assign(U& u, V&& v)
|
||||
{
|
||||
u = std::forward<V>(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<char, false, false, false, false, false>;
|
||||
using type = basic_multi_buffer<alloc_type>;
|
||||
type b;
|
||||
}
|
||||
{
|
||||
using alloc_type =
|
||||
test_allocator<char, false, false, false, false, false>;
|
||||
using type = basic_multi_buffer<alloc_type>;
|
||||
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
|
@ -8,7 +8,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/core/ostream.hpp>
|
||||
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <ostream>
|
||||
@ -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<std::string>(
|
||||
buffers(sb.data())) == "Hello, world!\n");
|
||||
buffers(b.data())) == "Hello, world!\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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 <beast/core/streambuf.hpp>
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
#include <beast/core/buffer_concepts.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/test/test_allocator.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace beast {
|
||||
|
||||
static_assert(is_DynamicBuffer<streambuf>::value, "");
|
||||
|
||||
class basic_streambuf_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
return boost::lexical_cast<
|
||||
std::string>(buffers(bs));
|
||||
}
|
||||
|
||||
template<class Alloc1, class Alloc2>
|
||||
static
|
||||
bool
|
||||
eq(basic_streambuf<Alloc1> const& sb1,
|
||||
basic_streambuf<Alloc2> const& sb2)
|
||||
{
|
||||
return to_string(sb1.data()) == to_string(sb2.data());
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
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<class U, class V>
|
||||
static
|
||||
void
|
||||
self_assign(U& u, V&& v)
|
||||
{
|
||||
u = std::forward<V>(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<char, false, false, false, false, false>;
|
||||
using sb_type = basic_streambuf<alloc_type>;
|
||||
sb_type sb;
|
||||
BEAST_EXPECT(sb.get_allocator().id() == 1);
|
||||
}
|
||||
{
|
||||
using alloc_type =
|
||||
test_allocator<char, false, false, false, false, false>;
|
||||
using sb_type = basic_streambuf<alloc_type>;
|
||||
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
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <beast/core/buffer_cat.hpp>
|
||||
#include <beast/core/consuming_buffers.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
|
||||
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<true> 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);
|
||||
|
@ -104,8 +104,8 @@ public:
|
||||
"*"
|
||||
};
|
||||
message<true, direct_body, fields> 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<false, direct_body, fields> 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<true, direct_body, fields> 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<true, indirect_body, fields> 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<false, indirect_body, fields> 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<true, indirect_body, fields> 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<true, fields> 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<false, fields> 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<true, fields> 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<true>(os, sb, is);
|
||||
flat_streambuf b{16};
|
||||
relay<true>(os, b, is);
|
||||
}
|
||||
|
||||
// end of file
|
||||
@ -410,8 +410,8 @@ public:
|
||||
3 // max_read
|
||||
};
|
||||
test::string_ostream os{ios_};
|
||||
flat_streambuf sb{16};
|
||||
relay<false>(os, sb, is);
|
||||
flat_streambuf b{16};
|
||||
relay<false>(os, b, is);
|
||||
}
|
||||
|
||||
// chunked
|
||||
@ -427,8 +427,8 @@ public:
|
||||
2 // max_read
|
||||
};
|
||||
test::string_ostream os{ios_};
|
||||
flat_streambuf sb{16};
|
||||
relay<true>(os, sb, is);
|
||||
flat_streambuf b{16};
|
||||
relay<true>(os, b, is);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ public:
|
||||
"xyz";
|
||||
test::string_istream ss(ios_, s);
|
||||
message_parser<false, dynamic_body, fields> p;
|
||||
streambuf sb;
|
||||
read(ss, sb, p);
|
||||
multi_buffer b;
|
||||
read(ss, b, p);
|
||||
auto const& m = p.get();
|
||||
BEAST_EXPECT(boost::lexical_cast<std::string>(
|
||||
buffers(m.body.data())) == "xyz");
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <beast/test/string_ostream.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
#include <beast/core/flat_streambuf.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/header_parser.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
@ -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<true, string_body, fields> 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<true, string_body, fields> 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<true, fields> 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<true,
|
||||
string_body, fields> p1{std::move(p0)};
|
||||
read(ss, sb, p1, ec);
|
||||
read(ss, b, p1, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(p1.get().body == "*****");
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <beast/http.hpp>
|
||||
#include <beast/core/consuming_buffers.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <chrono>
|
||||
@ -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<streambuf>;
|
||||
using corpus = std::vector<multi_buffer>;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<isRequest> 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<test::string_istream> fs{
|
||||
fc, ios_, std::string{s + pre, len - pre}};
|
||||
test_parser<isRequest> 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<isRequest> 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<test::string_istream> fs{
|
||||
fc, ios_, std::string{s + pre, len - pre}};
|
||||
test_parser<isRequest> 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<true, dynamic_body, fields> p;
|
||||
read(ss, sb, p);
|
||||
read(ss, b, p);
|
||||
fail();
|
||||
}
|
||||
catch(std::exception const&)
|
||||
@ -197,8 +197,8 @@ public:
|
||||
request<dynamic_body> 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<dynamic_body> 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<dynamic_body> 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<true, dynamic_body, fields> 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<true, dynamic_body, fields> 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<true, dynamic_body, fields> 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<true, dynamic_body, fields> m;
|
||||
async_read(is, sb, m, handler{});
|
||||
async_read(is, b, m, handler{});
|
||||
BEAST_EXPECT(handler::count() > 0);
|
||||
}
|
||||
BEAST_EXPECT(handler::count() == 0);
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <beast/core/error.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/test/fail_stream.hpp>
|
||||
#include <beast/test/string_ostream.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
|
@ -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<std::uint8_t> 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;
|
||||
}
|
||||
|
||||
|
@ -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<std::string>(
|
||||
buffers(sb.data())) == "Hello, world!");
|
||||
buffers(b.data())) == "Hello, world!");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define WEBSOCKET_ASYNC_SSL_ECHO_SERVER_HPP
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket/ssl.hpp>
|
||||
#include <beast/websocket/stream.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
@ -156,7 +156,7 @@ private:
|
||||
boost::asio::ssl::stream<socket_type>> 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_,
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "websocket_sync_echo_server.hpp"
|
||||
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/test/fail_stream.hpp>
|
||||
#include <beast/test/string_istream.hpp>
|
||||
#include <beast/test/string_iostream.hpp>
|
||||
@ -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");
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <beast/websocket/detail/utf8_checker.hpp>
|
||||
|
||||
#include <beast/core/consuming_buffers.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <array>
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket/stream.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -216,7 +216,7 @@ private:
|
||||
beast::websocket::stream<socket_type> 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_,
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@ -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;
|
||||
|
Reference in New Issue
Block a user