async_read works with dynamic_buffer v2.

This commit is contained in:
Klemens
2022-10-04 12:30:57 +08:00
committed by Klemens Morgenstern
parent 73922b72f9
commit 606d776ebb
2 changed files with 43 additions and 0 deletions

View File

@@ -692,6 +692,25 @@ public:
BEAST_EXPECTS(bt == 0, std::to_string(0));
}
{
// bytes_transferred returns length of header
request_parser<string_body> p;
test::stream s(ioc);
s.append(string_view(hdr));
s.append(string_view(body));
std::string res ;
auto fb = asio::dynamic_buffer(res);
error_code ec;
auto bt = read_header(s, fb, p, ec);
BEAST_EXPECTS(!ec, ec.message());
BEAST_EXPECT(bt == hdr.size());
// next read should be zero-size, success
bt = read_header(s, fb, p, ec);
BEAST_EXPECTS(!ec, ec.message());
BEAST_EXPECTS(bt == 0, std::to_string(0));
}
{
// incomplete header consumes all parsable header bytes
request_parser<string_body> p;

View File

@@ -137,6 +137,30 @@ public:
beast::error::timeout));
test::run(ioc);
}
{
stream<tcp::socket> ws1(ioc);
stream<tcp::socket> ws2(ioc);
test::connect(ws1.next_layer(), ws2.next_layer());
ws1.async_handshake("test", "/", test::success_handler());
ws2.async_accept(test::success_handler());
test::run(ioc);
std::string res ;
auto b = asio::dynamic_buffer(res);
ws1.set_option(stream_base::timeout{
stream_base::none(),
std::chrono::milliseconds(50),
false});
ws1.async_read(b, test::success_handler());
ws2.async_write(net::const_buffer("Hello, world!", 13),
test::success_handler());
test::run(ioc);
BEAST_EXPECT(res == "Hello, world!");
}
}
void