Async init-fns use the executor's default token

This commit is contained in:
Vinnie Falco
2019-10-30 19:36:41 -07:00
parent 2ccb110dc9
commit 7cc8759261
11 changed files with 265 additions and 87 deletions

View File

@@ -1,3 +1,9 @@
Version 275:
* Async init-fns use the executor's default token
--------------------------------------------------------------------------------
Version 274:
* Fix leftovers in basic_parser corner case

View File

@@ -224,11 +224,14 @@ public:
*/
template<
class MutableBufferSequence,
class ReadHandler>
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>{});
/** Write some data to the stream.
@@ -303,11 +306,14 @@ public:
*/
template<
class ConstBufferSequence,
class WriteHandler>
class WriteHandler =
net::default_completion_token_t<executor_type>
>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write_some(
ConstBufferSequence const& buffers,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<executor_type>{});
};
} // http

View File

@@ -475,9 +475,12 @@ public:
to ensure that the requested amount of data is read before the asynchronous
operation completes.
*/
template<class MutableBufferSequence, class ReadHandler>
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<class ConstBufferSequence, class WriteHandler>
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

View File

@@ -911,11 +911,16 @@ public:
@see async_connect
*/
template<class ConnectHandler>
template<
class ConnectHandler =
net::default_completion_token_t<executor_type>
>
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<executor_type>
#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<executor_type>{});
/** 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<executor_type>
#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<executor_type>>
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<executor_type>{});
/** 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<executor_type>>
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<executor_type>{});
//--------------------------------------------------------------------------
@@ -1277,11 +1291,17 @@ public:
to ensure that the requested amount of data is read before the asynchronous
operation completes.
*/
template<class MutableBufferSequence, class ReadHandler>
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>{}
);
/** Write some data.
@@ -1394,11 +1414,16 @@ public:
to ensure that the requested amount of data is sent before the asynchronous
operation completes.
*/
template<class ConstBufferSequence, class WriteHandler>
template<
class ConstBufferSequence,
class WriteHandler =
net::default_completion_token_t<Executor>
>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write_some(
ConstBufferSequence const& buffers,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<Executor>{});
};
} // beast

View File

@@ -261,10 +261,15 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `net::post`.
*/
template<class MutableBufferSequence, class ReadHandler>
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);
async_read_some(
MutableBufferSequence const& buffers,
ReadHandler&& handler =
net::default_completion_token_t<executor_type>{});
/** 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<class ConstBufferSequence, class WriteHandler>
template<
class ConstBufferSequence,
class WriteHandler =
net::default_completion_token_t<executor_type>>
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<executor_type>{});
};
} // beast

View File

@@ -316,7 +316,9 @@ detect_ssl(
template<
class AsyncReadStream,
class DynamicBuffer,
class CompletionToken>
class CompletionToken =
net::default_completion_token_t<beast::executor_type<AsyncReadStream>>
>
#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<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 >*/

View File

@@ -253,11 +253,13 @@ public:
*/
template<
class MutableBufferSequence,
class ReadHandler>
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>{});
/** Write some data to the stream.
@@ -332,11 +334,13 @@ public:
*/
template<
class ConstBufferSequence,
class WriteHandler>
class WriteHandler =
net::default_completion_token_t<executor_type>>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write_some(
ConstBufferSequence const& buffers,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<executor_type>{});
};
} // beast

View File

@@ -12,6 +12,7 @@
#include <boost/beast/core/detail/config.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/stream_traits.hpp>
#include <boost/beast/http/basic_parser.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/asio/async_result.hpp>
@@ -204,13 +205,17 @@ template<
class AsyncReadStream,
class DynamicBuffer,
bool isRequest,
class ReadHandler>
class ReadHandler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>>
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
async_read_some(
AsyncReadStream& stream,
DynamicBuffer& buffer,
basic_parser<isRequest>& parser,
ReadHandler&& handler);
ReadHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>{});
//------------------------------------------------------------------------------
@@ -397,13 +402,17 @@ template<
class AsyncReadStream,
class DynamicBuffer,
bool isRequest,
class ReadHandler>
class ReadHandler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>>
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
async_read_header(
AsyncReadStream& stream,
DynamicBuffer& buffer,
basic_parser<isRequest>& parser,
ReadHandler&& handler);
ReadHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>{});
//------------------------------------------------------------------------------
@@ -590,13 +599,17 @@ template<
class AsyncReadStream,
class DynamicBuffer,
bool isRequest,
class ReadHandler>
class ReadHandler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>>
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
async_read(
AsyncReadStream& stream,
DynamicBuffer& buffer,
basic_parser<isRequest>& parser,
ReadHandler&& handler);
ReadHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>{});
//------------------------------------------------------------------------------
@@ -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<AsyncReadStream>>>
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
async_read(
AsyncReadStream& stream,
DynamicBuffer& buffer,
message<isRequest, Body, basic_fields<Allocator>>& msg,
ReadHandler&& handler);
ReadHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncReadStream>>{});
} // http
} // beast

