From 1da611fa0478053aa706ea83979fa1c4cf9cd1b5 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 22 Jan 2019 20:16:21 -0800 Subject: [PATCH] Pass the correct handler in basic_timeout_stream --- CHANGELOG.md | 1 + .../beast/core/impl/basic_timeout_stream.hpp | 18 ++- test/beast/core/CMakeLists.txt | 1 + test/beast/core/basic_timeout_stream.cpp | 129 ++++++++++++++++++ test/beast/core/stream_tests.hpp | 70 ++++++++++ 5 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 test/beast/core/stream_tests.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 41005f7c..80c32296 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 207 * Send from the strand +* Pass the correct handler in basic_timeout_stream API Changes: diff --git a/include/boost/beast/core/impl/basic_timeout_stream.hpp b/include/boost/beast/core/impl/basic_timeout_stream.hpp index e7028b92..26e8f6ab 100644 --- a/include/boost/beast/core/impl/basic_timeout_stream.hpp +++ b/include/boost/beast/core/impl/basic_timeout_stream.hpp @@ -575,7 +575,7 @@ async_read_some( ReadHandler, void(error_code, std::size_t)); async_op( - *this, buffers, std::forward(handler)); + *this, buffers, std::move(init.completion_handler)); return init.result.get(); } @@ -595,7 +595,7 @@ async_write_some( WriteHandler, void(error_code, std::size_t)); async_op( - *this, buffers, std::forward(handler)); + *this, buffers, std::move(init.completion_handler)); return init.result.get(); } @@ -617,10 +617,9 @@ async_connect( void(error_code, typename Protocol::endpoint)); detail::timeout_stream_connect_op( + void(error_code, typename Protocol::endpoint))>( stream, endpoints, detail::any_endpoint{}, - std::forward(handler)); + std::move(init.completion_handler)); return init.result.get(); } @@ -642,10 +641,9 @@ async_connect( void(error_code, typename Protocol::endpoint)); detail::timeout_stream_connect_op( + void(error_code, typename Protocol::endpoint))>( stream, endpoints, connect_condition, - std::forward(handler)); + std::move(init.completion_handler)); return init.result.get(); } @@ -666,7 +664,7 @@ async_connect( BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, void(error_code, Iterator))>( stream, begin, end, detail::any_endpoint{}, - std::forward(handler)); + std::move(init.completion_handler)); return init.result.get(); } @@ -689,7 +687,7 @@ async_connect( BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, void(error_code, Iterator))>( stream, begin, end, connect_condition, - std::forward(handler)); + std::move(init.completion_handler)); return init.result.get(); } diff --git a/test/beast/core/CMakeLists.txt b/test/beast/core/CMakeLists.txt index 28bf4e0f..2729b849 100644 --- a/test/beast/core/CMakeLists.txt +++ b/test/beast/core/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable (tests-beast-core Jamfile buffer_test.hpp file_test.hpp + stream_tests.hpp test_handler.hpp _detail_base64.cpp _detail_buffer.cpp diff --git a/test/beast/core/basic_timeout_stream.cpp b/test/beast/core/basic_timeout_stream.cpp index 4e86404f..02cbdccc 100644 --- a/test/beast/core/basic_timeout_stream.cpp +++ b/test/beast/core/basic_timeout_stream.cpp @@ -10,6 +10,8 @@ // Test that header file is self-contained. #include +#include "stream_tests.hpp" + #include #include #include @@ -374,6 +376,13 @@ public: } } + void + testAsyncStream() + { + test_async_stream>(); + } + //-------------------------------------------------------------------------- struct match @@ -623,8 +632,127 @@ public: auto const ep = net::ip::tcp::endpoint( 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 const&, + range_connect_handler&&)>( + &beast::async_connect)); + + BEAST_EXPECT( + static_cast const&, + connect_condition const&, + range_connect_handler&&)>( + &beast::async_connect)); + + BEAST_EXPECT( + static_cast( + &beast::async_connect)); + + BEAST_EXPECT( + static_cast( + &beast::async_connect)); + + // use_future + + BEAST_EXPECT(static_cast(*)(stream_t&, + std::array const&, + net::use_future_t<>&&)>( + &beast::async_connect)); + + BEAST_EXPECT(static_cast(*)(stream_t&, + std::array const&, + connect_condition const&, + net::use_future_t<>&&)>( + &beast::async_connect)); + + BEAST_EXPECT(static_cast(*)(stream_t&, + tcp::endpoint const*, + tcp::endpoint const*, + net::use_future_t<>&&)>( + &beast::async_connect)); + + BEAST_EXPECT(static_cast(*)(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 const&, + net::yield_context&&)>( + &beast::async_connect)); + + BEAST_EXPECT(static_cast< + tcp::endpoint(*)(stream_t&, + std::array 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 { + //BEAST_EXPECT(); + server srv("", ep, log); net::io_context ioc; stream_t s(ioc); @@ -917,6 +1045,7 @@ public: { testStrand(); testMembers(); + testAsyncStream(); testRead(); testWrite(); testConnect(); diff --git a/test/beast/core/stream_tests.hpp b/test/beast/core/stream_tests.hpp new file mode 100644 index 00000000..7166ec84 --- /dev/null +++ b/test/beast/core/stream_tests.hpp @@ -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 +#include +#include +#include +#include +#include + +namespace boost { +namespace beast { + +template +void +test_async_read_stream() +{ + struct handler + { + void operator()(error_code, std::size_t) + { + } + }; + + BOOST_ASSERT(is_async_read_stream::value); + BEAST_EXPECT(&AsyncReadStream::get_executor); + BEAST_EXPECT((&AsyncReadStream::template async_read_some)); + BEAST_EXPECT((&AsyncReadStream::template async_read_some>)); + BEAST_EXPECT((&AsyncReadStream::template async_read_some)); +} + +template +void +test_async_write_stream() +{ + struct handler + { + void operator()(error_code, std::size_t) + { + } + }; + + BOOST_ASSERT(is_async_write_stream::value); + BEAST_EXPECT(&AsyncWriteStream::get_executor); + BEAST_EXPECT((&AsyncWriteStream::template async_write_some)); + BEAST_EXPECT((&AsyncWriteStream::template async_write_some>)); + BEAST_EXPECT((&AsyncWriteStream::template async_write_some)); +} + +template +void +test_async_stream() +{ + test_async_read_stream(); + test_async_write_stream(); +} + +} // beast +} // boost + +#endif