Replace BOOST_ASIO_INITFN_RESULT_TYPE with BOOST_ASIO_INITFN_AUTO_RESULT_TYPE

asio::deferred doesn't work with BOOST_ASIO_INITFN_RESULT_TYPE
Fixes #2727.
This commit is contained in:
Mohammad
2023-08-21 11:40:31 +00:00
committed by Mohammad Nejati
parent 35d533299c
commit 45d4f7f306
14 changed files with 107 additions and 42 deletions

View File

@@ -41,7 +41,7 @@ docca.reference reference.qbk
\"BOOST_BEAST_ASYNC_RESULT2(t)=__deduced__\" \\ \"BOOST_BEAST_ASYNC_RESULT2(t)=__deduced__\" \\
\"BOOST_BEAST_ASYNC_TPARAM1=class\" \\ \"BOOST_BEAST_ASYNC_TPARAM1=class\" \\
\"BOOST_BEAST_ASYNC_TPARAM2=class\" \\ \"BOOST_BEAST_ASYNC_TPARAM2=class\" \\
\"BOOST_ASIO_INITFN_RESULT_TYPE(t,a)=__deduced__\" \\ \"BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(t,a)=__deduced__\" \\
\"BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e)= =__deduced__\" \\ \"BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e)= =__deduced__\" \\
\"BOOST_ASIO_COMPLETION_TOKEN_FOR(sig)=class\" \\ \"BOOST_ASIO_COMPLETION_TOKEN_FOR(sig)=class\" \\
GENERATING_DOCUMENTATION \\ GENERATING_DOCUMENTATION \\

View File

@@ -31,11 +31,6 @@ template<class Executor>
template<class Handler, class Buffers> template<class Handler, class Buffers>
class basic_stream<Executor>::read_op : public detail::stream_read_op_base class basic_stream<Executor>::read_op : public detail::stream_read_op_base
{ {
using ex1_type =
executor_type;
using ex2_type
= net::associated_executor_t<Handler, ex1_type>;
struct lambda struct lambda
{ {
Handler h_; Handler h_;
@@ -44,7 +39,8 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
#if defined(BOOST_ASIO_NO_TS_EXECUTORS) #if defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::any_io_executor wg2_; net::any_io_executor wg2_;
#else // defined(BOOST_ASIO_NO_TS_EXECUTORS) #else // defined(BOOST_ASIO_NO_TS_EXECUTORS)
net::executor_work_guard<ex2_type> wg2_; net::executor_work_guard<
net::associated_executor_t<Handler, net::any_io_executor>> wg2_;
#endif // defined(BOOST_ASIO_NO_TS_EXECUTORS) #endif // defined(BOOST_ASIO_NO_TS_EXECUTORS)
lambda(lambda&&) = default; lambda(lambda&&) = default;
@@ -330,7 +326,7 @@ read_some(MutableBufferSequence const& buffers,
template<class Executor> template<class Executor>
template<class MutableBufferSequence, template<class MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) ReadHandler> BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler, void(error_code, std::size_t))
basic_stream<Executor>:: basic_stream<Executor>::
async_read_some( async_read_some(
MutableBufferSequence const& buffers, MutableBufferSequence const& buffers,
@@ -414,7 +410,7 @@ write_some(
template<class Executor> template<class Executor>
template<class ConstBufferSequence, template<class ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) WriteHandler> BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(error_code, std::size_t))
basic_stream<Executor>:: basic_stream<Executor>::
async_write_some( async_write_some(
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,

View File

@@ -468,7 +468,7 @@ public:
class MutableBufferSequence, class MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) ReadHandler BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) ReadHandler
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler, void(error_code, std::size_t))
async_read_some( async_read_some(
MutableBufferSequence const& buffers, MutableBufferSequence const& buffers,
ReadHandler&& handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)); ReadHandler&& handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type));
@@ -547,7 +547,7 @@ public:
class ConstBufferSequence, class ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) WriteHandler BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, std::size_t)) WriteHandler
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)> BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(error_code, std::size_t))
async_write_some( async_write_some(
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
WriteHandler&& handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type) WriteHandler&& handler BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)

View File