View File

@@ -11,15 +11,12 @@
#define BOOST_BEAST_HTTP_WRITE_HPP
#include <boost/beast/core/detail/config.hpp>
#include <boost/beast/core/buffers_cat.hpp>
#include <boost/beast/core/buffers_suffix.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/serializer.hpp>
#include <boost/beast/http/type_traits.hpp>
#include <boost/beast/http/detail/chunk_encode.hpp>
#include <boost/beast/core/error.hpp>
#include <boost/beast/core/string.hpp>
#include <boost/beast/core/stream_traits.hpp>
#include <boost/asio/async_result.hpp>
#include <iosfwd>
#include <limits>
@@ -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<AsyncWriteStream>>>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write_some(
AsyncWriteStream& stream,
serializer<isRequest, Body, Fields>& sr,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncWriteStream>>{});
//------------------------------------------------------------------------------
@@ -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<AsyncWriteStream>>>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write_header(
AsyncWriteStream& stream,
serializer<isRequest, Body, Fields>& sr,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncWriteStream>>{});
//------------------------------------------------------------------------------
@@ -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<AsyncWriteStream>>>
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
async_write(
AsyncWriteStream& stream,
serializer<isRequest, Body, Fields>& sr,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncWriteStream>>{});
//------------------------------------------------------------------------------
@@ -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<AsyncWriteStream>>>
#if BOOST_BEAST_DOXYGEN
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
#else
@@ -644,7 +655,9 @@ typename std::enable_if<
async_write(
AsyncWriteStream& stream,
message<isRequest, Body, Fields>& msg,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncWriteStream>>);
/** 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<AsyncWriteStream>>>
#if BOOST_BEAST_DOXYGEN
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
#else
@@ -703,7 +718,9 @@ typename std::enable_if<
async_write(
AsyncWriteStream& stream,
message<isRequest, Body, Fields> const& msg,
WriteHandler&& handler);
WriteHandler&& handler =
net::default_completion_token_t<
executor_type<AsyncWriteStream>>{});
//------------------------------------------------------------------------------

View File

@@ -875,12 +875,17 @@ public:
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
*/
template<class HandshakeHandler>
template<
class HandshakeHandler =
net::default_completion_token_t<executor_type>
>
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 <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
*/
template<class HandshakeHandler>
template<
class HandshakeHandler =
net::default_completion_token_t<executor_type>
>
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 <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
*/
template<class AcceptHandler>
template<
class AcceptHandler =
net::default_completion_token_t<executor_type>
>
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<executor_type>
>
#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<executor_type>
>
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
async_accept(
http::request<Body,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler);
AcceptHandler&& handler =
net::default_completion_token_t<
executor_type>{});
//--------------------------------------------------------------------------
//
@@ -1529,9 +1553,16 @@ public:
@see
@li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
*/
template<class CloseHandler>
template<
class CloseHandler =
net::default_completion_token_t<executor_type>
>
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<class WriteHandler>
template<
class WriteHandler =
net::default_completion_token_t<executor_type>
>
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<class WriteHandler>
template<
class WriteHandler =
net::default_completion_token_t<executor_type>
>
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<class DynamicBuffer, class ReadHandler>
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<class DynamicBuffer, class ReadHandler>
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<class MutableBufferSequence, class ReadHandler>
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<class ConstBufferSequence, class WriteHandler>
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

View File

@@ -243,11 +243,15 @@ public:
}
/// Read some data from the stream asynchronously
template <class MutableBufferSequence, class ReadHandler>
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>{})
{
return net::async_initiate<
ReadHandler,
@@ -259,11 +263,16 @@ public:
}
/// Write some data to the stream asynchronously
template <class ConstBufferSequence, class WriteHandler>
template<
class ConstBufferSequence,
class WriteHandler =
net::default_completion_token_t<executor_type>>
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,