Pass the correct handler in basic_timeout_stream

This commit is contained in:
Vinnie Falco
2019-01-22 20:16:21 -08:00
parent 60c96104ec
commit 1da611fa04
5 changed files with 209 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
Version 207
* Send from the strand
* Pass the correct handler in basic_timeout_stream
API Changes:

View File

@@ -575,7 +575,7 @@ async_read_some(
ReadHandler, void(error_code, std::size_t));
async_op<true, MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void(error_code, std::size_t))>(
*this, buffers, std::forward<ReadHandler>(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<false, ConstBufferSequence, BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void(error_code, std::size_t))>(
*this, buffers, std::forward<WriteHandler>(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<Protocol, Executor,
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
void(error_code,
typename Protocol::endpoint))>(
void(error_code, typename Protocol::endpoint))>(
stream, endpoints, detail::any_endpoint{},
std::forward<RangeConnectHandler>(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<Protocol, Executor,
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler,
void(error_code,
typename Protocol::endpoint))>(
void(error_code, typename Protocol::endpoint))>(
stream, endpoints, connect_condition,
std::forward<RangeConnectHandler>(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<IteratorConnectHandler>(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<IteratorConnectHandler>(handler));
std::move(init.completion_handler));
return init.result.get();
}

View File

@@ -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

View File

@@ -10,6 +10,8 @@
// Test that header file is self-contained.
#include <boost/beast/core/basic_timeout_stream.hpp>
#include "stream_tests.hpp"
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/beast/core/flat_buffer.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
@@ -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<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
{
//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();

View 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