@@ -1022,7 +1022,7 @@ public:
EndpointSequence>::value>::type EndpointSequence>::value>::type
#endif #endif
> >
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
RangeConnectHandler, RangeConnectHandler,
void(error_code, typename Protocol::endpoint)) void(error_code, typename Protocol::endpoint))
async_connect( async_connect(
@@ -1126,7 +1126,7 @@ public:
EndpointSequence>::value>::type EndpointSequence>::value>::type
#endif #endif
> >
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
RangeConnectHandler, RangeConnectHandler,
void(error_code, typename Protocol::endpoint)) void(error_code, typename Protocol::endpoint))
async_connect( async_connect(
@@ -1195,7 +1195,7 @@ public:
void(error_code, Iterator)) void(error_code, Iterator))
IteratorConnectHandler = IteratorConnectHandler =
net::default_completion_token_t<executor_type>> net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
IteratorConnectHandler, IteratorConnectHandler,
void(error_code, Iterator)) void(error_code, Iterator))
async_connect( async_connect(
@@ -1267,7 +1267,7 @@ public:
void(error_code, Iterator)) void(error_code, Iterator))
IteratorConnectHandler = IteratorConnectHandler =
net::default_completion_token_t<executor_type>> net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
IteratorConnectHandler, IteratorConnectHandler,
void(error_code, Iterator)) void(error_code, Iterator))
async_connect( async_connect(

View File

@@ -319,19 +319,12 @@ template<
class CompletionToken = class CompletionToken =
net::default_completion_token_t<beast::executor_type<AsyncReadStream>> net::default_completion_token_t<beast::executor_type<AsyncReadStream>>
> >
#if BOOST_BEAST_DOXYGEN BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, bool))
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(error_code, bool))
#else
auto
#endif
async_detect_ssl( async_detect_ssl(
AsyncReadStream& stream, AsyncReadStream& stream,
DynamicBuffer& buffer, DynamicBuffer& buffer,
CompletionToken&& token = net::default_completion_token_t< CompletionToken&& token = net::default_completion_token_t<
beast::executor_type<AsyncReadStream>>{}) -> beast::executor_type<AsyncReadStream>>{});
typename net::async_result<
typename std::decay<CompletionToken>::type, /*< `async_result` customizes the return value based on the completion token >*/
void(error_code, bool)>::return_type; /*< This is the signature for the completion handler >*/
//] //]
//[example_core_detect_ssl_5 //[example_core_detect_ssl_5
@@ -395,18 +388,11 @@ template<
class AsyncReadStream, class AsyncReadStream,
class DynamicBuffer, class DynamicBuffer,
class CompletionToken> class CompletionToken>
#if BOOST_BEAST_DOXYGEN BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void(error_code, bool))
BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(error_code, bool))
#else
auto
#endif
async_detect_ssl( async_detect_ssl(
AsyncReadStream& stream, AsyncReadStream& stream,
DynamicBuffer& buffer, DynamicBuffer& buffer,
CompletionToken&& token) CompletionToken&& token)
-> typename net::async_result<
typename std::decay<CompletionToken>::type,
void(error_code, bool)>::return_type
{ {
// Make sure arguments meet the type requirements // Make sure arguments meet the type requirements

View File

@@ -893,7 +893,7 @@ template<
class EndpointSequence, class EndpointSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, typename Protocol::endpoint)) RangeConnectHandler, BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, typename Protocol::endpoint)) RangeConnectHandler,
class> class>
BOOST_ASIO_INITFN_RESULT_TYPE(RangeConnectHandler,void(error_code, typename Protocol::endpoint)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectHandler,void(error_code, typename Protocol::endpoint))
basic_stream<Protocol, Executor, RatePolicy>:: basic_stream<Protocol, Executor, RatePolicy>::
async_connect( async_connect(
EndpointSequence const& endpoints, EndpointSequence const& endpoints,
@@ -915,7 +915,7 @@ template<
class ConnectCondition, class ConnectCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, typename Protocol::endpoint)) RangeConnectHandler, BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, typename Protocol::endpoint)) RangeConnectHandler,
class> class>
BOOST_ASIO_INITFN_RESULT_TYPE(RangeConnectHandler,void (error_code, typename Protocol::endpoint)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectHandler,void (error_code, typename Protocol::endpoint))
basic_stream<Protocol, Executor, RatePolicy>:: basic_stream<Protocol, Executor, RatePolicy>::
async_connect( async_connect(
EndpointSequence const& endpoints, EndpointSequence const& endpoints,
@@ -936,7 +936,7 @@ template<class Protocol, class Executor, class RatePolicy>
template< template<
class Iterator, class Iterator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, Iterator)) IteratorConnectHandler> BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, Iterator)) IteratorConnectHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator))
basic_stream<Protocol, Executor, RatePolicy>:: basic_stream<Protocol, Executor, RatePolicy>::
async_connect( async_connect(
Iterator begin, Iterator end, Iterator begin, Iterator end,
@@ -957,7 +957,7 @@ template<
class Iterator, class Iterator,
class ConnectCondition, class ConnectCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, Iterator)) IteratorConnectHandler> BOOST_ASIO_COMPLETION_TOKEN_FOR(void(error_code, Iterator)) IteratorConnectHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator))
basic_stream<Protocol, Executor, RatePolicy>:: basic_stream<Protocol, Executor, RatePolicy>::
async_connect( async_connect(
Iterator begin, Iterator end, Iterator begin, Iterator end,

View File

@@ -412,7 +412,7 @@ public:
); @endcode ); @endcode
*/ */
template<BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler = net::default_completion_token_t<executor_type>> template<BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler = net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void(boost::system::error_code)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(HandshakeHandler, void(boost::system::error_code))
async_handshake(handshake_type type, async_handshake(handshake_type type,
BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler = net::default_completion_token_t<executor_type>{}) BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler = net::default_completion_token_t<executor_type>{})
{ {
@@ -443,7 +443,7 @@ public:
*/ */
template<class ConstBufferSequence, template<class ConstBufferSequence,
BOOST_BEAST_ASYNC_TPARAM2 BufferedHandshakeHandler = net::default_completion_token_t<executor_type>> BOOST_BEAST_ASYNC_TPARAM2 BufferedHandshakeHandler = net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void(boost::system::error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(BufferedHandshakeHandler, void(boost::system::error_code, std::size_t))
async_handshake(handshake_type type, ConstBufferSequence const& buffers, async_handshake(handshake_type type, ConstBufferSequence const& buffers,
BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler
= net::default_completion_token_t<executor_type>{}) = net::default_completion_token_t<executor_type>{})
@@ -491,7 +491,7 @@ public:
); @endcode ); @endcode
*/ */
template<BOOST_BEAST_ASYNC_TPARAM1 ShutdownHandler = net::default_completion_token_t<executor_type>> template<BOOST_BEAST_ASYNC_TPARAM1 ShutdownHandler = net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void(boost::system::error_code)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ShutdownHandler, void(boost::system::error_code))
async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler = net::default_completion_token_t<executor_type>{}) async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler = net::default_completion_token_t<executor_type>{})
{ {
return p_->next_layer().async_shutdown( return p_->next_layer().async_shutdown(
@@ -570,7 +570,7 @@ public:
*/ */
template<class ConstBufferSequence, template<class ConstBufferSequence,
BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = net::default_completion_token_t<executor_type>> BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
async_write_some(ConstBufferSequence const& buffers, async_write_some(ConstBufferSequence const& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler= net::default_completion_token_t<executor_type>{}) BOOST_ASIO_MOVE_ARG(WriteHandler) handler= net::default_completion_token_t<executor_type>{})
{ {
@@ -652,7 +652,7 @@ public:
*/ */
template<class MutableBufferSequence, template<class MutableBufferSequence,
BOOST_BEAST_ASYNC_TPARAM2 ReadHandler = net::default_completion_token_t<executor_type>> BOOST_BEAST_ASYNC_TPARAM2 ReadHandler = net::default_completion_token_t<executor_type>>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t)) BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
async_read_some(MutableBufferSequence const& buffers, async_read_some(MutableBufferSequence const& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler BOOST_ASIO_MOVE_ARG(ReadHandler) handler
= net::default_completion_token_t<executor_type>{}) = net::default_completion_token_t<executor_type>{})

View File

@@ -1298,7 +1298,7 @@ public:
resolve_results.begin()->endpoint(), resolve_results.begin()->endpoint(),
net::use_awaitable))>); net::use_awaitable))>);
auto comparison_function = [](error_code&, net::ip::tcp::endpoint) { return true; }; auto comparison_function = [](error_code const&, net::ip::tcp::endpoint) { return true; };
static_assert(std::is_same_v< static_assert(std::is_same_v<
net::awaitable<net::ip::tcp::resolver::results_type::const_iterator>, decltype( net::awaitable<net::ip::tcp::resolver::results_type::const_iterator>, decltype(

View File

@@ -23,6 +23,7 @@ add_executable (tests-beast-http
basic_parser.cpp basic_parser.cpp
buffer_body.cpp buffer_body.cpp
chunk_encode.cpp chunk_encode.cpp
deferred.cpp
dynamic_body.cpp dynamic_body.cpp
empty_body.cpp empty_body.cpp
error.cpp error.cpp

View File

@@ -14,6 +14,7 @@ local SOURCES =
basic_parser.cpp basic_parser.cpp
buffer_body.cpp buffer_body.cpp
chunk_encode.cpp chunk_encode.cpp
deferred.cpp
dynamic_body.cpp dynamic_body.cpp
error.cpp error.cpp
field.cpp field.cpp

View File

@@ -0,0 +1,36 @@
//
// Copyright (c) 2023 Mohammad Nejati
//
// 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)
//
#include <boost/asio/deferred.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/beast/http.hpp>
using namespace boost;
namespace http = boost::beast::http;
#if !defined(BOOST_NO_CXX14)
// just compile this.
void test_deferred_for_http(
asio::ip::tcp::socket & stream,
beast::flat_static_buffer_base & buf,
http::basic_parser<true> & parser,
http::serializer<true, http::empty_body> & ser,
http::message<false, http::empty_body> & msg)
{
http::async_read(stream, buf, parser, asio::deferred);
http::async_read(stream, buf, msg, asio::deferred);
http::async_read_some(stream, buf, parser, asio::deferred);
http::async_read_header(stream, buf, parser, asio::deferred);
http::async_write(stream, ser, asio::deferred);
http::async_write(stream, msg, asio::deferred);
http::async_write_header(stream, ser, asio::deferred);
http::async_write_some(stream, ser, asio::deferred);
}
#endif

View File

@@ -24,6 +24,7 @@ add_executable (tests-beast-websocket
accept.cpp accept.cpp
cancel.cpp cancel.cpp
close.cpp close.cpp
deferred.cpp
error.cpp error.cpp
frame.cpp frame.cpp
handshake.cpp handshake.cpp

View File

@@ -15,6 +15,7 @@ local SOURCES =
accept.cpp accept.cpp
cancel.cpp cancel.cpp
close.cpp close.cpp
deferred.cpp
error.cpp error.cpp
frame.cpp frame.cpp
handshake.cpp handshake.cpp

View File

@@ -0,0 +1,43 @@
//
// Copyright (c) 2023 Mohammad Nejati
//
// 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)
//
#include <boost/asio/deferred.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/beast/websocket.hpp>
using namespace boost;
namespace websocket = boost::beast::websocket;
#if !defined(BOOST_NO_CXX14)
// just compile this.
void test_deferred_for_websocket(
websocket::stream<asio::ip::tcp::socket> & stream,
beast::flat_static_buffer_base & buf,
beast::http::request<beast::http::empty_body> & req,
websocket::response_type & res)
{
stream.async_accept(asio::deferred);
stream.async_accept(asio::const_buffer(), asio::deferred);
stream.async_accept(req, asio::deferred);
stream.async_close(websocket::close_code::bad_payload, asio::deferred);
stream.async_handshake("", "/", asio::deferred);
stream.async_handshake(res, "", "/", asio::deferred);
stream.async_ping(websocket::ping_data{}, asio::deferred);
stream.async_pong(websocket::ping_data{}, asio::deferred);
stream.async_read(buf, asio::deferred);
stream.async_read_some(buf.data(), asio::deferred);
stream.async_write(buf.cdata(), asio::deferred);
stream.async_write_some(true, buf.cdata(), asio::deferred);
}
#endif