diff --git a/include/boost/beast/core/basic_stream.hpp b/include/boost/beast/core/basic_stream.hpp index 52861f03..25076059 100644 --- a/include/boost/beast/core/basic_stream.hpp +++ b/include/boost/beast/core/basic_stream.hpp @@ -73,7 +73,7 @@ namespace beast { be invoked by the executor associated with the stream upon construction. The type of executor used with this stream must meet the following requirements: - + @li Function objects submitted to the executor shall never run concurrently with each other. @@ -284,6 +284,7 @@ private: // but the implementation is still waiting on a timer. boost::shared_ptr impl_; + template struct timeout_handler; struct ops; @@ -367,7 +368,7 @@ public: /** Move constructor - @param other The other object from which the move will occur. + @param other The other object from which the move will occur. @note Following the move, the moved-from object is in the same state as if newly constructed. @@ -490,7 +491,7 @@ public: //-------------------------------------------------------------------------- /** Get the executor associated with the object. - + This function may be used to obtain the executor object that the stream uses to dispatch completion handlers without an assocaited executor. @@ -525,7 +526,7 @@ public: } /** Connect the stream to the specified endpoint. - + This function is used to connect the underlying socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs. @@ -534,7 +535,7 @@ public: closed state upon failure. @param ep The remote endpoint to connect to. - + @param ec Set to indicate what error occurred, if any. @see connect @@ -546,7 +547,7 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -556,11 +557,11 @@ public: The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param endpoints A sequence of endpoints. - + @returns The successfully connected endpoint. - + @throws system_error Thrown on failure. If the sequence is empty, the associated error code is `net::error::not_found`. Otherwise, contains the error from the last connection attempt. @@ -579,7 +580,7 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -589,16 +590,16 @@ public: The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param endpoints A sequence of endpoints. - + @param ec Set to indicate what error occurred, if any. If the sequence is empty, set to `net::error::not_found`. Otherwise, contains the error from the last connection attempt. - + @returns On success, the successfully connected endpoint. Otherwise, a default-constructed endpoint. - */ + */ templatecomposed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param begin An iterator pointing to the start of a sequence of endpoints. - + @param end An iterator pointing to the end of a sequence of endpoints. - + @returns An iterator denoting the successfully connected endpoint. - + @throws system_error Thrown on failure. If the sequence is empty, the associated error code is `net::error::not_found`. Otherwise, contains the error from the last connection attempt. - */ + */ template Iterator connect( @@ -646,25 +647,25 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. The underlying socket is automatically opened if needed. An automatically opened socket is not returned to the closed state upon failure. - + The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param begin An iterator pointing to the start of a sequence of endpoints. - + @param end An iterator pointing to the end of a sequence of endpoints. - + @param ec Set to indicate what error occurred, if any. If the sequence is empty, set to boost::asio::error::not_found. Otherwise, contains the error from the last connection attempt. - + @returns On success, an iterator denoting the successfully connected endpoint. Otherwise, the end iterator. */ @@ -678,7 +679,7 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -688,9 +689,9 @@ public: The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param endpoints A sequence of endpoints. - + @param connect_condition A function object that is called prior to each connection attempt. The signature of the function object must be: @code @@ -703,9 +704,9 @@ public: indicate success. The @c next parameter is the next endpoint to be tried. The function object should return true if the next endpoint should be tried, and false if it should be skipped. - + @returns The successfully connected endpoint. - + @throws boost::system::system_error Thrown on failure. If the sequence is empty, the associated error code is `net::error::not_found`. Otherwise, contains the error from the last connection attempt. @@ -779,7 +780,7 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -789,11 +790,11 @@ public: The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param begin An iterator pointing to the start of a sequence of endpoints. - + @param end An iterator pointing to the end of a sequence of endpoints. - + @param connect_condition A function object that is called prior to each connection attempt. The signature of the function object must be: @code @@ -806,13 +807,13 @@ public: indicate success. The @c next parameter is the next endpoint to be tried. The function object should return true if the next endpoint should be tried, and false if it should be skipped. - + @returns An iterator denoting the successfully connected endpoint. - + @throws boost::system::system_error Thrown on failure. If the sequence is empty, the associated @c error_code is `net::error::not_found`. Otherwise, contains the error from the last connection attempt. - */ + */ template< class Iterator, class ConnectCondition> Iterator @@ -824,7 +825,7 @@ public: } /** Establishes a connection by trying each endpoint in a sequence. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -834,11 +835,11 @@ public: The algorithm, known as a composed operation, is implemented in terms of calls to the underlying socket's `connect` function. - + @param begin An iterator pointing to the start of a sequence of endpoints. - + @param end An iterator pointing to the end of a sequence of endpoints. - + @param connect_condition A function object that is called prior to each connection attempt. The signature of the function object must be: @code @@ -851,11 +852,11 @@ public: indicate success. The @c next parameter is the next endpoint to be tried. The function object should return true if the next endpoint should be tried, and false if it should be skipped. - + @param ec Set to indicate what error occurred, if any. If the sequence is empty, set to `net::error::not_found`. Otherwise, contains the error from the last connection attempt. - + @returns On success, an iterator denoting the successfully connected endpoint. Otherwise, the end iterator. */ @@ -885,7 +886,7 @@ public: @param ep The remote endpoint to which the underlying socket will be connected. Copies will be made of the endpoint object as required. - + @param handler The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of @@ -909,7 +910,7 @@ public: ConnectHandler&& handler); /** Establishes a connection by trying each endpoint in a sequence asynchronously. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -924,10 +925,10 @@ public: If the timeout timer expires while the operation is outstanding, the current connection attempt will be canceled and the completion handler will be invoked with the error @ref error::timeout. - + @param endpoints A sequence of endpoints. This this object must meet the requirements of EndpointSequence. - + @param handler The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of @@ -938,7 +939,7 @@ public: // net::error::not_found. Otherwise, contains the // error from the last connection attempt. error_code const& error, - + // On success, the successfully connected endpoint. // Otherwise, a default-constructed endpoint. typename Protocol::endpoint const& endpoint @@ -964,7 +965,7 @@ public: RangeConnectHandler&& handler); /** Establishes a connection by trying each endpoint in a sequence asynchronously. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -982,7 +983,7 @@ public: @param endpoints A sequence of endpoints. This this object must meet the requirements of EndpointSequence. - + @param connect_condition A function object that is called prior to each connection attempt. The signature of the function object must be: @code @@ -1006,7 +1007,7 @@ public: // net::error::not_found. Otherwise, contains the // error from the last connection attempt. error_code const& error, - + // On success, the successfully connected endpoint. // Otherwise, a default-constructed endpoint. typename Protocol::endpoint const& endpoint @@ -1052,7 +1053,7 @@ public: RangeConnectHandler&& handler); /** Establishes a connection by trying each endpoint in a sequence asynchronously. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -1067,9 +1068,9 @@ public: If the timeout timer expires while the operation is outstanding, the current connection attempt will be canceled and the completion handler will be invoked with the error @ref error::timeout. - + @param begin An iterator pointing to the start of a sequence of endpoints. - + @param end An iterator pointing to the end of a sequence of endpoints. @param handler The completion handler to invoke when the operation @@ -1082,7 +1083,7 @@ public: // net::error::not_found. Otherwise, contains the // error from the last connection attempt. error_code const& error, - + // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator @@ -1102,7 +1103,7 @@ public: IteratorConnectHandler&& handler); /** Establishes a connection by trying each endpoint in a sequence asynchronously. - + This function attempts to connect the stream to one of a sequence of endpoints by trying each endpoint until a connection is successfully established. @@ -1113,11 +1114,11 @@ public: If the timeout timer expires while the operation is outstanding, the current connection attempt will be canceled and the completion handler will be invoked with the error @ref error::timeout. - + @param begin An iterator pointing to the start of a sequence of endpoints. @param end An iterator pointing to the end of a sequence of endpoints. - + @param connect_condition A function object that is called prior to each connection attempt. The signature of the function object must be: @code @@ -1136,7 +1137,7 @@ public: // net::error::not_found. Otherwise, contains the // error from the last connection attempt. error_code const& error, - + // On success, an iterator denoting the successfully // connected endpoint. Otherwise, the end iterator. Iterator iterator @@ -1162,7 +1163,7 @@ public: /** Read some data. This function is used to read some data from the stream. - + The call blocks until one of the following is true: @li One or more bytes are read from the stream. @@ -1172,11 +1173,11 @@ public: @param buffers The buffers into which the data will be read. If the size of the buffers is zero bytes, the call always returns immediately with no error. - + @returns The number of bytes read. - + @throws system_error Thrown on failure. - + @note The `read_some` operation may not receive all of the requested number of bytes. Consider using the function `net::read` if you need to ensure that the requested amount of data is read before the @@ -1202,11 +1203,11 @@ public: @param buffers The buffers into which the data will be read. If the size of the buffers is zero bytes, the call always returns immediately with no error. - + @param ec Set to indicate what error occurred, if any. @returns The number of bytes read. - + @note The `read_some` operation may not receive all of the requested number of bytes. Consider using the function `net::read` if you need to ensure that the requested amount of data is read before the @@ -1224,7 +1225,7 @@ public: /** Read some data asynchronously. This function is used to asynchronously read data from the stream. - + This call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -1247,7 +1248,7 @@ public: Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. - + @param handler The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of @@ -1277,7 +1278,7 @@ public: /** Write some data. This function is used to write some data to the stream. - + The call blocks until one of the following is true: @li One or more bytes are written to the stream. @@ -1289,9 +1290,9 @@ public: with no error. @returns The number of bytes written. - + @throws system_error Thrown on failure. - + @note The `write_some` operation may not transmit all of the requested number of bytes. Consider using the function `net::write` if you need to ensure that the requested amount of data is written before the @@ -1307,7 +1308,7 @@ public: /** Write some data. This function is used to write some data to the stream. - + The call blocks until one of the following is true: @li One or more bytes are written to the stream. @@ -1321,9 +1322,9 @@ public: @param ec Set to indicate what error occurred, if any. @returns The number of bytes written. - + @throws system_error Thrown on failure. - + @note The `write_some` operation may not transmit all of the requested number of bytes. Consider using the function `net::write` if you need to ensure that the requested amount of data is written before the @@ -1341,7 +1342,7 @@ public: /** Write some data asynchronously. This function is used to asynchronously write data to the underlying socket. - + This call always returns immediately. The asynchronous operation will continue until one of the following conditions is true: @@ -1364,7 +1365,7 @@ public: Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called. - + @param handler The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of diff --git a/include/boost/beast/core/impl/basic_stream.hpp b/include/boost/beast/core/impl/basic_stream.hpp index c8719445..3c01469c 100644 --- a/include/boost/beast/core/impl/basic_stream.hpp +++ b/include/boost/beast/core/impl/basic_stream.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -161,12 +160,21 @@ close() //------------------------------------------------------------------------------ template +template struct basic_stream:: timeout_handler { + using executor_type = Executor2; + op_state& state; boost::weak_ptr wp; tick_type tick; + executor_type ex; + + executor_type get_executor() const noexcept + { + return ex; + } void operator()(error_code ec) @@ -329,13 +337,11 @@ public: // if a timeout is active, wait on the timer if(state().timer.expiry() != never()) state().timer.async_wait( - net::bind_executor( - this->get_executor(), - timeout_handler{ - state(), - impl_, - state().tick - })); + timeout_handlerget_executor())>{ + state(), + impl_, + state().tick, + this->get_executor()}); // check rate limit, maybe wait std::size_t amount; @@ -430,12 +436,11 @@ public: { if(state().timer.expiry() != stream_base::never()) impl_->write.timer.async_wait( - net::bind_executor( - this->get_executor(), - timeout_handler{ - state(), - impl_, - state().tick})); + timeout_handlerget_executor())>{ + state(), + impl_, + state().tick, + this->get_executor()}); impl_->socket.async_connect( ep, std::move(*this)); @@ -458,12 +463,11 @@ public: { if(state().timer.expiry() != stream_base::never()) impl_->write.timer.async_wait( - net::bind_executor( - this->get_executor(), - timeout_handler{ - state(), - impl_, - state().tick})); + timeout_handlerget_executor())>{ + state(), + impl_, + state().tick, + this->get_executor()}); net::async_connect(impl_->socket, eps, cond, std::move(*this)); @@ -486,12 +490,11 @@ public: { if(state().timer.expiry() != stream_base::never()) impl_->write.timer.async_wait( - net::bind_executor( - this->get_executor(), - timeout_handler{ - state(), - impl_, - state().tick})); + timeout_handlerget_executor())>{ + state(), + impl_, + state().tick, + this->get_executor()}); net::async_connect(impl_->socket, begin, end, cond, std::move(*this));