diff --git a/CHANGELOG.md b/CHANGELOG.md index b683f67d..7b0cb6f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ WebSocket: * Tidy up websocket javadocs * Refactor accept, handshake ops +* Use read buffer instead of buffered stream -------------------------------------------------------------------------------- diff --git a/include/boost/beast/websocket/impl/accept.ipp b/include/boost/beast/websocket/impl/accept.ipp index fcf6df32..a0d2c5b5 100644 --- a/include/boost/beast/websocket/impl/accept.ipp +++ b/include/boost/beast/websocket/impl/accept.ipp @@ -119,11 +119,11 @@ operator()(Buffers const& buffers) auto& d = *d_; error_code ec; boost::optional mb; + static_buffer_base::mutable_buffers_type> mb; auto const len = buffer_size(buffers); try { - mb.emplace(d.ws.stream_.buffer().prepare(len)); + mb.emplace(d.ws.rd_.buf.prepare(len)); } catch(std::length_error const&) { @@ -132,7 +132,7 @@ operator()(Buffers const& buffers) return d.ws.get_io_service().post( bind_handler(std::move(*this), ec)); } - d.ws.stream_.buffer().commit( + d.ws.rd_.buf.commit( buffer_copy(*mb, buffers)); (*this)(ec); } @@ -263,11 +263,11 @@ operator()(Buffers const& buffers) auto& d = *d_; error_code ec; boost::optional mb; + static_buffer_base::mutable_buffers_type> mb; auto const len = buffer_size(buffers); try { - mb.emplace(d.ws.stream_.buffer().prepare(len)); + mb.emplace(d.ws.rd_.buf.prepare(len)); } catch(std::length_error const&) { @@ -276,7 +276,7 @@ operator()(Buffers const& buffers) return d.ws.get_io_service().post( bind_handler(std::move(*this), ec)); } - d.ws.stream_.buffer().commit( + d.ws.rd_.buf.commit( buffer_copy(*mb, buffers)); (*this)(ec); } @@ -294,7 +294,7 @@ operator()(error_code ec) case 0: d.step = 1; return http::async_read( - d.ws.next_layer(), d.ws.stream_.buffer(), + d.ws.next_layer(), d.ws.rd_.buf, d.p, std::move(*this)); case 1: @@ -437,8 +437,8 @@ accept(ConstBufferSequence const& buffers, error_code& ec) reset(); using boost::asio::buffer_copy; using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( + rd_.buf.commit(buffer_copy( + rd_.buf.prepare( buffer_size(buffers)), buffers)); do_accept(&default_decorate_res, ec); } @@ -463,8 +463,8 @@ accept_ex(ConstBufferSequence const& buffers, reset(); using boost::asio::buffer_copy; using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( + rd_.buf.commit(buffer_copy( + rd_.buf.prepare( buffer_size(buffers)), buffers)); do_accept(decorator, ec); } @@ -597,8 +597,8 @@ accept(http::request p; http::read(next_layer(), - stream_.buffer(), p, ec); + rd_.buf, p, ec); if(ec) return; do_accept(p.get(), decorator, ec); diff --git a/include/boost/beast/websocket/impl/handshake.ipp b/include/boost/beast/websocket/impl/handshake.ipp index 4c035295..1c4bc5c4 100644 --- a/include/boost/beast/websocket/impl/handshake.ipp +++ b/include/boost/beast/websocket/impl/handshake.ipp @@ -148,7 +148,7 @@ operator()(error_code ec, bool again) // read http response d.state = 2; http::async_read(d.ws.next_layer(), - d.ws.stream_.buffer(), d.res, + d.ws.rd_.buf, d.res, std::move(*this)); return; @@ -413,7 +413,7 @@ do_handshake( } if(ec) return; - http::read(next_layer(), stream_.buffer(), res, ec); + http::read(next_layer(), rd_.buf, res, ec); if(ec) return; do_response(res, key, ec); @@ -421,8 +421,6 @@ do_handshake( *res_p = std::move(res); } -//------------------------------------------------------------------------------ - } // websocket } // beast } // boost diff --git a/include/boost/beast/websocket/impl/stream.ipp b/include/boost/beast/websocket/impl/stream.ipp index a480c7b1..6e680fa2 100644 --- a/include/boost/beast/websocket/impl/stream.ipp +++ b/include/boost/beast/websocket/impl/stream.ipp @@ -140,7 +140,8 @@ open(role_type role) rd_.remain = 0; rd_.cont = false; rd_.done = true; - rd_.buf.consume(rd_.buf.size()); + // Can't clear this because accept uses it + //rd_.buf.consume(rd_.buf.size()); rd_.fh.fin = false; rd_close_ = false; wr_close_ = false; @@ -204,9 +205,6 @@ reset() wr_.cont = false; wr_block_.reset(); ping_data_ = nullptr; // should be nullptr on close anyway - - stream_.buffer().consume( - stream_.buffer().size()); } // Called before each write frame diff --git a/include/boost/beast/websocket/stream.hpp b/include/boost/beast/websocket/stream.hpp index 3e410f3d..ea572cc5 100644 --- a/include/boost/beast/websocket/stream.hpp +++ b/include/boost/beast/websocket/stream.hpp @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include #include @@ -223,8 +221,7 @@ class stream zlib::inflate_stream zi; }; - buffered_read_stream< - NextLayer, flat_buffer> stream_; // the wrapped stream + NextLayer stream_; // the wrapped stream detail::maskgen maskgen_; // source of mask keys std::size_t rd_msg_max_ = 16 * 1024 * 1024; // max message size @@ -343,7 +340,7 @@ public: next_layer_type& next_layer() { - return stream_.next_layer(); + return stream_; } /** Get a reference to the next layer @@ -357,7 +354,7 @@ public: next_layer_type const& next_layer() const { - return stream_.next_layer(); + return stream_; } /** Get a reference to the lowest layer @@ -717,1155 +714,10 @@ public: //-------------------------------------------------------------------------- // - // Handshaking + // Handshaking (Client) // //-------------------------------------------------------------------------- - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @throws system_error Thrown on failure. - */ - void - accept(); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(ResponseDecorator const& decorator); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param ec Set to indicate what error occurred, if any. - */ - void - accept(error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex( - ResponseDecorator const& decorator, - error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @throws system_error Thrown on failure. - */ - template -#if BOOST_BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept(ConstBufferSequence const& buffers); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template -#if BOOST_BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept_ex( - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param ec Set to indicate what error occurred, if any. - */ - template -#if BOOST_BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept( - ConstBufferSequence const& buffers, - error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template -#if BOOST_BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept_ex( - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @throws system_error Thrown on failure. - */ - template - void - accept(http::request> const& req); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(http::request> const& req, - ResponseDecorator const& decorator); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept(http::request> const& req, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex(http::request> const& req, - ResponseDecorator const& decorator, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @throws system_error Thrown on failure. - */ - template - void - accept(http::request> const& req, - ConstBufferSequence const& buffers); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(http::request> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept(http::request> const& req, - ConstBufferSequence const& buffers, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex(http::request> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - error_code& ec); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex(ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -#endif - async_accept(ConstBufferSequence const& buffers, - AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -#endif - async_accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(http::request> const& req, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex(http::request> const& req, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(http::request> const& req, - ConstBufferSequence const& buffers, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - 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 `boost::asio::io_service::post`. - */ - template< - class Body, class Allocator, - class ConstBufferSequence, - class ResponseDecorator, - class AcceptHandler> -#if BOOST_BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex( - http::request> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - /** Send an HTTP WebSocket Upgrade request and receive the response. This function is used to synchronously send the WebSocket @@ -2534,6 +1386,1271 @@ public: RequestDecorator const& decorator, HandshakeHandler&& handler); + //-------------------------------------------------------------------------- + // + // Handshaking (Server) + // + //-------------------------------------------------------------------------- + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @throws system_error Thrown on failure. + */ + void + accept(); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @throws system_error Thrown on failure. + */ + template + void + accept_ex(ResponseDecorator const& decorator); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param ec Set to indicate what error occurred, if any. + */ + void + accept(error_code& ec); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param ec Set to indicate what error occurred, if any. + */ + template + void + accept_ex( + ResponseDecorator const& decorator, + error_code& ec); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. The implementation will copy the + caller provided data before the function returns. + + @throws system_error Thrown on failure. + */ + template +#if BOOST_BEAST_DOXYGEN + void +#else + typename std::enable_if::value>::type +#endif + accept(ConstBufferSequence const& buffers); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. The implementation will copy the + caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @throws system_error Thrown on failure. + */ + template +#if BOOST_BEAST_DOXYGEN + void +#else + typename std::enable_if::value>::type +#endif + accept_ex( + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. The implementation will copy the + caller provided data before the function returns. + + @param ec Set to indicate what error occurred, if any. + */ + template +#if BOOST_BEAST_DOXYGEN + void +#else + typename std::enable_if::value>::type +#endif + accept( + ConstBufferSequence const& buffers, + error_code& ec); + + /** Read and respond to a WebSocket HTTP Upgrade request. + + This function is used to synchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The call blocks + until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. The implementation will copy the + caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param ec Set to indicate what error occurred, if any. + */ + template +#if BOOST_BEAST_DOXYGEN + void +#else + typename std::enable_if::value>::type +#endif + accept_ex( + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator, + error_code& ec); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @throws system_error Thrown on failure. + */ + template + void + accept(http::request> const& req); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @throws system_error Thrown on failure. + */ + template + void + accept_ex(http::request> const& req, + ResponseDecorator const& decorator); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param ec Set to indicate what error occurred, if any. + */ + template + void + accept(http::request> const& req, + error_code& ec); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param ec Set to indicate what error occurred, if any. + */ + template + void + accept_ex(http::request> const& req, + ResponseDecorator const& decorator, + error_code& ec); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This must not include the octets + corresponding to the HTTP Upgrade request. The implementation + will copy the caller provided data before the function returns. + + @throws system_error Thrown on failure. + */ + template + void + accept(http::request> const& req, + ConstBufferSequence const& buffers); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This must not include the octets + corresponding to the HTTP Upgrade request. The implementation + will copy the caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @throws system_error Thrown on failure. + */ + template + void + accept_ex(http::request> const& req, + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This must not include the octets + corresponding to the HTTP Upgrade request. The implementation + will copy the caller provided data before the function returns. + + @param ec Set to indicate what error occurred, if any. + */ + template + void + accept(http::request> const& req, + ConstBufferSequence const& buffers, + error_code& ec); + + /** Respond to a WebSocket HTTP Upgrade request + + This function is used to synchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade. + The call blocks until one of the following conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This function is implemented in terms of one or more calls to + the next layer's `read_some` and `write_some` functions. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When this call returns, the stream is then ready to send and + receive WebSocket protocol frames and messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not + access this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This must not include the octets + corresponding to the HTTP Upgrade request. The implementation + will copy the caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param ec Set to indicate what error occurred, if any. + */ + template + void + accept_ex(http::request> const& req, + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator, + error_code& ec); + + /** Start reading and responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The function call + always returns immediately. The asynchronous operation will + continue until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_read_some` and `async_write_some` + functions, and is known as a composed operation. The + program must ensure that the stream performs no other + asynchronous operations until this operation completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept(AcceptHandler&& handler); + + /** Start reading and responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The function call + always returns immediately. The asynchronous operation will + continue until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_read_some` and `async_write_some` + functions, and is known as a composed operation. The + program must ensure that the stream performs no other + asynchronous operations until this operation completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept_ex(ResponseDecorator const& decorator, + AcceptHandler&& handler); + + /** Start reading and responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The function call + always returns immediately. The asynchronous operation will + continue until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_read_some` and `async_write_some` + functions, and is known as a composed operation. The + program must ensure that the stream performs no other + asynchronous operations until this operation completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. This may be used for implementations + allowing multiple protocols on the same stream. The + buffered data will first be applied to the handshake, and + then to received WebSocket frames. The implementation will + copy the caller provided data before the function returns. + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + typename std::enable_if< + ! http::detail::is_header::value, + async_return_type>::type +#endif + async_accept(ConstBufferSequence const& buffers, + AcceptHandler&& handler); + + /** Start reading and responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously read an HTTP WebSocket + Upgrade request and send the HTTP response. The function call + always returns immediately. The asynchronous operation will + continue until one of the following conditions is true: + + @li The request is received and the response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_read_some` and `async_write_some` + functions, and is known as a composed operation. The + program must ensure that the stream performs no other + asynchronous operations until this operation completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + receive the request. If the request is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to receive larger requests should first read the + request using their own buffer and a suitable overload of + @ref http::read or @ref http::async_read, then call @ref accept + or @ref async_accept with the request. + + @param buffers Caller provided data that has already been + received on the stream. This may be used for implementations + allowing multiple protocols on the same stream. The + buffered data will first be applied to the handshake, and + then to received WebSocket frames. The implementation will + copy the caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + typename std::enable_if< + ! http::detail::is_header::value, + async_return_type>::type +#endif + async_accept_ex(ConstBufferSequence const& buffers, + ResponseDecorator const& decorator, + AcceptHandler&& handler); + + /** Start responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade + request. The function call always returns immediately. The + asynchronous operation will continue until one of the following + conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_write_some` functions, and is known as + a composed operation. The program must ensure that the + stream performs no other operations until this operation + completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not access + this object from other threads. + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept(http::request> const& req, + AcceptHandler&& handler); + + /** Start responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade + request. The function call always returns immediately. The + asynchronous operation will continue until one of the following + conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_write_some` functions, and is known as + a composed operation. The program must ensure that the + stream performs no other operations until this operation + completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not access + this object from other threads. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept_ex(http::request> const& req, + ResponseDecorator const& decorator, + AcceptHandler&& handler); + + /** Start responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade + request. The function call always returns immediately. The + asynchronous operation will continue until one of the following + conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_write_some` functions, and is known as + a composed operation. The program must ensure that the + stream performs no other operations until this operation + completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not access + this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This may be used for implementations + allowing multiple protocols on the same stream. The + buffered data will first be applied to the handshake, and + then to received WebSocket frames. The implementation will + copy the caller provided data before the function returns. + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept(http::request> const& req, + ConstBufferSequence const& buffers, + AcceptHandler&& handler); + + /** Start responding to a WebSocket HTTP Upgrade request. + + This function is used to asynchronously send the HTTP response + to an HTTP request possibly containing a WebSocket Upgrade + request. The function call always returns immediately. The + asynchronous operation will continue until one of the following + conditions is true: + + @li The response finishes sending. + + @li An error occurs on the stream. + + This operation is implemented in terms of one or more calls to + the next layer's `async_write_some` functions, and is known as + a composed operation. The program must ensure that the + stream performs no other operations until this operation + completes. + + If the stream receives a valid HTTP WebSocket Upgrade request, + an HTTP response is sent back indicating a successful upgrade. + When the completion handler is invoked, the stream is then + ready to send and receive WebSocket protocol frames and + messages. + If the HTTP Upgrade request is invalid or cannot be satisfied, + an HTTP response is sent indicating the reason and status code + (typically 400, "Bad Request"). This counts as a failure, and + the completion handler will be invoked with a suitable error + code set. + + The implementation uses fixed size internal storage to + copy the buffer. If the buffer is too large, the error + @ref error::buffer_overflow will be indicated. Applications + that wish to supply larger buffers should wrap the next layer + in a @ref buffered_read_stream and store the buffer contents in + the wrapper before calling accept. + + @param req An object containing the HTTP Upgrade request. + Ownership is not transferred, the implementation will not access + this object from other threads. + + @param buffers Caller provided data that has already been + received on the stream. This may be used for implementations + allowing multiple protocols on the same stream. The + buffered data will first be applied to the handshake, and + then to received WebSocket frames. The implementation will + copy the caller provided data before the function returns. + + @param decorator A function object which will be called to modify + the HTTP response object delivered by the implementation. This + could be used to set the Server field, subprotocols, or other + application or HTTP specific fields. The object will be called + with this equivalent signature: + @code void decorator( + response_type& res + ); @endcode + + @param handler The handler to be called when the request + completes. Copies will be made of the handler as required. The + equivalent function signature of the handler must be: + @code void handler( + 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 `boost::asio::io_service::post`. + */ + template< + class Body, class Allocator, + class ConstBufferSequence, + class ResponseDecorator, + class AcceptHandler> +#if BOOST_BEAST_DOXYGEN + void_or_deduced +#else + async_return_type< + AcceptHandler, void(error_code)> +#endif + async_accept_ex( + http::request> const& req, + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator, + AcceptHandler&& handler); + //-------------------------------------------------------------------------- // // Control Frames