From 36ba90076308b96f300f323562a9252e1fe60ff9 Mon Sep 17 00:00:00 2001 From: Klemens Date: Mon, 24 Apr 2023 19:27:42 +0800 Subject: [PATCH] added immediate_executor support. --- .../beast/_experimental/http/icy_stream.hpp | 24 +-- .../boost/beast/_experimental/test/stream.hpp | 25 +-- include/boost/beast/core/async_base.hpp | 69 ++++++-- include/boost/beast/core/basic_stream.hpp | 82 +++++---- .../boost/beast/core/buffered_read_stream.hpp | 24 +-- .../boost/beast/core/buffers_generator.hpp | 9 +- include/boost/beast/core/detail/read.hpp | 7 +- include/boost/beast/core/detect_ssl.hpp | 7 +- include/boost/beast/core/flat_stream.hpp | 24 +-- .../beast/core/impl/buffered_read_stream.hpp | 14 +- include/boost/beast/http/impl/read.hpp | 15 +- include/boost/beast/http/impl/write.hpp | 16 +- include/boost/beast/http/read.hpp | 28 ++-- include/boost/beast/http/write.hpp | 35 ++-- include/boost/beast/websocket/impl/accept.hpp | 1 - include/boost/beast/websocket/impl/close.hpp | 8 +- include/boost/beast/websocket/impl/ping.hpp | 4 +- include/boost/beast/websocket/impl/read.hpp | 19 ++- .../boost/beast/websocket/impl/teardown.hpp | 5 +- include/boost/beast/websocket/impl/write.hpp | 3 +- include/boost/beast/websocket/ssl.hpp | 7 +- include/boost/beast/websocket/stream.hpp | 156 ++++++++++-------- include/boost/beast/websocket/teardown.hpp | 14 +- 23 files changed, 363 insertions(+), 233 deletions(-) diff --git a/include/boost/beast/_experimental/http/icy_stream.hpp b/include/boost/beast/_experimental/http/icy_stream.hpp index 81730b5801..d033935136 100644 --- a/include/boost/beast/_experimental/http/icy_stream.hpp +++ b/include/boost/beast/_experimental/http/icy_stream.hpp @@ -212,11 +212,13 @@ class icy_stream std::size_t bytes_transferred // Number of bytes read. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_read_some` operation may not read all of the requested number of bytes. Consider using the function `net::async_read` if you need to ensure that the requested amount of data is read before the asynchronous @@ -295,11 +297,13 @@ class icy_stream std::size_t bytes_transferred // Number of bytes written. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_write_some` operation may not transmit all of the data to the peer. Consider using the function `net::async_write` if you need to ensure that all data is written before the asynchronous operation completes. diff --git a/include/boost/beast/_experimental/test/stream.hpp b/include/boost/beast/_experimental/test/stream.hpp index 0f9cc809ed..bfbbb424f3 100644 --- a/include/boost/beast/_experimental/test/stream.hpp +++ b/include/boost/beast/_experimental/test/stream.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -454,11 +453,13 @@ class basic_stream std::size_t bytes_transferred // Number of bytes read. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_read_some` operation may not read all of the requested number of bytes. Consider using the function `net::async_read` if you need to ensure that the requested amount of data is read before the asynchronous @@ -534,11 +535,13 @@ class basic_stream std::size_t bytes_transferred // Number of bytes written. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_write_some` operation may not transmit all of the data to the peer. Consider using the function `net::async_write` if you need to ensure that all data is written before the asynchronous operation completes. diff --git a/include/boost/beast/core/async_base.hpp b/include/boost/beast/core/async_base.hpp index 6dd7b178bc..009968fa4d 100644 --- a/include/boost/beast/core/async_base.hpp +++ b/include/boost/beast/core/async_base.hpp @@ -18,10 +18,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -30,6 +32,7 @@ namespace boost { namespace beast { + /** Base class to assist writing composed operations. A function object submitted to intermediate initiating functions during @@ -207,7 +210,25 @@ class async_base >::type; #endif -private: + /** The type of the immediate executor associated with this object. + + If a class derived from @ref boost::beast::async_base is a completion + handler, then the associated immediage executor of the derived class will + be this type. +*/ + using immediate_executor_type = +#if BOOST_BEAST_DOXYGEN + __implementation_defined__; +#else + typename + net::associated_immediate_executor< + Handler, + typename detail::select_work_guard_t::executor_type + >::type; +#endif + + + private: virtual void @@ -309,15 +330,29 @@ class async_base h_, wg1_.get_executor()); } - /** The type of cancellation_slot associated with this object. - - If a class derived from @ref async_base is a completion - handler, then the associated cancellation_slot of the - derived class will be this type. + /** Returns the executor associated with this object. - The default type is a filtering cancellation slot, - that only allows terminal cancellation. + If a class derived from @ref boost::beast::async_base is a completion + handler, then the object returned from this function will be used + as the associated executor of the derived class. */ + immediate_executor_type + get_immediate_executor() const noexcept + { + return net::get_associated_immediate_executor( + h_, wg1_.get_executor()); + } + + + /** The type of cancellation_slot associated with this object. + + If a class derived from @ref async_base is a completion + handler, then the associated cancellation_slot of the + derived class will be this type. + + The default type is a filtering cancellation slot, + that only allows terminal cancellation. + */ using cancellation_slot_type = beast::detail::filtering_cancellation_slot>; @@ -373,7 +408,9 @@ class async_base is invoked. @param is_continuation If this value is `false`, then the - handler will be submitted to the executor using `net::post`. + handler will be submitted to the to the immediate executor using + `net::dispatch`. If the handler has no immediate executor, + this will submit to the executor via `net::post`. Otherwise the handler will be invoked as if by calling @ref boost::beast::async_base::complete_now. @@ -388,14 +425,12 @@ class async_base this->before_invoke_hook(); if(! is_continuation) { - auto const ex = get_executor(); - net::post( - wg1_.get_executor(), - net::bind_executor( - ex, - beast::bind_front_handler( - std::move(h_), - std::forward(args)...))); + auto const ex = this->get_immediate_executor(); + net::dispatch( + ex, + beast::bind_front_handler( + std::move(h_), + std::forward(args)...)); wg1_.reset(); } else diff --git a/include/boost/beast/core/basic_stream.hpp b/include/boost/beast/core/basic_stream.hpp index 19e9597464..e16b39561d 100644 --- a/include/boost/beast/core/basic_stream.hpp +++ b/include/boost/beast/core/basic_stream.hpp @@ -928,10 +928,13 @@ class basic_stream error_code ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation @@ -993,10 +996,13 @@ class basic_stream typename Protocol::endpoint const& endpoint ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation @@ -1079,11 +1085,13 @@ class basic_stream typename Protocol::endpoint const& endpoint ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Example The following connect condition function object can be used to output information about the individual connection attempts: @@ -1173,11 +1181,13 @@ class basic_stream Iterator iterator ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -1244,11 +1254,13 @@ class basic_stream Iterator iterator ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -1377,11 +1389,13 @@ class basic_stream std::size_t bytes_transferred // Number of bytes read. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_read_some` operation may not receive all of the requested number of bytes. Consider using the function `net::async_read` if you need to ensure that the requested amount of data is read before the asynchronous @@ -1511,11 +1525,13 @@ class basic_stream std::size_t bytes_transferred // Number of bytes written. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_write_some` operation may not transmit all of the requested number of bytes. Consider using the function `net::async_write` if you need to ensure that the requested amount of data is sent before the asynchronous diff --git a/include/boost/beast/core/buffered_read_stream.hpp b/include/boost/beast/core/buffered_read_stream.hpp index 2d86a63180..2b25da4903 100644 --- a/include/boost/beast/core/buffered_read_stream.hpp +++ b/include/boost/beast/core/buffered_read_stream.hpp @@ -256,11 +256,13 @@ class buffered_read_stream std::size_t bytes_transferred // number of bytes transferred ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - */ + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. */ template< class MutableBufferSequence, BOOST_BEAST_ASYNC_TPARAM2 ReadHandler = @@ -335,11 +337,13 @@ class buffered_read_stream std::size_t bytes_transferred // number of bytes transferred ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - */ + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. */ template< class ConstBufferSequence, BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = diff --git a/include/boost/beast/core/buffers_generator.hpp b/include/boost/beast/core/buffers_generator.hpp index 5394865e00..dfc1c2a512 100644 --- a/include/boost/beast/core/buffers_generator.hpp +++ b/include/boost/beast/core/buffers_generator.hpp @@ -167,10 +167,11 @@ write( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from - within this function. Invocation of the handler will be - performed in a manner equivalent to using `net::post`. + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed in a + manner equivalent to using `net::post`. @see BuffersGenerator */ diff --git a/include/boost/beast/core/detail/read.hpp b/include/boost/beast/core/detail/read.hpp index 91a02b8321..e7d1c64361 100644 --- a/include/boost/beast/core/detail/read.hpp +++ b/include/boost/beast/core/detail/read.hpp @@ -210,10 +210,11 @@ read( // prior to the error. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. */ template< class AsyncReadStream, diff --git a/include/boost/beast/core/detect_ssl.hpp b/include/boost/beast/core/detect_ssl.hpp index b641b3ff2b..3d668728c2 100644 --- a/include/boost/beast/core/detect_ssl.hpp +++ b/include/boost/beast/core/detect_ssl.hpp @@ -308,10 +308,11 @@ detect_ssl( bool result // The result of the detector ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. */ template< class AsyncReadStream, diff --git a/include/boost/beast/core/flat_stream.hpp b/include/boost/beast/core/flat_stream.hpp index 913fdc3e10..42844ba5f2 100644 --- a/include/boost/beast/core/flat_stream.hpp +++ b/include/boost/beast/core/flat_stream.hpp @@ -241,11 +241,13 @@ class flat_stream std::size_t bytes_transferred // Number of bytes read. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `read_some` operation may not read all of the requested number of bytes. Consider using the function `net::async_read` if you need to ensure that the requested amount of data is read before the asynchronous @@ -323,11 +325,13 @@ class flat_stream std::size_t bytes_transferred // Number of bytes written. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @note The `async_write_some` operation may not transmit all of the data to the peer. Consider using the function `net::async_write` if you need to ensure that all data is written before the asynchronous operation completes. diff --git a/include/boost/beast/core/impl/buffered_read_stream.hpp b/include/boost/beast/core/impl/buffered_read_stream.hpp index 097deaceaf..6b861c89f7 100644 --- a/include/boost/beast/core/impl/buffered_read_stream.hpp +++ b/include/boost/beast/core/impl/buffered_read_stream.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include namespace boost { @@ -80,11 +80,13 @@ class read_op std::move(*this)); } step_ = 3; - return net::post( - s_.get_executor(), - beast::bind_front_handler( - std::move(*this), ec, 0)); - + { + const auto ex = this->get_immediate_executor(); + return net::dispatch( + ex, + beast::bind_front_handler( + std::move(*this), ec, 0)); + } case 1: // upcall break; diff --git a/include/boost/beast/http/impl/read.hpp b/include/boost/beast/http/impl/read.hpp index e320014e9b..09c8303d0f 100644 --- a/include/boost/beast/http/impl/read.hpp +++ b/include/boost/beast/http/impl/read.hpp @@ -244,8 +244,13 @@ class read_some_op : asio::coroutine __FILE__, __LINE__, "http::async_read_some")); - net::post( - s_.get_executor(), + + const auto ex = + asio::get_associated_immediate_executor( + self, s_.get_executor()); + + net::dispatch( + ex, beast::bind_front_handler(std::move(self), ec)); } } @@ -285,7 +290,11 @@ class read_op __FILE__, __LINE__, "http::async_read")); - net::post(s_.get_executor(), std::move(self)); + const auto ex = + asio::get_associated_immediate_executor( + self, s_.get_executor()); + + net::dispatch(ex, std::move(self)); } } else diff --git a/include/boost/beast/http/impl/write.hpp b/include/boost/beast/http/impl/write.hpp index 1739e0243b..c5aac867b0 100644 --- a/include/boost/beast/http/impl/write.hpp +++ b/include/boost/beast/http/impl/write.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -102,8 +102,8 @@ class write_some_op __FILE__, __LINE__, "http::async_write_some")); - return net::post( - s_.get_executor(), + return net::dispatch( + asio::get_associated_immediate_executor(*this, s_.get_executor()), beast::bind_front_handler( std::move(*this), ec, 0)); } @@ -120,8 +120,9 @@ class write_some_op __FILE__, __LINE__, "http::async_write_some")); - return net::post( - s_.get_executor(), + const auto ex = this->get_immediate_executor(); + return net::dispatch( + ex, beast::bind_front_handler( std::move(*this), ec, 0)); } @@ -219,8 +220,9 @@ class write_op __FILE__, __LINE__, "http::async_write")); - net::post( - s_.get_executor(), + const auto ex = this->get_immediate_executor(); + net::dispatch( + ex, std::move(*this)); } goto upcall; diff --git a/include/boost/beast/http/read.hpp b/include/boost/beast/http/read.hpp index 1d0d8e9ff9..8c32968ce9 100644 --- a/include/boost/beast/http/read.hpp +++ b/include/boost/beast/http/read.hpp @@ -192,10 +192,11 @@ read_some( std::size_t bytes_transferred // the total number of bytes transferred from the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @note The completion handler will receive as a parameter the total number of bytes transferred from the stream. This may be zero for the case where @@ -400,10 +401,11 @@ read_header( std::size_t bytes_transferred // the total number of bytes transferred from the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @note The completion handler will receive as a parameter the total number of bytes transferred from the stream. This may be zero for the case where @@ -610,10 +612,11 @@ read( std::size_t bytes_transferred // the total number of bytes transferred from the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @note The completion handler will receive as a parameter the total number of bytes transferred from the stream. This may be zero for the case where @@ -829,10 +832,11 @@ read( std::size_t bytes_transferred // the total number of bytes transferred from the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @note The completion handler will receive as a parameter the total number of bytes transferred from the stream. This may be zero for the case where diff --git a/include/boost/beast/http/write.hpp b/include/boost/beast/http/write.hpp index 50022e37a9..9af3f366ff 100644 --- a/include/boost/beast/http/write.hpp +++ b/include/boost/beast/http/write.hpp @@ -156,10 +156,11 @@ write_some( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation @@ -295,10 +296,11 @@ write_header( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @note The implementation will call @ref serializer::split with the value `true` on the serializer passed in. @@ -431,10 +433,11 @@ write( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation @@ -668,10 +671,11 @@ write( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation @@ -742,10 +746,11 @@ async_write( std::size_t bytes_transferred // the number of bytes written to the stream ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation diff --git a/include/boost/beast/websocket/impl/accept.hpp b/include/boost/beast/websocket/impl/accept.hpp index 4cd9bb84f3..6cc4c88b18 100644 --- a/include/boost/beast/websocket/impl/accept.hpp +++ b/include/boost/beast/websocket/impl/accept.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/beast/websocket/impl/close.hpp b/include/boost/beast/websocket/impl/close.hpp index 8c823542ae..85882186de 100644 --- a/include/boost/beast/websocket/impl/close.hpp +++ b/include/boost/beast/websocket/impl/close.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -106,7 +106,8 @@ class stream::close_op __FILE__, __LINE__, "websocket::async_close")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.wr_block.is_locked(this)); } @@ -167,7 +168,8 @@ class stream::close_op __FILE__, __LINE__, "websocket::async_close")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.rd_block.is_locked(this)); if(impl.check_stop_now(ec)) diff --git a/include/boost/beast/websocket/impl/ping.hpp b/include/boost/beast/websocket/impl/ping.hpp index cde043869c..4343ae6cf6 100644 --- a/include/boost/beast/websocket/impl/ping.hpp +++ b/include/boost/beast/websocket/impl/ping.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,8 @@ class stream::ping_op __FILE__, __LINE__, "websocket::async_ping")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.wr_block.is_locked(this)); } diff --git a/include/boost/beast/websocket/impl/read.hpp b/include/boost/beast/websocket/impl/read.hpp index c3338a7357..aff596b6ba 100644 --- a/include/boost/beast/websocket/impl/read.hpp +++ b/include/boost/beast/websocket/impl/read.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -122,7 +121,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.rd_block.is_locked(this)); @@ -238,7 +238,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(cont); // VFALCO call check_stop_now() here? @@ -291,7 +292,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.wr_block.is_locked(this)); if(impl.check_stop_now(ec)) @@ -335,7 +337,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(cont); } @@ -366,7 +369,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(cont); } @@ -648,7 +652,8 @@ class stream::read_some_op __FILE__, __LINE__, "websocket::async_read_some")); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.wr_block.is_locked(this)); if(impl.check_stop_now(ec)) diff --git a/include/boost/beast/websocket/impl/teardown.hpp b/include/boost/beast/websocket/impl/teardown.hpp index 43e63c2db2..f04be03b6f 100644 --- a/include/boost/beast/websocket/impl/teardown.hpp +++ b/include/boost/beast/websocket/impl/teardown.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include namespace boost { @@ -128,7 +128,8 @@ class teardown_tcp_op "websocket::tcp::async_teardown" )); - net::post(s_.get_executor(), bind_front_handler( + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, bind_front_handler( std::move(*this), ec)); } } diff --git a/include/boost/beast/websocket/impl/write.hpp b/include/boost/beast/websocket/impl/write.hpp index 69f2927e6e..a70cb1a091 100644 --- a/include/boost/beast/websocket/impl/write.hpp +++ b/include/boost/beast/websocket/impl/write.hpp @@ -199,7 +199,8 @@ operator()( "websocket::async_write_some" )); - net::post(sp->stream().get_executor(), std::move(*this)); + const auto ex = this->get_immediate_executor(); + net::dispatch(ex, std::move(*this)); } BOOST_ASSERT(impl.wr_block.is_locked(this)); } diff --git a/include/boost/beast/websocket/ssl.hpp b/include/boost/beast/websocket/ssl.hpp index 3fe63f41f2..04eba4f689 100644 --- a/include/boost/beast/websocket/ssl.hpp +++ b/include/boost/beast/websocket/ssl.hpp @@ -63,10 +63,11 @@ teardown( error_code const& error // result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation diff --git a/include/boost/beast/websocket/stream.hpp b/include/boost/beast/websocket/stream.hpp index fdbf070762..9dd10f28f1 100644 --- a/include/boost/beast/websocket/stream.hpp +++ b/include/boost/beast/websocket/stream.hpp @@ -931,11 +931,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Example @code ws.async_handshake("localhost", "/", @@ -1013,11 +1015,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Example @code response_type res; @@ -1354,11 +1358,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @see @li Websocket Opening Handshake Server Requirements (RFC6455) */ @@ -1421,11 +1427,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @see @li Websocket Opening Handshake Server Requirements (RFC6455) */ @@ -1486,11 +1494,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @see @li Websocket Opening Handshake Server Requirements (RFC6455) */ @@ -1622,11 +1632,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -1741,11 +1753,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -1864,11 +1878,13 @@ class stream error_code const& ec // Result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -2040,11 +2056,13 @@ class stream std::size_t bytes_written // Number of bytes appended to buffer ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -2234,11 +2252,13 @@ class stream std::size_t bytes_written // Number of bytes appended to buffer ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -2439,11 +2459,13 @@ class stream std::size_t bytes_written // Number of bytes written to the buffers ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation @@ -2578,11 +2600,13 @@ class stream // this will be less than the buffer_size. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following @@ -2717,11 +2741,13 @@ class stream // this will be less than the buffer_size. ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. - + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within + this function. Invocation of the handler will be performed + by dispatching to the immediate executor. If no + immediate executor is specified, this is equivalent + to using `net::post`. @par Per-Operation Cancellation This asynchronous operation supports cancellation for the following diff --git a/include/boost/beast/websocket/teardown.hpp b/include/boost/beast/websocket/teardown.hpp index 5ffbdcd8d6..3701fe9562 100644 --- a/include/boost/beast/websocket/teardown.hpp +++ b/include/boost/beast/websocket/teardown.hpp @@ -78,10 +78,11 @@ teardown( error_code const& error // result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. */ template< @@ -158,10 +159,11 @@ teardown( error_code const& error // result of operation ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within + If the handler has an associated immediate executor, + an immediate completion will be dispatched to it. + Otherwise, the handler will not be invoked from within this function. Invocation of the handler will be performed in a - manner equivalent to using `net::post`. + manner equivalent to using `net::post`.. @par Per-Operation Cancellation