From 7cc8759261ee282b5042104fbea53454707cc2d4 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 30 Oct 2019 19:36:41 -0700 Subject: [PATCH] Async init-fns use the executor's default token --- CHANGELOG.md | 6 + .../beast/_experimental/http/icy_stream.hpp | 14 +- .../boost/beast/_experimental/test/stream.hpp | 14 +- include/boost/beast/core/basic_stream.hpp | 53 +++++-- .../boost/beast/core/buffered_read_stream.hpp | 22 ++- include/boost/beast/core/detect_ssl.hpp | 7 +- include/boost/beast/core/flat_stream.hpp | 12 +- include/boost/beast/http/read.hpp | 33 +++-- include/boost/beast/http/write.hpp | 45 ++++-- include/boost/beast/websocket/stream.hpp | 129 ++++++++++++++---- test/doc/core_4_layers.cpp | 17 ++- 11 files changed, 265 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 502189c9..ccd70a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 275: + +* Async init-fns use the executor's default token + +-------------------------------------------------------------------------------- + Version 274: * Fix leftovers in basic_parser corner case diff --git a/include/boost/beast/_experimental/http/icy_stream.hpp b/include/boost/beast/_experimental/http/icy_stream.hpp index 5d075fff..bb6a8197 100644 --- a/include/boost/beast/_experimental/http/icy_stream.hpp +++ b/include/boost/beast/_experimental/http/icy_stream.hpp @@ -224,11 +224,14 @@ public: */ template< class MutableBufferSequence, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t{}); /** Write some data to the stream. @@ -303,11 +306,14 @@ public: */ template< class ConstBufferSequence, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_some( ConstBufferSequence const& buffers, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t{}); }; } // http diff --git a/include/boost/beast/_experimental/test/stream.hpp b/include/boost/beast/_experimental/test/stream.hpp index eb12e8d8..6fe7bd8c 100644 --- a/include/boost/beast/_experimental/test/stream.hpp +++ b/include/boost/beast/_experimental/test/stream.hpp @@ -475,9 +475,12 @@ public: to ensure that the requested amount of data is read before the asynchronous operation completes. */ - template + template< + class MutableBufferSequence, + class ReadHandler> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) - async_read_some(MutableBufferSequence const& buffers, + async_read_some( + MutableBufferSequence const& buffers, ReadHandler&& handler); /** Write some data to the stream. @@ -550,9 +553,12 @@ public: the peer. Consider using the function `net::async_write` if you need to ensure that all data is written before the asynchronous operation completes. */ - template + template< + class ConstBufferSequence, + class WriteHandler> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) - async_write_some(ConstBufferSequence const& buffers, + async_write_some( + ConstBufferSequence const& buffers, WriteHandler&& handler); #if ! BOOST_BEAST_DOXYGEN diff --git a/include/boost/beast/core/basic_stream.hpp b/include/boost/beast/core/basic_stream.hpp index eb340838..c8a33483 100644 --- a/include/boost/beast/core/basic_stream.hpp +++ b/include/boost/beast/core/basic_stream.hpp @@ -911,11 +911,16 @@ public: @see async_connect */ - template + template< + class ConnectHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(ConnectHandler) async_connect( endpoint_type const& ep, - ConnectHandler&& handler); + ConnectHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Establishes a connection by trying each endpoint in a sequence asynchronously. @@ -960,7 +965,8 @@ public: */ template< class EndpointSequence, - class RangeConnectHandler + class RangeConnectHandler = + net::default_completion_token_t #if ! BOOST_BEAST_DOXYGEN ,class = typename std::enable_if< net::is_endpoint_sequence< @@ -970,7 +976,8 @@ public: BOOST_ASIO_INITFN_RESULT_TYPE(RangeConnectHandler,void (error_code, typename Protocol::endpoint)) async_connect( EndpointSequence const& endpoints, - RangeConnectHandler&& handler); + RangeConnectHandler&& handler = + net::default_completion_token_t{}); /** Establishes a connection by trying each endpoint in a sequence asynchronously. @@ -1047,7 +1054,8 @@ public: template< class EndpointSequence, class ConnectCondition, - class RangeConnectHandler + class RangeConnectHandler = + net::default_completion_token_t #if ! BOOST_BEAST_DOXYGEN ,class = typename std::enable_if< net::is_endpoint_sequence< @@ -1058,7 +1066,9 @@ public: async_connect( EndpointSequence const& endpoints, ConnectCondition connect_condition, - RangeConnectHandler&& handler); + RangeConnectHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Establishes a connection by trying each endpoint in a sequence asynchronously. @@ -1104,11 +1114,13 @@ public: */ template< class Iterator, - class IteratorConnectHandler> + class IteratorConnectHandler = + net::default_completion_token_t> BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator)) async_connect( Iterator begin, Iterator end, - IteratorConnectHandler&& handler); + IteratorConnectHandler&& handler = + net::default_completion_token_t{}); /** Establishes a connection by trying each endpoint in a sequence asynchronously. @@ -1159,12 +1171,14 @@ public: template< class Iterator, class ConnectCondition, - class IteratorConnectHandler> + class IteratorConnectHandler = + net::default_completion_token_t> BOOST_ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,void (error_code, Iterator)) async_connect( Iterator begin, Iterator end, ConnectCondition connect_condition, - IteratorConnectHandler&& handler); + IteratorConnectHandler&& handler = + net::default_completion_token_t{}); //-------------------------------------------------------------------------- @@ -1277,11 +1291,17 @@ public: to ensure that the requested amount of data is read before the asynchronous operation completes. */ - template + template< + class MutableBufferSequence, + class ReadHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t{} + ); /** Write some data. @@ -1394,11 +1414,16 @@ public: to ensure that the requested amount of data is sent before the asynchronous operation completes. */ - template + template< + class ConstBufferSequence, + class WriteHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_some( ConstBufferSequence const& buffers, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t{}); }; } // beast diff --git a/include/boost/beast/core/buffered_read_stream.hpp b/include/boost/beast/core/buffered_read_stream.hpp index 66cd561e..5e03e7b1 100644 --- a/include/boost/beast/core/buffered_read_stream.hpp +++ b/include/boost/beast/core/buffered_read_stream.hpp @@ -261,10 +261,15 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class MutableBufferSequence, + class ReadHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) - async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler); + async_read_some( + MutableBufferSequence const& buffers, + ReadHandler&& handler = + net::default_completion_token_t{}); /** Write some data to the stream. @@ -335,10 +340,15 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class ConstBufferSequence, + class WriteHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) - async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler); + async_write_some( + ConstBufferSequence const& buffers, + WriteHandler&& handler = + net::default_completion_token_t{}); }; } // beast diff --git a/include/boost/beast/core/detect_ssl.hpp b/include/boost/beast/core/detect_ssl.hpp index 92811568..e0b4cd45 100644 --- a/include/boost/beast/core/detect_ssl.hpp +++ b/include/boost/beast/core/detect_ssl.hpp @@ -316,7 +316,9 @@ detect_ssl( template< class AsyncReadStream, class DynamicBuffer, - class CompletionToken> + class CompletionToken = + net::default_completion_token_t> +> #if BOOST_BEAST_DOXYGEN BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(error_code, bool)) #else @@ -325,7 +327,8 @@ auto async_detect_ssl( AsyncReadStream& stream, DynamicBuffer& buffer, - CompletionToken&& token) -> + CompletionToken&& token = net::default_completion_token_t< + beast::executor_type>{}) -> typename net::async_result< typename std::decay::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 >*/ diff --git a/include/boost/beast/core/flat_stream.hpp b/include/boost/beast/core/flat_stream.hpp index fb8d9c19..aab0839d 100644 --- a/include/boost/beast/core/flat_stream.hpp +++ b/include/boost/beast/core/flat_stream.hpp @@ -253,11 +253,13 @@ public: */ template< class MutableBufferSequence, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t{}); /** Write some data to the stream. @@ -332,11 +334,13 @@ public: */ template< class ConstBufferSequence, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_some( ConstBufferSequence const& buffers, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t{}); }; } // beast diff --git a/include/boost/beast/http/read.hpp b/include/boost/beast/http/read.hpp index 229444be..7a7dde04 100644 --- a/include/boost/beast/http/read.hpp +++ b/include/boost/beast/http/read.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -204,13 +205,17 @@ template< class AsyncReadStream, class DynamicBuffer, bool isRequest, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( AsyncReadStream& stream, DynamicBuffer& buffer, basic_parser& parser, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -397,13 +402,17 @@ template< class AsyncReadStream, class DynamicBuffer, bool isRequest, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_header( AsyncReadStream& stream, DynamicBuffer& buffer, basic_parser& parser, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -590,13 +599,17 @@ template< class AsyncReadStream, class DynamicBuffer, bool isRequest, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, basic_parser& parser, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -792,13 +805,17 @@ template< class AsyncReadStream, class DynamicBuffer, bool isRequest, class Body, class Allocator, - class ReadHandler> + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read( AsyncReadStream& stream, DynamicBuffer& buffer, message>& msg, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); } // http } // beast diff --git a/include/boost/beast/http/write.hpp b/include/boost/beast/http/write.hpp index b4d74101..00a05370 100644 --- a/include/boost/beast/http/write.hpp +++ b/include/boost/beast/http/write.hpp @@ -11,15 +11,12 @@ #define BOOST_BEAST_HTTP_WRITE_HPP #include -#include -#include -#include #include #include #include #include #include -#include +#include #include #include #include @@ -169,12 +166,16 @@ write_some( template< class AsyncWriteStream, bool isRequest, class Body, class Fields, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_some( AsyncWriteStream& stream, serializer& sr, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -295,12 +296,16 @@ write_header( template< class AsyncWriteStream, bool isRequest, class Body, class Fields, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_header( AsyncWriteStream& stream, serializer& sr, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -412,12 +417,16 @@ write( template< class AsyncWriteStream, bool isRequest, class Body, class Fields, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write( AsyncWriteStream& stream, serializer& sr, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ @@ -633,7 +642,9 @@ write( template< class AsyncWriteStream, bool isRequest, class Body, class Fields, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> #if BOOST_BEAST_DOXYGEN BOOST_BEAST_ASYNC_RESULT2(WriteHandler) #else @@ -644,7 +655,9 @@ typename std::enable_if< async_write( AsyncWriteStream& stream, message& msg, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>); /** Write a complete message to a stream asynchronously. @@ -692,7 +705,9 @@ async_write( template< class AsyncWriteStream, bool isRequest, class Body, class Fields, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> #if BOOST_BEAST_DOXYGEN BOOST_BEAST_ASYNC_RESULT2(WriteHandler) #else @@ -703,7 +718,9 @@ typename std::enable_if< async_write( AsyncWriteStream& stream, message const& msg, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //------------------------------------------------------------------------------ diff --git a/include/boost/beast/websocket/stream.hpp b/include/boost/beast/websocket/stream.hpp index 367a5453..9608b205 100644 --- a/include/boost/beast/websocket/stream.hpp +++ b/include/boost/beast/websocket/stream.hpp @@ -875,12 +875,17 @@ public: @li request-target (RFC7230) @li origin-form (RFC7230) */ - template + template< + class HandshakeHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler) async_handshake( string_view host, string_view target, - HandshakeHandler&& handler); + HandshakeHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Perform the WebSocket handshake asynchronously in the client role. @@ -956,13 +961,18 @@ public: @li request-target (RFC7230) @li origin-form (RFC7230) */ - template + template< + class HandshakeHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler) async_handshake( response_type& res, string_view host, string_view target, - HandshakeHandler&& handler); + HandshakeHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- // @@ -1275,9 +1285,15 @@ public: @see @li Websocket Opening Handshake Server Requirements (RFC6455) */ - template + template< + class AcceptHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(AcceptHandler) - async_accept(AcceptHandler&& handler); + async_accept( + AcceptHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Perform the WebSocket handshake asynchronously in the server role. @@ -1338,7 +1354,9 @@ public: */ template< class ConstBufferSequence, - class AcceptHandler> + class AcceptHandler = + net::default_completion_token_t + > #if BOOST_BEAST_DOXYGEN void_or_deduced #else @@ -1348,7 +1366,9 @@ public: #endif async_accept( ConstBufferSequence const& buffers, - AcceptHandler&& handler); + AcceptHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Perform the WebSocket handshake asynchronously in the server role. @@ -1399,12 +1419,16 @@ public: */ template< class Body, class Allocator, - class AcceptHandler> + class AcceptHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(AcceptHandler) async_accept( http::request> const& req, - AcceptHandler&& handler); + AcceptHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- // @@ -1529,9 +1553,16 @@ public: @see @li Websocket Closing Handshake (RFC6455) */ - template + template< + class CloseHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(CloseHandler) - async_close(close_reason const& cr, CloseHandler&& handler); + async_close( + close_reason const& cr, + CloseHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- // @@ -1624,9 +1655,16 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class WriteHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(WriteHandler) - async_ping(ping_data const& payload, WriteHandler&& handler); + async_ping( + ping_data const& payload, + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Send a websocket pong control frame. @@ -1725,9 +1763,16 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class WriteHandler = + net::default_completion_token_t + > BOOST_BEAST_ASYNC_RESULT1(WriteHandler) - async_pong(ping_data const& payload, WriteHandler&& handler); + async_pong( + ping_data const& payload, + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- // @@ -1879,11 +1924,17 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class DynamicBuffer, + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read( DynamicBuffer& buffer, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- @@ -2052,12 +2103,18 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class DynamicBuffer, + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( DynamicBuffer& buffer, std::size_t limit, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- @@ -2221,11 +2278,17 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class MutableBufferSequence, + class ReadHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler); + ReadHandler&& handler = + net::default_completion_token_t< + executor_type>{}); //-------------------------------------------------------------------------- // @@ -2340,11 +2403,15 @@ public: */ template< class ConstBufferSequence, - class WriteHandler> + class WriteHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write( ConstBufferSequence const& buffers, - WriteHandler&& handler); + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); /** Write some message data. @@ -2457,10 +2524,18 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `net::post`. */ - template + template< + class ConstBufferSequence, + class WriteHandler = + net::default_completion_token_t< + executor_type>> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) - async_write_some(bool fin, - ConstBufferSequence const& buffers, WriteHandler&& handler); + async_write_some( + bool fin, + ConstBufferSequence const& buffers, + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}); // // Deprecated diff --git a/test/doc/core_4_layers.cpp b/test/doc/core_4_layers.cpp index dd6dccf7..3e72c073 100644 --- a/test/doc/core_4_layers.cpp +++ b/test/doc/core_4_layers.cpp @@ -243,11 +243,15 @@ public: } /// Read some data from the stream asynchronously - template + template< + class MutableBufferSequence, + class ReadHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(ReadHandler) async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler) + ReadHandler&& handler = + net::default_completion_token_t{}) { return net::async_initiate< ReadHandler, @@ -259,11 +263,16 @@ public: } /// Write some data to the stream asynchronously - template + template< + class ConstBufferSequence, + class WriteHandler = + net::default_completion_token_t> BOOST_BEAST_ASYNC_RESULT2(WriteHandler) async_write_some( ConstBufferSequence const& buffers, - WriteHandler&& handler) + WriteHandler&& handler = + net::default_completion_token_t< + executor_type>{}) { return net::async_initiate< WriteHandler,