mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 14:54:32 +02:00
Pass the correct handler in basic_timeout_stream
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
Version 207
|
Version 207
|
||||||
|
|
||||||
* Send from the strand
|
* Send from the strand
|
||||||
|
* Pass the correct handler in basic_timeout_stream
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
|
@@ -575,7 +575,7 @@ async_read_some(
|
|||||||
ReadHandler, void(error_code, std::size_t));
|
ReadHandler, void(error_code, std::size_t));
|
||||||
async_op<true, MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
|
async_op<true, MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
|
||||||
ReadHandler, void(error_code, std::size_t))>(
|
ReadHandler, void(error_code, std::size_t))>(
|
||||||
*this, buffers, std::forward<ReadHandler>(handler));
|
*this, buffers, std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,7 +595,7 @@ async_write_some(
|
|||||||
WriteHandler, void(error_code, std::size_t));
|
WriteHandler, void(error_code, std::size_t));
|
||||||
async_op<false, ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
|
async_op<false, ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
|
||||||
WriteHandler, void(error_code, std::size_t))>(
|
WriteHandler, void(error_code, std::size_t))>(
|
||||||
*this, buffers, std::forward<WriteHandler>(handler));
|
*this, buffers, std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,10 +617,9 @@ async_connect(
|
|||||||
void(error_code, typename Protocol::endpoint));
|
void(error_code, typename Protocol::endpoint));
|
||||||
detail::timeout_stream_connect_op<Protocol, Executor,
|
detail::timeout_stream_connect_op<Protocol, Executor,
|
||||||
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
|
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
|
||||||
void(error_code,
|
void(error_code, typename Protocol::endpoint))>(
|
||||||
typename Protocol::endpoint))>(
|
|
||||||
stream, endpoints, detail::any_endpoint{},
|
stream, endpoints, detail::any_endpoint{},
|
||||||
std::forward<RangeConnectHandler>(handler));
|
std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,10 +641,9 @@ async_connect(
|
|||||||
void(error_code, typename Protocol::endpoint));
|
void(error_code, typename Protocol::endpoint));
|
||||||
detail::timeout_stream_connect_op<Protocol, Executor,
|
detail::timeout_stream_connect_op<Protocol, Executor,
|
||||||
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
|
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
|
||||||
void(error_code,
|
void(error_code, typename Protocol::endpoint))>(
|
||||||
typename Protocol::endpoint))>(
|
|
||||||
stream, endpoints, connect_condition,
|
stream, endpoints, connect_condition,
|
||||||
std::forward<RangeConnectHandler>(handler));
|
std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,7 +664,7 @@ async_connect(
|
|||||||
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler,
|
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler,
|
||||||
void(error_code, Iterator))>(
|
void(error_code, Iterator))>(
|
||||||
stream, begin, end, detail::any_endpoint{},
|
stream, begin, end, detail::any_endpoint{},
|
||||||
std::forward<IteratorConnectHandler>(handler));
|
std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,7 +687,7 @@ async_connect(
|
|||||||
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler,
|
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler,
|
||||||
void(error_code, Iterator))>(
|
void(error_code, Iterator))>(
|
||||||
stream, begin, end, connect_condition,
|
stream, begin, end, connect_condition,
|
||||||
std::forward<IteratorConnectHandler>(handler));
|
std::move(init.completion_handler));
|
||||||
return init.result.get();
|
return init.result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ add_executable (tests-beast-core
|
|||||||
Jamfile
|
Jamfile
|
||||||
buffer_test.hpp
|
buffer_test.hpp
|
||||||
file_test.hpp
|
file_test.hpp
|
||||||
|
stream_tests.hpp
|
||||||
test_handler.hpp
|
test_handler.hpp
|
||||||
_detail_base64.cpp
|
_detail_base64.cpp
|
||||||
_detail_buffer.cpp
|
_detail_buffer.cpp
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/beast/core/basic_timeout_stream.hpp>
|
#include <boost/beast/core/basic_timeout_stream.hpp>
|
||||||
|
|
||||||
|
#include "stream_tests.hpp"
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||||
#include <boost/beast/core/flat_buffer.hpp>
|
#include <boost/beast/core/flat_buffer.hpp>
|
||||||
#include <boost/beast/core/timeout_stream.hpp>
|
#include <boost/beast/core/timeout_stream.hpp>
|
||||||
@@ -374,6 +376,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testAsyncStream()
|
||||||
|
{
|
||||||
|
test_async_stream<basic_timeout_stream<
|
||||||
|
net::ip::tcp, net::io_context::strand>>();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
struct match
|
struct match
|
||||||
@@ -623,8 +632,127 @@ public:
|
|||||||
auto const ep = net::ip::tcp::endpoint(
|
auto const ep = net::ip::tcp::endpoint(
|
||||||
net::ip::make_address("127.0.0.1"), 0);
|
net::ip::make_address("127.0.0.1"), 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
struct connect_condition
|
||||||
|
{
|
||||||
|
bool operator()(
|
||||||
|
error_code, tcp::endpoint)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct range_connect_handler
|
||||||
|
{
|
||||||
|
void operator()(
|
||||||
|
error_code, tcp::endpoint)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct iterator_connect_handler
|
||||||
|
{
|
||||||
|
void operator()(
|
||||||
|
error_code, tcp::endpoint const*)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// completion handler
|
||||||
|
|
||||||
|
BEAST_EXPECT(
|
||||||
|
static_cast<void(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
range_connect_handler&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(
|
||||||
|
static_cast<void(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
connect_condition const&,
|
||||||
|
range_connect_handler&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(
|
||||||
|
static_cast<void(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
iterator_connect_handler&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(
|
||||||
|
static_cast<void(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
connect_condition const&,
|
||||||
|
iterator_connect_handler&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
// use_future
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<std::future<
|
||||||
|
tcp::endpoint>(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
net::use_future_t<>&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<std::future<
|
||||||
|
tcp::endpoint>(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
connect_condition const&,
|
||||||
|
net::use_future_t<>&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<std::future<
|
||||||
|
tcp::endpoint const*>(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
net::use_future_t<>&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<std::future<
|
||||||
|
tcp::endpoint const*>(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
connect_condition const&,
|
||||||
|
net::use_future_t<>&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
// yield_context
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<
|
||||||
|
tcp::endpoint(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
net::yield_context&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<
|
||||||
|
tcp::endpoint(*)(stream_t&,
|
||||||
|
std::array<tcp::endpoint, 2> const&,
|
||||||
|
connect_condition const&,
|
||||||
|
net::yield_context&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<
|
||||||
|
tcp::endpoint const*(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
net::yield_context&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
|
||||||
|
BEAST_EXPECT(static_cast<
|
||||||
|
tcp::endpoint const*(*)(stream_t&,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
tcp::endpoint const*,
|
||||||
|
connect_condition const&,
|
||||||
|
net::yield_context&&)>(
|
||||||
|
&beast::async_connect));
|
||||||
|
}
|
||||||
|
|
||||||
// overload 1
|
// overload 1
|
||||||
{
|
{
|
||||||
|
//BEAST_EXPECT();
|
||||||
|
|
||||||
server srv("", ep, log);
|
server srv("", ep, log);
|
||||||
net::io_context ioc;
|
net::io_context ioc;
|
||||||
stream_t s(ioc);
|
stream_t s(ioc);
|
||||||
@@ -917,6 +1045,7 @@ public:
|
|||||||
{
|
{
|
||||||
testStrand();
|
testStrand();
|
||||||
testMembers();
|
testMembers();
|
||||||
|
testAsyncStream();
|
||||||
testRead();
|
testRead();
|
||||||
testWrite();
|
testWrite();
|
||||||
testConnect();
|
testConnect();
|
||||||
|
70
test/beast/core/stream_tests.hpp
Normal file
70
test/beast/core/stream_tests.hpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2016-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)
|
||||||
|
//
|
||||||
|
// Official repository: https://github.com/boostorg/beast
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef BOOST_BEAST_STREAM_TESTS_HPP
|
||||||
|
#define BOOST_BEAST_STREAM_TESTS_HPP
|
||||||
|
|
||||||
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||||
|
#include <boost/beast/core/error.hpp>
|
||||||
|
#include <boost/beast/core/type_traits.hpp>
|
||||||
|
#include <boost/asio/buffer.hpp>
|
||||||
|
#include <boost/asio/spawn.hpp>
|
||||||
|
#include <boost/asio/use_future.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
|
template<class AsyncReadStream>
|
||||||
|
void
|
||||||
|
test_async_read_stream()
|
||||||
|
{
|
||||||
|
struct handler
|
||||||
|
{
|
||||||
|
void operator()(error_code, std::size_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_ASSERT(is_async_read_stream<AsyncReadStream>::value);
|
||||||
|
BEAST_EXPECT(&AsyncReadStream::get_executor);
|
||||||
|
BEAST_EXPECT((&AsyncReadStream::template async_read_some<net::mutable_buffer, handler>));
|
||||||
|
BEAST_EXPECT((&AsyncReadStream::template async_read_some<net::mutable_buffer, net::use_future_t<>>));
|
||||||
|
BEAST_EXPECT((&AsyncReadStream::template async_read_some<net::mutable_buffer, net::yield_context>));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class AsyncWriteStream>
|
||||||
|
void
|
||||||
|
test_async_write_stream()
|
||||||
|
{
|
||||||
|
struct handler
|
||||||
|
{
|
||||||
|
void operator()(error_code, std::size_t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_ASSERT(is_async_write_stream<AsyncWriteStream>::value);
|
||||||
|
BEAST_EXPECT(&AsyncWriteStream::get_executor);
|
||||||
|
BEAST_EXPECT((&AsyncWriteStream::template async_write_some<net::const_buffer, handler>));
|
||||||
|
BEAST_EXPECT((&AsyncWriteStream::template async_write_some<net::const_buffer, net::use_future_t<>>));
|
||||||
|
BEAST_EXPECT((&AsyncWriteStream::template async_write_some<net::const_buffer, net::yield_context>));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class AsyncStream>
|
||||||
|
void
|
||||||
|
test_async_stream()
|
||||||
|
{
|
||||||
|
test_async_read_stream<AsyncStream>();
|
||||||
|
test_async_write_stream<AsyncStream>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // beast
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user