forked from boostorg/beast
Refactor HTTP operations (API Change):
* Revise stream algorithm javadocs * HTTP stream algorithms now use beast::read and beast::async_read with a custom completion condition. API Changes: * HTTP stream algorithms return the number of bytes transferred from the stream. Previously, they returned the number of bytes consumed by the parser. Actions Required: * Callers depending on the return value of http::read or http::async_read overloads should adjust the usage of the returned value as needed.
This commit is contained in:
1 parent
c11682032b
commit
35e4f321bc
13 files changed
+1597
-823
No files matched your search
@@ -44,6 +44,7 @@ add_executable (tests-beast-core
|
||||
static_buffer.cpp
|
||||
string_param.cpp
|
||||
type_traits.cpp
|
||||
detail_read.cpp
|
||||
detail/base64.cpp
|
||||
detail/clamp.cpp
|
||||
detail/lean_tuple.cpp
|
||||
|
||||
@@ -34,6 +34,7 @@ local SOURCES =
|
||||
string.cpp
|
||||
string_param.cpp
|
||||
type_traits.cpp
|
||||
detail_read.cpp
|
||||
detail/base64.cpp
|
||||
detail/clamp.cpp
|
||||
detail/lean_tuple.cpp
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// Copyright (c) 2018 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/detail/read.hpp>
|
||||
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/completion_condition.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
namespace detail {
|
||||
|
||||
class read_test : public unit_test::suite
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
void
|
||||
testRead()
|
||||
{
|
||||
{
|
||||
net::io_context ioc;
|
||||
test::stream ts(ioc);
|
||||
ostream(ts.buffer()) << "test";
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
read(ts, b, boost::asio::transfer_at_least(4), ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "test");
|
||||
}
|
||||
{
|
||||
net::io_context ioc;
|
||||
test::stream ts(ioc);
|
||||
auto tc = connect(ts);
|
||||
ostream(ts.buffer()) << "test";
|
||||
tc.close();
|
||||
error_code ec;
|
||||
flat_buffer b;
|
||||
read(ts, b, boost::asio::transfer_all(), ec);
|
||||
BEAST_EXPECTS(ec == boost::asio::error::eof, ec.message());
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "test");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testAsyncRead()
|
||||
{
|
||||
{
|
||||
net::io_context ioc;
|
||||
test::stream ts(ioc);
|
||||
ostream(ts.buffer()) << "test";
|
||||
flat_buffer b;
|
||||
error_code ec;
|
||||
bool invoked = false;
|
||||
async_read(ts, b, boost::asio::transfer_at_least(4),
|
||||
[&invoked, &ec](error_code ec_, std::size_t)
|
||||
{
|
||||
ec = ec_;
|
||||
invoked = true;
|
||||
});
|
||||
ioc.run();
|
||||
BEAST_EXPECT(invoked);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "test");
|
||||
}
|
||||
{
|
||||
net::io_context ioc;
|
||||
test::stream ts(ioc);
|
||||
auto tc = connect(ts);
|
||||
ostream(ts.buffer()) << "test";
|
||||
tc.close();
|
||||
flat_buffer b;
|
||||
error_code ec;
|
||||
bool invoked = false;
|
||||
async_read(ts, b, boost::asio::transfer_all(),
|
||||
[&invoked, &ec](error_code ec_, std::size_t)
|
||||
{
|
||||
ec = ec_;
|
||||
invoked = true;
|
||||
});
|
||||
ioc.run();
|
||||
BEAST_EXPECT(invoked);
|
||||
BEAST_EXPECTS(ec == boost::asio::error::eof, ec.message());
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "test");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void
|
||||
run() override
|
||||
{
|
||||
pass();
|
||||
//testRead();
|
||||
//testAsyncRead();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,read);
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <boost/beast/test/yield_to.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <atomic>
|
||||
|
||||
namespace boost {
|
||||
|
||||
Reference in new issue
Block a user