2017-07-20 08:01:46 -07:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
//
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#ifndef BOOST_BEAST_WEBSOCKET_STREAM_HPP
|
|
|
|
#define BOOST_BEAST_WEBSOCKET_STREAM_HPP
|
|
|
|
|
2017-10-10 07:49:03 -07:00
|
|
|
#include <boost/beast/core/detail/config.hpp>
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/websocket/error.hpp>
|
|
|
|
#include <boost/beast/websocket/option.hpp>
|
|
|
|
#include <boost/beast/websocket/rfc6455.hpp>
|
2019-02-13 08:00:07 -08:00
|
|
|
#include <boost/beast/websocket/stream_base.hpp>
|
2017-12-29 09:25:18 -08:00
|
|
|
#include <boost/beast/websocket/stream_fwd.hpp>
|
2019-01-19 07:24:00 -08:00
|
|
|
#include <boost/beast/websocket/detail/hybi13.hpp>
|
2019-02-13 08:00:07 -08:00
|
|
|
#include <boost/beast/websocket/detail/impl_base.hpp>
|
|
|
|
#include <boost/beast/websocket/detail/pmd_extension.hpp>
|
2019-03-10 20:56:40 +01:00
|
|
|
#include <boost/beast/websocket/detail/prng.hpp>
|
2019-02-25 16:00:50 -08:00
|
|
|
#include <boost/beast/core/role.hpp>
|
2019-02-20 20:25:01 -08:00
|
|
|
#include <boost/beast/core/stream_traits.hpp>
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/string.hpp>
|
|
|
|
#include <boost/beast/http/detail/type_traits.hpp>
|
2017-09-07 07:39:52 -07:00
|
|
|
#include <boost/asio/async_result.hpp>
|
2017-08-26 20:10:04 -07:00
|
|
|
#include <boost/asio/error.hpp>
|
2019-02-13 08:00:07 -08:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
2017-06-24 12:11:46 -07:00
|
|
|
#include <functional>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <limits>
|
2019-01-19 07:24:00 -08:00
|
|
|
#include <memory>
|
2017-04-25 10:12:43 -07:00
|
|
|
#include <type_traits>
|
2019-03-10 20:56:40 +01:00
|
|
|
#include <random>
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2017-07-20 08:01:46 -07:00
|
|
|
namespace beast {
|
|
|
|
namespace websocket {
|
|
|
|
|
2017-06-24 12:11:46 -07:00
|
|
|
/** The type of received control frame.
|
|
|
|
|
|
|
|
Values of this type are passed to the control frame
|
|
|
|
callback set using @ref stream::control_callback.
|
|
|
|
*/
|
|
|
|
enum class frame_type
|
|
|
|
{
|
|
|
|
/// A close frame was received
|
|
|
|
close,
|
|
|
|
|
|
|
|
/// A ping frame was received
|
|
|
|
ping,
|
|
|
|
|
|
|
|
/// A pong frame was received
|
|
|
|
pong
|
|
|
|
};
|
2017-06-24 10:13:17 -07:00
|
|
|
|
2017-12-29 09:26:29 -08:00
|
|
|
namespace detail {
|
|
|
|
class frame_test;
|
|
|
|
} // detail
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** Provides message-oriented functionality using WebSocket.
|
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
The @ref stream class template provides asynchronous and blocking
|
2017-07-20 08:01:46 -07:00
|
|
|
message-oriented functionality necessary for clients and servers
|
|
|
|
to utilize the WebSocket protocol.
|
2018-11-24 00:41:53 +01:00
|
|
|
|
2017-04-27 17:21:57 -07:00
|
|
|
For asynchronous operations, the application must ensure
|
|
|
|
that they are are all performed within the same implicit
|
|
|
|
or explicit strand.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-20 21:28:17 -07:00
|
|
|
@par Thread Safety
|
|
|
|
@e Distinct @e objects: Safe.@n
|
|
|
|
@e Shared @e objects: Unsafe.
|
2017-11-05 09:29:33 -08:00
|
|
|
The application must also ensure that all asynchronous
|
|
|
|
operations are performed within the same implicit or explicit strand.
|
2017-06-20 21:28:17 -07:00
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
@par Example
|
2019-02-13 08:00:07 -08:00
|
|
|
To declare the @ref stream object with a @ref tcp_stream in a
|
|
|
|
multi-threaded asynchronous program using a strand, you may write:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
2019-02-18 12:42:24 -08:00
|
|
|
websocket::stream<tcp_stream> ws{net::io_context::strand(ioc)};
|
2017-07-20 08:01:46 -07:00
|
|
|
@endcode
|
2019-02-13 08:00:07 -08:00
|
|
|
Alternatively, for a single-threaded or synchronous application
|
|
|
|
you may write:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
2019-02-18 12:42:24 -08:00
|
|
|
websocket::stream<tcp_stream> ws(ioc);
|
2017-07-20 08:01:46 -07:00
|
|
|
@endcode
|
|
|
|
|
2017-06-20 21:28:17 -07:00
|
|
|
@tparam NextLayer The type representing the next layer, to which
|
|
|
|
data will be read and written during operations. For synchronous
|
2019-03-05 12:05:00 -08:00
|
|
|
operations, the type must support the <em>SyncStream</em> concept.
|
2017-06-20 21:28:17 -07:00
|
|
|
For asynchronous operations, the type must support the
|
2019-03-05 12:05:00 -08:00
|
|
|
<em>AsyncStream</em> concept.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-11-18 16:52:18 -08:00
|
|
|
@tparam deflateSupported A `bool` indicating whether or not the
|
|
|
|
stream will be capable of negotiating the permessage-deflate websocket
|
|
|
|
extension. Note that even if this is set to `true`, the permessage
|
|
|
|
deflate options (set by the caller at runtime) must still have the
|
|
|
|
feature enabled for a successful negotiation to occur.
|
|
|
|
|
2016-09-25 11:19:51 -04:00
|
|
|
@note A stream object must not be moved or destroyed while there
|
|
|
|
are pending asynchronous operations associated with it.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@par Concepts
|
2019-03-05 12:05:00 -08:00
|
|
|
@li <em>AsyncStream</em>
|
|
|
|
@li <em>DynamicBuffer</em>
|
|
|
|
@li <em>SyncStream</em>
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">Websocket Close (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">WebSocket Ping (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">WebSocket Pong (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-11-18 16:52:18 -08:00
|
|
|
template<
|
|
|
|
class NextLayer,
|
|
|
|
bool deflateSupported>
|
2017-06-24 10:13:17 -07:00
|
|
|
class stream
|
2018-05-29 15:31:42 -07:00
|
|
|
#if ! BOOST_BEAST_DOXYGEN
|
2019-02-13 08:00:07 -08:00
|
|
|
: private stream_base
|
2017-11-18 16:52:18 -08:00
|
|
|
#endif
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2019-02-20 20:25:01 -08:00
|
|
|
struct impl_type;
|
|
|
|
|
|
|
|
boost::shared_ptr<impl_type> impl_;
|
|
|
|
|
|
|
|
using time_point = typename
|
|
|
|
std::chrono::steady_clock::time_point;
|
|
|
|
|
|
|
|
using control_cb_type =
|
|
|
|
std::function<void(frame_type, string_view)>;
|
|
|
|
|
2017-08-26 06:13:11 -07:00
|
|
|
friend class close_test;
|
2017-07-14 12:11:44 -07:00
|
|
|
friend class frame_test;
|
2017-08-26 06:13:11 -07:00
|
|
|
friend class ping_test;
|
2017-12-06 21:59:39 +01:00
|
|
|
friend class read2_test;
|
2019-02-13 08:00:07 -08:00
|
|
|
friend class read3_test;
|
2017-08-24 06:21:30 -07:00
|
|
|
friend class stream_test;
|
2017-08-26 06:13:11 -07:00
|
|
|
friend class write_test;
|
2018-11-24 00:41:53 +01:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
/* The read buffer has to be at least as large
|
|
|
|
as the largest possible control frame including
|
|
|
|
the frame header.
|
|
|
|
*/
|
|
|
|
static std::size_t constexpr max_control_frame_size = 2 + 8 + 4 + 125;
|
|
|
|
static std::size_t constexpr tcp_frame_size = 1536;
|
|
|
|
|
2019-02-20 22:01:30 -08:00
|
|
|
static time_point never() noexcept
|
2019-01-20 12:25:30 -08:00
|
|
|
{
|
|
|
|
return (time_point::max)();
|
|
|
|
}
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
public:
|
2017-11-18 16:52:18 -08:00
|
|
|
/// Indicates if the permessage-deflate extension is supported
|
|
|
|
using is_deflate_supported =
|
|
|
|
std::integral_constant<bool, deflateSupported>;
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
/// The type of the next layer.
|
|
|
|
using next_layer_type =
|
|
|
|
typename std::remove_reference<NextLayer>::type;
|
|
|
|
|
2017-10-24 06:40:22 -07:00
|
|
|
/// The type of the executor associated with the object.
|
2019-02-20 20:25:01 -08:00
|
|
|
using executor_type =
|
|
|
|
beast::executor_type<next_layer_type>;
|
2017-10-24 06:40:22 -07:00
|
|
|
|
2017-07-14 12:11:44 -07:00
|
|
|
/** Destructor
|
|
|
|
|
|
|
|
Destroys the stream and all associated resources.
|
|
|
|
|
|
|
|
@note A stream object must not be destroyed while there
|
|
|
|
are pending asynchronous operations associated with it.
|
|
|
|
*/
|
2019-02-27 15:02:00 -08:00
|
|
|
~stream();
|
2017-07-14 12:11:44 -07:00
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
/** Constructor
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-14 12:11:44 -07:00
|
|
|
If `NextLayer` is move constructible, this function
|
2016-04-30 13:00:33 -04:00
|
|
|
will move-construct a new stream from the existing stream.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-27 15:02:00 -08:00
|
|
|
After the move, the only valid operation on the moved-from
|
|
|
|
object is destruction.
|
2016-04-30 13:00:33 -04:00
|
|
|
*/
|
2017-07-20 08:01:46 -07:00
|
|
|
stream(stream&&) = default;
|
|
|
|
|
2019-02-27 15:02:00 -08:00
|
|
|
/// Move assignment (deleted)
|
|
|
|
stream& operator=(stream&&) = delete;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-12 05:01:24 -07:00
|
|
|
/** Constructor
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-15 16:22:25 -04:00
|
|
|
This constructor creates a websocket stream and initializes
|
2017-07-20 08:01:46 -07:00
|
|
|
the next layer object.
|
|
|
|
|
|
|
|
@throws Any exceptions thrown by the NextLayer constructor.
|
|
|
|
|
2016-05-15 16:22:25 -04:00
|
|
|
@param args The arguments to be passed to initialize the
|
2017-07-20 08:01:46 -07:00
|
|
|
next layer object. The arguments are forwarded to the next
|
|
|
|
layer's constructor.
|
|
|
|
*/
|
|
|
|
template<class... Args>
|
|
|
|
explicit
|
|
|
|
stream(Args&&... args);
|
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2017-09-07 07:39:52 -07:00
|
|
|
/** Get the executor associated with the object.
|
2018-11-24 00:41:53 +01:00
|
|
|
|
2017-10-24 06:40:22 -07:00
|
|
|
This function may be used to obtain the executor object that the
|
|
|
|
stream uses to dispatch handlers for asynchronous operations.
|
2017-06-08 17:36:31 -07:00
|
|
|
|
2017-09-07 07:39:52 -07:00
|
|
|
@return A copy of the executor that stream will use to dispatch handlers.
|
2017-06-08 18:03:10 -07:00
|
|
|
*/
|
2017-10-24 06:40:22 -07:00
|
|
|
executor_type
|
2019-04-18 18:31:39 -07:00
|
|
|
get_executor() noexcept;
|
2017-06-08 17:36:31 -07:00
|
|
|
|
2017-06-12 05:01:24 -07:00
|
|
|
/** Get a reference to the next layer
|
2017-06-08 17:36:31 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
This function returns a reference to the next layer
|
|
|
|
in a stack of stream layers.
|
2017-06-08 17:36:31 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
@return A reference to the next layer in the stack of
|
2017-06-12 05:01:24 -07:00
|
|
|
stream layers.
|
2017-06-08 17:36:31 -07:00
|
|
|
*/
|
2017-06-08 18:03:10 -07:00
|
|
|
next_layer_type&
|
2019-01-19 07:24:00 -08:00
|
|
|
next_layer() noexcept;
|
2017-06-08 17:36:31 -07:00
|
|
|
|
2017-06-12 05:01:24 -07:00
|
|
|
/** Get a reference to the next layer
|
2017-06-08 18:03:10 -07:00
|
|
|
|
|
|
|
This function returns a reference to the next layer in a
|
|
|
|
stack of stream layers.
|
|
|
|
|
|
|
|
@return A reference to the next layer in the stack of
|
2017-06-12 05:01:24 -07:00
|
|
|
stream layers.
|
2017-06-08 18:03:10 -07:00
|
|
|
*/
|
|
|
|
next_layer_type const&
|
2019-01-19 07:24:00 -08:00
|
|
|
next_layer() const noexcept;
|
2017-06-08 18:03:10 -07:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Observers
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2017-08-26 20:10:04 -07:00
|
|
|
/** Returns `true` if the stream is open.
|
|
|
|
|
|
|
|
The stream is open after a successful handshake, and when
|
|
|
|
no error has occurred.
|
|
|
|
*/
|
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
is_open() const noexcept;
|
2017-08-26 20:10:04 -07:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
/** Returns `true` if the latest message data indicates binary.
|
|
|
|
|
|
|
|
This function informs the caller of whether the last
|
|
|
|
received message frame represents a message with the
|
|
|
|
binary opcode.
|
|
|
|
|
|
|
|
If there is no last message frame, the return value is
|
|
|
|
undefined.
|
|
|
|
*/
|
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
got_binary() const noexcept;
|
2017-07-15 17:05:24 -07:00
|
|
|
|
|
|
|
/** Returns `true` if the latest message data indicates text.
|
|
|
|
|
|
|
|
This function informs the caller of whether the last
|
|
|
|
received message frame represents a message with the
|
|
|
|
text opcode.
|
|
|
|
|
|
|
|
If there is no last message frame, the return value is
|
|
|
|
undefined.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
got_text() const
|
|
|
|
{
|
|
|
|
return ! got_binary();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns `true` if the last completed read finished the current message.
|
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
is_message_done() const noexcept;
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Returns the close reason received from the remote peer.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
|
|
|
This is only valid after a read completes with error::closed.
|
|
|
|
*/
|
|
|
|
close_reason const&
|
2019-01-19 07:24:00 -08:00
|
|
|
reason() const noexcept;
|
2017-07-15 17:05:24 -07:00
|
|
|
|
|
|
|
/** Returns a suggested maximum buffer size for the next call to read.
|
|
|
|
|
|
|
|
This function returns a reasonable upper limit on the number
|
|
|
|
of bytes for the size of the buffer passed in the next call
|
|
|
|
to read. The number is determined by the state of the current
|
|
|
|
frame and whether or not the permessage-deflate extension is
|
|
|
|
enabled.
|
|
|
|
|
2017-08-01 20:15:07 -07:00
|
|
|
@param initial_size A non-zero size representing the caller's
|
|
|
|
desired buffer size for when there is no information which may
|
|
|
|
be used to calculate a more specific value. For example, when
|
|
|
|
reading the first frame header of a message.
|
2017-07-15 17:05:24 -07:00
|
|
|
*/
|
|
|
|
std::size_t
|
|
|
|
read_size_hint(
|
2019-01-19 07:24:00 -08:00
|
|
|
std::size_t initial_size = +tcp_frame_size) const;
|
2017-07-15 17:05:24 -07:00
|
|
|
|
|
|
|
/** Returns a suggested maximum buffer size for the next call to read.
|
|
|
|
|
|
|
|
This function returns a reasonable upper limit on the number
|
|
|
|
of bytes for the size of the buffer passed in the next call
|
|
|
|
to read. The number is determined by the state of the current
|
|
|
|
frame and whether or not the permessage-deflate extension is
|
|
|
|
enabled.
|
|
|
|
|
|
|
|
@param buffer The buffer which will be used for reading. The
|
|
|
|
implementation will query the buffer to obtain the optimum
|
|
|
|
size of a subsequent call to `buffer.prepare` based on the
|
|
|
|
state of the current frame, if any.
|
|
|
|
*/
|
|
|
|
template<class DynamicBuffer
|
2017-07-20 13:40:34 -07:00
|
|
|
#if ! BOOST_BEAST_DOXYGEN
|
2017-07-15 17:05:24 -07:00
|
|
|
, class = typename std::enable_if<
|
|
|
|
! std::is_integral<DynamicBuffer>::value>::type
|
|
|
|
#endif
|
|
|
|
>
|
|
|
|
std::size_t
|
|
|
|
read_size_hint(
|
|
|
|
DynamicBuffer& buffer) const;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Settings
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-02-13 08:00:07 -08:00
|
|
|
#if BOOST_BEAST_DOXYGEN
|
|
|
|
template<class Option>
|
|
|
|
void
|
|
|
|
get_option(Option& opt);
|
|
|
|
|
|
|
|
template<class Option>
|
|
|
|
void
|
2019-02-17 16:03:09 -08:00
|
|
|
set_option(Option opt);
|
2019-02-13 08:00:07 -08:00
|
|
|
#else
|
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
void set_option(decorator opt);
|
|
|
|
|
2019-02-13 08:00:07 -08:00
|
|
|
void get_option(timeout& opt);
|
|
|
|
void set_option(timeout const& opt);
|
|
|
|
#endif
|
|
|
|
|
2017-11-18 16:52:18 -08:00
|
|
|
/** Set the permessage-deflate extension options
|
|
|
|
|
|
|
|
@throws invalid_argument if `deflateSupported == false`, and either
|
|
|
|
`client_enable` or `server_enable` is `true`.
|
|
|
|
*/
|
2016-10-24 18:41:25 -04:00
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
set_option(permessage_deflate const& o);
|
2016-10-24 18:41:25 -04:00
|
|
|
|
|
|
|
/// Get the permessage-deflate extension options
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
get_option(permessage_deflate& o);
|
2016-10-24 18:41:25 -04:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
/** Set the automatic fragmentation option.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
Determines if outgoing message payloads are broken up into
|
|
|
|
multiple pieces.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
When the automatic fragmentation size is turned on, outgoing
|
|
|
|
message payloads are broken up into multiple frames no larger
|
|
|
|
than the write buffer size.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
The default setting is to fragment messages.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
@param value A `bool` indicating if auto fragmentation should be on.
|
2017-06-08 18:27:32 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
@par Example
|
|
|
|
Setting the automatic fragmentation option:
|
|
|
|
@code
|
|
|
|
ws.auto_fragment(true);
|
|
|
|
@endcode
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-06-08 18:03:10 -07:00
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
auto_fragment(bool value);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
/// Returns `true` if the automatic fragmentation option is set.
|
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
auto_fragment() const;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2018-04-24 12:59:51 +02:00
|
|
|
/** Set the binary message write option.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
This controls whether or not outgoing message opcodes
|
|
|
|
are set to binary or text. The setting is only applied
|
|
|
|
at the start when a caller begins a new message. Changing
|
|
|
|
the opcode after a message is started will only take effect
|
|
|
|
after the current message being sent is complete.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
The default setting is to send text messages.
|
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
@param value `true` if outgoing messages should indicate
|
2017-06-08 18:27:32 -07:00
|
|
|
binary, or `false` if they should indicate text.
|
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
@par Example
|
|
|
|
Setting the message type to binary.
|
|
|
|
@code
|
|
|
|
ws.binary(true);
|
|
|
|
@endcode
|
2017-06-08 18:27:32 -07:00
|
|
|
*/
|
2017-06-08 18:03:10 -07:00
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
binary(bool value);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2018-04-24 12:59:51 +02:00
|
|
|
/// Returns `true` if the binary message write option is set.
|
2017-06-08 18:03:10 -07:00
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
binary() const;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-28 12:04:55 -07:00
|
|
|
/** Set a callback to be invoked on each incoming control frame.
|
2017-06-08 19:28:12 -07:00
|
|
|
|
2017-06-24 12:11:46 -07:00
|
|
|
Sets the callback to be invoked whenever a ping, pong,
|
|
|
|
or close control frame is received during a call to one
|
|
|
|
of the following functions:
|
2017-06-08 19:28:12 -07:00
|
|
|
|
|
|
|
@li @ref beast::websocket::stream::read
|
2017-07-15 17:05:24 -07:00
|
|
|
@li @ref beast::websocket::stream::read_some
|
2017-06-08 19:28:12 -07:00
|
|
|
@li @ref beast::websocket::stream::async_read
|
2017-07-15 17:05:24 -07:00
|
|
|
@li @ref beast::websocket::stream::async_read_some
|
2017-06-08 19:28:12 -07:00
|
|
|
|
|
|
|
Unlike completion handlers, the callback will be invoked
|
2017-06-24 12:11:46 -07:00
|
|
|
for each control frame during a call to any synchronous
|
|
|
|
or asynchronous read function. The operation is passive,
|
|
|
|
with no associated error code, and triggered by reads.
|
2017-06-08 19:28:12 -07:00
|
|
|
|
2017-07-28 12:04:55 -07:00
|
|
|
For close frames, the close reason code may be obtained by
|
|
|
|
calling the function @ref reason.
|
|
|
|
|
|
|
|
@param cb The function object to call, which must be
|
|
|
|
invocable with this equivalent signature:
|
2017-06-08 19:28:12 -07:00
|
|
|
@code
|
|
|
|
void
|
|
|
|
callback(
|
2017-06-24 12:11:46 -07:00
|
|
|
frame_type kind, // The type of frame
|
|
|
|
string_view payload // The payload in the frame
|
2017-06-08 19:28:12 -07:00
|
|
|
);
|
|
|
|
@endcode
|
2017-11-27 15:05:58 -08:00
|
|
|
The implementation type-erases the callback which may require
|
2018-09-23 14:58:03 -04:00
|
|
|
a dynamic allocation. To prevent the possibility of a dynamic
|
2017-11-27 15:05:58 -08:00
|
|
|
allocation, use `std::ref` to wrap the callback.
|
2017-06-24 12:11:46 -07:00
|
|
|
If the read operation which receives the control frame is
|
|
|
|
an asynchronous operation, the callback will be invoked using
|
2017-06-08 19:28:12 -07:00
|
|
|
the same method as that used to invoke the final handler.
|
|
|
|
|
2018-03-01 11:31:41 -08:00
|
|
|
@note Incoming ping and close frames are automatically
|
|
|
|
handled. Pings are responded to with pongs, and a close frame
|
|
|
|
is responded to with a close frame leading to the closure of
|
|
|
|
the stream. It is not necessary to manually send pings, pongs,
|
|
|
|
or close frames from inside the control callback.
|
|
|
|
Attempting to manually send a close frame from inside the
|
|
|
|
control callback after receiving a close frame will result
|
|
|
|
in undefined behavior.
|
2017-07-28 12:04:55 -07:00
|
|
|
*/
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
control_callback(std::function<void(frame_type, string_view)> cb);
|
2017-07-28 12:04:55 -07:00
|
|
|
|
|
|
|
/** Reset the control frame callback.
|
2017-06-24 12:11:46 -07:00
|
|
|
|
2017-07-28 12:04:55 -07:00
|
|
|
This function removes any previously set control frame callback.
|
2017-06-08 19:28:12 -07:00
|
|
|
*/
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
control_callback();
|
2017-06-08 19:28:12 -07:00
|
|
|
|
2017-06-08 18:22:25 -07:00
|
|
|
/** Set the maximum incoming message size option.
|
|
|
|
|
|
|
|
Sets the largest permissible incoming message size. Message
|
|
|
|
frame fields indicating a size that would bring the total
|
|
|
|
message size over this limit will cause a protocol failure.
|
|
|
|
|
|
|
|
The default setting is 16 megabytes. A value of zero indicates
|
|
|
|
a limit of the maximum value of a `std::uint64_t`.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
Setting the maximum read message size.
|
|
|
|
@code
|
|
|
|
ws.read_message_max(65536);
|
|
|
|
@endcode
|
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
@param amount The limit on the size of incoming messages.
|
2017-06-08 18:22:25 -07:00
|
|
|
*/
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
read_message_max(std::size_t amount);
|
2017-06-08 18:22:25 -07:00
|
|
|
|
|
|
|
/// Returns the maximum incoming message size setting.
|
|
|
|
std::size_t
|
2019-01-19 07:24:00 -08:00
|
|
|
read_message_max() const;
|
2017-06-08 18:22:25 -07:00
|
|
|
|
2018-07-05 16:47:07 -07:00
|
|
|
/** Set whether the PRNG is cryptographically secure
|
|
|
|
|
|
|
|
This controls whether or not the source of pseudo-random
|
|
|
|
numbers used to produce the masks required by the WebSocket
|
|
|
|
protocol are of cryptographic quality. When the setting is
|
|
|
|
`true`, a strong algorithm is used which cannot be guessed
|
|
|
|
by observing outputs. When the setting is `false`, a much
|
|
|
|
faster algorithm is used.
|
|
|
|
Masking is only performed by streams operating in the client
|
|
|
|
mode. For streams operating in the server mode, this setting
|
|
|
|
has no effect.
|
|
|
|
By default, newly constructed streams use a secure PRNG.
|
|
|
|
|
|
|
|
If the WebSocket stream is used with an encrypted SSL or TLS
|
|
|
|
next layer, if it is known to the application that intermediate
|
|
|
|
proxies are not vulnerable to cache poisoning, or if the
|
|
|
|
application is designed such that an attacker cannot send
|
|
|
|
arbitrary inputs to the stream interface, then the faster
|
|
|
|
algorithm may be used.
|
|
|
|
|
|
|
|
For more information please consult the WebSocket protocol RFC.
|
|
|
|
|
|
|
|
@param value `true` if the PRNG algorithm should be
|
|
|
|
cryptographically secure.
|
|
|
|
*/
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
secure_prng(bool value);
|
2018-07-05 16:47:07 -07:00
|
|
|
|
2017-06-08 18:27:32 -07:00
|
|
|
/** Set the write buffer size option.
|
|
|
|
|
|
|
|
Sets the size of the write buffer used by the implementation to
|
|
|
|
send frames. The write buffer is needed when masking payload data
|
|
|
|
in the client role, compressing frames, or auto-fragmenting message
|
|
|
|
data.
|
|
|
|
|
|
|
|
Lowering the size of the buffer can decrease the memory requirements
|
|
|
|
for each connection, while increasing the size of the buffer can reduce
|
|
|
|
the number of calls made to the next layer to write data.
|
|
|
|
|
|
|
|
The default setting is 4096. The minimum value is 8.
|
|
|
|
|
|
|
|
The write buffer size can only be changed when the stream is not
|
|
|
|
open. Undefined behavior results if the option is modified after a
|
|
|
|
successful WebSocket handshake.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
Setting the write buffer size.
|
|
|
|
@code
|
2019-03-05 08:47:02 -08:00
|
|
|
ws.write_buffer_bytes(8192);
|
2017-06-08 18:27:32 -07:00
|
|
|
@endcode
|
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
@param amount The size of the write buffer in bytes.
|
2017-06-08 18:27:32 -07:00
|
|
|
*/
|
|
|
|
void
|
2019-03-05 08:47:02 -08:00
|
|
|
write_buffer_bytes(std::size_t amount);
|
2017-06-08 18:27:32 -07:00
|
|
|
|
|
|
|
/// Returns the size of the write buffer.
|
|
|
|
std::size_t
|
2019-03-05 08:47:02 -08:00
|
|
|
write_buffer_bytes() const;
|
2017-06-08 18:27:32 -07:00
|
|
|
|
2018-04-24 12:59:51 +02:00
|
|
|
/** Set the text message write option.
|
2017-06-08 19:55:42 -07:00
|
|
|
|
|
|
|
This controls whether or not outgoing message opcodes
|
|
|
|
are set to binary or text. The setting is only applied
|
|
|
|
at the start when a caller begins a new message. Changing
|
|
|
|
the opcode after a message is started will only take effect
|
|
|
|
after the current message being sent is complete.
|
|
|
|
|
|
|
|
The default setting is to send text messages.
|
|
|
|
|
2017-07-12 07:05:27 -07:00
|
|
|
@param value `true` if outgoing messages should indicate
|
2017-06-08 19:55:42 -07:00
|
|
|
text, or `false` if they should indicate binary.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
Setting the message type to text.
|
|
|
|
@code
|
|
|
|
ws.text(true);
|
|
|
|
@endcode
|
|
|
|
*/
|
|
|
|
void
|
2019-01-19 07:24:00 -08:00
|
|
|
text(bool value);
|
2017-06-08 19:55:42 -07:00
|
|
|
|
2018-04-24 12:59:51 +02:00
|
|
|
/// Returns `true` if the text message write option is set.
|
2017-06-08 19:55:42 -07:00
|
|
|
bool
|
2019-01-19 07:24:00 -08:00
|
|
|
text() const;
|
2017-06-08 19:55:42 -07:00
|
|
|
|
2019-01-20 12:25:30 -08:00
|
|
|
/*
|
|
|
|
timer settings
|
|
|
|
|
|
|
|
* Timer is disabled
|
|
|
|
* Close on timeout
|
|
|
|
- no complete frame received, OR
|
|
|
|
- no complete frame sent
|
|
|
|
* Ping on timeout
|
|
|
|
- ping on no complete frame received
|
|
|
|
* if can't ping?
|
|
|
|
*/
|
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2017-07-27 15:40:10 -07:00
|
|
|
// Handshaking (Client)
|
2017-07-15 17:05:24 -07:00
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
2017-06-08 19:55:42 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake in the client role.
|
|
|
|
|
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
|
|
|
@par Example
|
|
|
|
@code
|
2019-02-08 13:26:55 -08:00
|
|
|
ws.handshake("localhost", "/");
|
2017-07-27 15:40:10 -07:00
|
|
|
@endcode
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
void
|
2017-07-27 15:40:10 -07:00
|
|
|
handshake(
|
|
|
|
string_view host,
|
|
|
|
string_view target);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake in the client role.
|
|
|
|
|
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param res The HTTP Upgrade response returned by the remote
|
2019-02-08 13:26:55 -08:00
|
|
|
endpoint. The caller may use the response to access any
|
|
|
|
additional information sent by the server.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
|
|
|
@throws system_error Thrown on failure.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
|
|
|
@par Example
|
|
|
|
@code
|
2019-02-08 13:26:55 -08:00
|
|
|
response_type res;
|
|
|
|
ws.handshake(res, "localhost", "/");
|
|
|
|
std::cout << res;
|
2017-07-27 15:40:10 -07:00
|
|
|
@endcode
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
|
|
|
void
|
2017-07-27 15:40:10 -07:00
|
|
|
handshake(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake in the client role.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
|
|
|
|
|
|
|
The call blocks until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
@code
|
|
|
|
error_code ec;
|
2019-02-08 13:26:55 -08:00
|
|
|
ws.handshake("localhost", "/", ec);
|
2017-07-27 15:40:10 -07:00
|
|
|
@endcode
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-04-25 10:12:43 -07:00
|
|
|
void
|
2017-07-27 15:40:10 -07:00
|
|
|
handshake(
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake in the client role.
|
|
|
|
|
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param res The HTTP Upgrade response returned by the remote
|
2019-02-08 13:26:55 -08:00
|
|
|
endpoint. The caller may use the response to access any
|
|
|
|
additional information sent by the server.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
@code
|
|
|
|
error_code ec;
|
|
|
|
response_type res;
|
2019-02-08 13:26:55 -08:00
|
|
|
ws.handshake(res, "localhost", "/", ec);
|
|
|
|
if(! ec)
|
|
|
|
std::cout << res;
|
2017-07-27 15:40:10 -07:00
|
|
|
@endcode
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
|
|
|
void
|
2017-07-27 15:40:10 -07:00
|
|
|
handshake(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
error_code& ec);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake asynchronously in the client role.
|
|
|
|
|
|
|
|
This initiating function is used to asynchronously begin performing the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. No other operation may be performed
|
|
|
|
on the stream until this operation completes.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
|
|
|
The implementation will not access the string data after the
|
|
|
|
initiating function returns.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
|
|
|
The implementation will not access the string data after the
|
|
|
|
initiating function returns.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-27 15:40:10 -07:00
|
|
|
error_code const& ec // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
);
|
|
|
|
@endcode
|
2017-07-27 15:40:10 -07:00
|
|
|
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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2019-03-10 20:56:40 +01:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@par Example
|
|
|
|
@code
|
|
|
|
ws.async_handshake("localhost", "/",
|
|
|
|
[](error_code ec)
|
|
|
|
{
|
|
|
|
if(ec)
|
|
|
|
std::cerr << "Error: " << ec.message() << "\n";
|
|
|
|
});
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
2017-04-25 10:12:43 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
template<class HandshakeHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
|
2017-07-27 15:40:10 -07:00
|
|
|
async_handshake(
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
HandshakeHandler&& handler);
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake asynchronously in the client role.
|
|
|
|
|
|
|
|
This initiating function is used to asynchronously begin performing the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@li The request is sent and the response is received.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. No other operation may be performed
|
|
|
|
on the stream until this operation completes.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The handshake is successful if the received HTTP response
|
|
|
|
indicates the upgrade was accepted by the server, represented by a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols.
|
2017-04-25 10:12:43 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param res The HTTP Upgrade response returned by the remote
|
2019-02-08 13:26:55 -08:00
|
|
|
endpoint. The caller may use the response to access any
|
|
|
|
additional information sent by the server. This object will
|
|
|
|
be assigned before the completion handler is invoked.
|
|
|
|
|
|
|
|
@param host The name of the remote host. This is required by
|
|
|
|
the HTTP protocol to set the "Host" header field.
|
|
|
|
The implementation will not access the string data after the
|
|
|
|
initiating function returns.
|
|
|
|
|
|
|
|
@param target The request-target, in origin-form. The server may use the
|
|
|
|
target to distinguish different services on the same listening port.
|
|
|
|
The implementation will not access the string data after the
|
|
|
|
initiating function returns.
|
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
|
|
|
error_code const& ec // Result of operation
|
|
|
|
);
|
|
|
|
@endcode
|
2017-07-27 15:40:10 -07:00
|
|
|
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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
|
|
|
|
|
|
|
@par Example
|
|
|
|
@code
|
|
|
|
response_type res;
|
|
|
|
ws.async_handshake(res, "localhost", "/",
|
|
|
|
[&res](error_code ec)
|
|
|
|
{
|
|
|
|
if(ec)
|
|
|
|
std::cerr << "Error: " << ec.message() << "\n";
|
|
|
|
else
|
|
|
|
std::cout << res;
|
|
|
|
|
|
|
|
});
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.1">Websocket Opening Handshake Client Requirements (RFC6455)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.4">Host field (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-3.1.1">request-target (RFC7230)</a>
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc7230#section-5.3.1">origin-form (RFC7230)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
template<class HandshakeHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
|
2017-07-27 15:40:10 -07:00
|
|
|
async_handshake(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
HandshakeHandler&& handler);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Handshaking (Server)
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
2019-02-08 13:26:55 -08:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
/** Perform the WebSocket handshake in the server role.
|
|
|
|
|
|
|
|
This function is used to perform the
|
2019-02-08 13:26:55 -08:00
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
@li The request is received and the response is sent.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
2017-07-27 15:40:10 -07:00
|
|
|
|
|
|
|
@throws system_error Thrown on failure.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
void
|
2019-02-17 16:03:09 -08:00
|
|
|
accept();
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
/** Read and respond to a WebSocket HTTP Upgrade request.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The request is received and the response is sent.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
|
|
|
|
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
void
|
2019-02-17 16:03:09 -08:00
|
|
|
accept(error_code& ec);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
/** Read and respond to a WebSocket HTTP Upgrade request.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The request is received and the response is sent.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
|
|
|
|
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
|
|
|
@param buffers Caller provided data that has already been
|
2017-07-27 15:40:10 -07:00
|
|
|
received on the stream. The implementation will copy the
|
|
|
|
caller provided data before the function returns.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
@throws system_error Thrown on failure.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
template<class ConstBufferSequence>
|
2017-07-20 13:40:34 -07:00
|
|
|
#if BOOST_BEAST_DOXYGEN
|
2017-07-27 15:40:10 -07:00
|
|
|
void
|
|
|
|
#else
|
|
|
|
typename std::enable_if<! http::detail::is_header<
|
|
|
|
ConstBufferSequence>::value>::type
|
2017-05-23 15:50:15 -07:00
|
|
|
#endif
|
2019-02-17 16:03:09 -08:00
|
|
|
accept(ConstBufferSequence const& buffers);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
/** Read and respond to a WebSocket HTTP Upgrade request.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The request is received and the response is sent.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
2017-07-27 15:40:10 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
|
|
|
@param buffers Caller provided data that has already been
|
2017-07-27 15:40:10 -07:00
|
|
|
received on the stream. The implementation will copy the
|
|
|
|
caller provided data before the function returns.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
2019-02-17 16:03:09 -08:00
|
|
|
template<class ConstBufferSequence>
|
2017-07-20 13:40:34 -07:00
|
|
|
#if BOOST_BEAST_DOXYGEN
|
2017-07-27 15:40:10 -07:00
|
|
|
void
|
2017-05-23 15:50:15 -07:00
|
|
|
#else
|
2017-07-27 15:40:10 -07:00
|
|
|
typename std::enable_if<! http::detail::is_header<
|
|
|
|
ConstBufferSequence>::value>::type
|
2017-05-23 15:50:15 -07:00
|
|
|
#endif
|
2019-02-17 16:03:09 -08:00
|
|
|
accept(
|
2017-07-27 15:40:10 -07:00
|
|
|
ConstBufferSequence const& buffers,
|
|
|
|
error_code& ec);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
/** Respond to a WebSocket HTTP Upgrade request
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The response is sent.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
|
|
|
@param req An object containing the HTTP Upgrade request.
|
2017-07-27 15:40:10 -07:00
|
|
|
Ownership is not transferred, the implementation will not
|
|
|
|
access this object from other threads.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@throws system_error Thrown on failure.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
*/
|
2017-07-27 15:40:10 -07:00
|
|
|
template<class Body, class Allocator>
|
|
|
|
void
|
|
|
|
accept(http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
/** Respond to a WebSocket HTTP Upgrade request
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to perform the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
The call blocks until one of the following conditions is true:
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The response is sent.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
@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.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2019-02-17 16:03:09 -08:00
|
|
|
template<class Body, class Allocator>
|
|
|
|
void
|
|
|
|
accept(http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake asynchronously in the server role.
|
|
|
|
|
|
|
|
This initiating function is used to asynchronously begin performing the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
|
|
|
|
|
|
|
This 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 is sent.
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. No other operation may be performed
|
|
|
|
on the stream until this operation completes.
|
|
|
|
|
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
|
|
|
|
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::async_read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-27 15:40:10 -07:00
|
|
|
error_code const& ec // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
);
|
|
|
|
@endcode
|
2017-07-27 15:40:10 -07:00
|
|
|
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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2019-02-17 16:03:09 -08:00
|
|
|
template<class AcceptHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
|
2019-02-17 16:03:09 -08:00
|
|
|
async_accept(AcceptHandler&& handler);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake asynchronously in the server role.
|
|
|
|
|
|
|
|
This initiating function is used to asynchronously begin performing the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
|
|
|
|
|
|
|
This 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 is sent.
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. No other operation may be performed
|
|
|
|
on the stream until this operation completes.
|
|
|
|
|
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
|
|
|
|
|
|
|
If the request size exceeds the capacity of the stream's
|
|
|
|
internal buffer, the error @ref error::buffer_overflow will be
|
|
|
|
indicated. To handle larger requests, an application should
|
|
|
|
read the HTTP request directly using @ref http::async_read and then
|
|
|
|
pass the request to the appropriate overload of @ref accept or
|
|
|
|
@ref async_accept
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@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.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-27 15:40:10 -07:00
|
|
|
error_code const& ec // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
);
|
|
|
|
@endcode
|
2017-07-27 15:40:10 -07:00
|
|
|
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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-08-16 19:25:02 -07:00
|
|
|
template<
|
|
|
|
class ConstBufferSequence,
|
|
|
|
class AcceptHandler>
|
2017-07-27 15:40:10 -07:00
|
|
|
#if BOOST_BEAST_DOXYGEN
|
|
|
|
void_or_deduced
|
|
|
|
#else
|
|
|
|
typename std::enable_if<
|
|
|
|
! http::detail::is_header<ConstBufferSequence>::value,
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)>::type
|
2017-07-27 15:40:10 -07:00
|
|
|
#endif
|
2019-02-17 16:03:09 -08:00
|
|
|
async_accept(
|
2017-08-16 19:25:02 -07:00
|
|
|
ConstBufferSequence const& buffers,
|
|
|
|
AcceptHandler&& handler);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Perform the WebSocket handshake asynchronously in the server role.
|
|
|
|
|
|
|
|
This initiating function is used to asynchronously begin performing the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake">WebSocket handshake</a>,
|
|
|
|
required before messages can be sent and received. During the handshake,
|
|
|
|
the client sends the Websocket Upgrade HTTP request, and the server
|
|
|
|
replies with an HTTP response indicating the result of the handshake.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The request is received and the response is sent.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. No other operation may be performed
|
|
|
|
on the stream until this operation completes.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
If a valid upgrade request is received, an HTTP response with a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc7230#section-3.1.2">status-code</a>
|
|
|
|
of @ref beast::http::status::switching_protocols is sent to
|
|
|
|
the peer, otherwise a non-successful error is associated with
|
|
|
|
the operation.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-27 15:40:10 -07:00
|
|
|
@param req An object containing the HTTP Upgrade request.
|
|
|
|
Ownership is not transferred, the implementation will not access
|
|
|
|
this object from other threads.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
error_code const& ec // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
);
|
|
|
|
@endcode
|
2017-07-20 08:01:46 -07:00
|
|
|
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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-4.2">Websocket Opening Handshake Server Requirements (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-08-16 19:25:02 -07:00
|
|
|
template<
|
|
|
|
class Body, class Allocator,
|
2017-07-27 15:40:10 -07:00
|
|
|
class AcceptHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
|
2017-08-16 19:25:02 -07:00
|
|
|
async_accept(
|
|
|
|
http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
AcceptHandler&& handler);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2019-02-08 13:26:55 -08:00
|
|
|
// Close Frames
|
2017-07-15 17:05:24 -07:00
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket close control frame.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
|
|
|
|
which begins the websocket closing handshake. The session ends when
|
|
|
|
both ends of the connection have sent and received a close frame.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The close frame is written.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
After beginning the closing handshake, the program should not write
|
|
|
|
further message data, pings, or pongs. Instead, the program should
|
|
|
|
continue reading message data until an error occurs. A read returning
|
|
|
|
@ref error::closed indicates a successful connection closure.
|
|
|
|
|
|
|
|
@param cr The reason for the close.
|
2017-07-20 08:01:46 -07:00
|
|
|
If the close reason specifies a close code other than
|
2016-10-15 21:39:24 -04:00
|
|
|
@ref beast::websocket::close_code::none, the close frame is
|
|
|
|
sent with the close code and optional reason string. Otherwise,
|
|
|
|
the close frame is sent with no payload.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
void
|
2016-04-30 13:00:33 -04:00
|
|
|
close(close_reason const& cr);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket close control frame.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
|
|
|
|
which begins the websocket closing handshake. The session ends when
|
|
|
|
both ends of the connection have sent and received a close frame.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
|
|
|
|
|
|
|
@li The close frame is written.
|
|
|
|
|
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
After beginning the closing handshake, the program should not write
|
|
|
|
further message data, pings, or pongs. Instead, the program should
|
|
|
|
continue reading message data until an error occurs. A read returning
|
|
|
|
@ref error::closed indicates a successful connection closure.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param cr The reason for the close.
|
2017-07-20 08:01:46 -07:00
|
|
|
If the close reason specifies a close code other than
|
2016-10-15 21:39:24 -04:00
|
|
|
@ref beast::websocket::close_code::none, the close frame is
|
|
|
|
sent with the close code and optional reason string. Otherwise,
|
|
|
|
the close frame is sent with no payload.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
2019-02-08 13:26:55 -08:00
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
close(close_reason const& cr, error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket close control frame asynchronously.
|
|
|
|
|
|
|
|
This function is used to asynchronously send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
|
|
|
|
which begins the websocket closing handshake. The session ends when
|
|
|
|
both ends of the connection have sent and received a close frame.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li The close frame finishes sending.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_write_some`
|
|
|
|
function. No other operations except for message reading operations
|
|
|
|
should be initiated on the stream after a close operation is started.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
After beginning the closing handshake, the program should not write
|
|
|
|
further message data, pings, or pongs. Instead, the program should
|
|
|
|
continue reading message data until an error occurs. A read returning
|
|
|
|
@ref error::closed indicates a successful connection closure.
|
|
|
|
|
|
|
|
@param cr The reason for the close.
|
2017-07-20 08:01:46 -07:00
|
|
|
If the close reason specifies a close code other than
|
2016-10-15 21:39:24 -04:00
|
|
|
@ref beast::websocket::close_code::none, the close frame is
|
|
|
|
sent with the close code and optional reason string. Otherwise,
|
|
|
|
the close frame is sent with no payload.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
|
|
|
void handler(
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
error_code const& ec // Result of operation
|
2017-07-20 08:01:46 -07:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
|
|
|
|
|
|
|
@see
|
|
|
|
@li <a href="https://tools.ietf.org/html/rfc6455#section-7.1.2">Websocket Closing Handshake (RFC6455)</a>
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class CloseHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(CloseHandler)
|
2017-07-20 08:01:46 -07:00
|
|
|
async_close(close_reason const& cr, CloseHandler&& handler);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Ping/Pong Frames
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket ping control frame.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
|
|
|
|
which usually elicits an automatic pong control frame response from
|
|
|
|
the peer.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The ping frame is written.
|
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
|
|
|
@param payload The payload of the ping message, which may be empty.
|
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2016-05-15 16:22:25 -04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ping(ping_data const& payload);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket ping control frame.
|
|
|
|
|
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
|
|
|
|
which usually elicits an automatic pong control frame response from
|
|
|
|
the peer.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The ping frame is written.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
|
|
|
@param payload The payload of the ping message, which may be empty.
|
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ping(ping_data const& payload, error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket ping control frame asynchronously.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to asynchronously send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">ping frame</a>,
|
|
|
|
which usually elicits an automatic pong control frame response from
|
|
|
|
the peer.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The ping frame is written.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_write_some`
|
|
|
|
function. The program must ensure that no other calls to @ref ping,
|
|
|
|
@ref pong, @ref async_ping, or @ref async_pong are performed until
|
|
|
|
this operation completes.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2017-02-24 14:53:20 -05:00
|
|
|
If a close frame is sent or received before the ping frame is
|
2019-02-08 13:26:55 -08:00
|
|
|
sent, the error received by this completion handler will be
|
|
|
|
`net::error::operation_aborted`.
|
2017-02-24 14:53:20 -05:00
|
|
|
|
2016-05-15 16:22:25 -04:00
|
|
|
@param payload The payload of the ping message, which may be empty.
|
2019-02-08 13:26:55 -08:00
|
|
|
The implementation will not access the contents of this object after
|
|
|
|
the initiating function returns.
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2016-05-15 16:22:25 -04:00
|
|
|
@code
|
|
|
|
void handler(
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
error_code const& ec // Result of operation
|
2016-05-15 16:22:25 -04:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2016-05-15 16:22:25 -04:00
|
|
|
*/
|
2016-11-03 17:53:32 -04:00
|
|
|
template<class WriteHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(WriteHandler)
|
2016-11-03 17:53:32 -04:00
|
|
|
async_ping(ping_data const& payload, WriteHandler&& handler);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket pong control frame.
|
|
|
|
|
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
|
|
|
|
which is usually sent automatically in response to a ping frame
|
2019-03-30 21:03:06 +04:00
|
|
|
from the remote peer.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The pong frame is written.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
WebSocket allows pong frames to be sent at any time, without first
|
|
|
|
receiving a ping. An unsolicited pong sent in this fashion may
|
|
|
|
indicate to the remote peer that the connection is still active.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
|
|
|
@param payload The payload of the pong message, which may be empty.
|
|
|
|
|
|
|
|
@throws system_error Thrown on failure.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pong(ping_data const& payload);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket pong control frame.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
|
|
|
|
which is usually sent automatically in response to a ping frame
|
2019-03-30 21:03:06 +04:00
|
|
|
from the remote peer.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following conditions is true:
|
|
|
|
|
|
|
|
@li The pong frame is written.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
WebSocket allows pong frames to be sent at any time, without first
|
|
|
|
receiving a ping. An unsolicited pong sent in this fashion may
|
|
|
|
indicate to the remote peer that the connection is still active.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
|
|
|
@param payload The payload of the pong message, which may be empty.
|
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pong(ping_data const& payload, error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Send a websocket pong control frame asynchronously.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to asynchronously send a
|
|
|
|
<a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pong frame</a>,
|
|
|
|
which is usually sent automatically in response to a ping frame
|
2019-03-30 21:03:06 +04:00
|
|
|
from the remote peer.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The pong frame is written.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_write_some`
|
|
|
|
function. The program must ensure that no other calls to @ref ping,
|
|
|
|
@ref pong, @ref async_ping, or @ref async_pong are performed until
|
|
|
|
this operation completes.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2017-02-24 14:53:20 -05:00
|
|
|
If a close frame is sent or received before the pong frame is
|
2019-02-08 13:26:55 -08:00
|
|
|
sent, the error received by this completion handler will be
|
|
|
|
`net::error::operation_aborted`.
|
|
|
|
|
|
|
|
WebSocket allows pong frames to be sent at any time, without first
|
|
|
|
receiving a ping. An unsolicited pong sent in this fashion may
|
|
|
|
indicate to the remote peer that the connection is still active.
|
2017-02-24 14:53:20 -05:00
|
|
|
|
2016-11-03 17:53:32 -04:00
|
|
|
@param payload The payload of the pong message, which may be empty.
|
2019-02-08 13:26:55 -08:00
|
|
|
The implementation will not access the contents of this object after
|
|
|
|
the initiating function returns.
|
2016-11-03 17:53:32 -04:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2016-11-03 17:53:32 -04:00
|
|
|
@code
|
|
|
|
void handler(
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
error_code const& ec // Result of operation
|
2016-11-03 17:53:32 -04:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2016-11-03 17:53:32 -04:00
|
|
|
*/
|
|
|
|
template<class WriteHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(WriteHandler)
|
2016-11-03 17:53:32 -04:00
|
|
|
async_pong(ping_data const& payload, WriteHandler&& handler);
|
2016-05-15 16:22:25 -04:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Reading
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read a complete message.
|
|
|
|
|
|
|
|
This function is used to read a complete message.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-07-25 08:50:58 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
@li A complete message is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 08:50:58 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 08:50:58 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 08:50:58 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 08:50:58 -07:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-25 08:50:58 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer>
|
2017-07-25 08:50:58 -07:00
|
|
|
std::size_t
|
2017-06-08 19:55:42 -07:00
|
|
|
read(DynamicBuffer& buffer);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read a complete message.
|
|
|
|
|
|
|
|
This function is used to read a complete message.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
@li A complete message is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 10:35:16 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-02-06 20:07:03 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer>
|
2017-07-25 08:50:58 -07:00
|
|
|
std::size_t
|
2017-06-08 19:55:42 -07:00
|
|
|
read(DynamicBuffer& buffer, error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read a complete message asynchronously.
|
|
|
|
|
|
|
|
This function is used to asynchronously read a complete message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li A complete message is received.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. The program must ensure that no other
|
|
|
|
calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
|
|
|
|
are performed until this operation completes.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the operation completes, the implementation will read incoming
|
2017-07-25 10:35:16 -07:00
|
|
|
control frames and handle them automatically as follows:
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li If a close frame is received, the WebSocket close procedure is
|
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-02-06 20:07:03 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Pong frames and close frames sent by the implementation while the
|
|
|
|
read operation is outstanding do not prevent the application from
|
|
|
|
also writing message data, sending pings, sending pongs, or sending
|
|
|
|
close frames.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-25 08:50:58 -07:00
|
|
|
error_code const& ec, // Result of operation
|
2017-07-25 10:35:16 -07:00
|
|
|
std::size_t bytes_written // Number of bytes appended to buffer
|
2017-07-20 08:01:46 -07:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer, class ReadHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
|
2017-07-25 08:50:58 -07:00
|
|
|
async_read(
|
|
|
|
DynamicBuffer& buffer,
|
|
|
|
ReadHandler&& handler);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-15 17:05:24 -07:00
|
|
|
//--------------------------------------------------------------------------
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data.
|
|
|
|
|
|
|
|
This function is used to read some message data.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
|
|
|
The function @ref is_message_done may be called to determine if the
|
|
|
|
message received by the last read operation is complete.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-06 20:07:03 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 10:35:16 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
2017-06-08 20:34:27 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-25 10:35:16 -07:00
|
|
|
|
|
|
|
@param limit An upper limit on the number of bytes this function
|
|
|
|
will append into the buffer. If this value is zero, then a reasonable
|
|
|
|
size will be chosen automatically.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer>
|
2017-07-15 17:05:24 -07:00
|
|
|
std::size_t
|
|
|
|
read_some(
|
|
|
|
DynamicBuffer& buffer,
|
|
|
|
std::size_t limit);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data.
|
|
|
|
|
|
|
|
This function is used to read some message data.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-25 10:35:16 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
|
|
|
The function @ref is_message_done may be called to determine if the
|
|
|
|
message received by the last read operation is complete.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 10:35:16 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
2017-02-06 20:07:03 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@param limit An upper limit on the number of bytes this function
|
|
|
|
will append into the buffer. If this value is zero, then a reasonable
|
2017-07-15 17:05:24 -07:00
|
|
|
size will be chosen automatically.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer>
|
2017-07-15 17:05:24 -07:00
|
|
|
std::size_t
|
|
|
|
read_some(
|
|
|
|
DynamicBuffer& buffer,
|
|
|
|
std::size_t limit,
|
|
|
|
error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data asynchronously.
|
|
|
|
|
|
|
|
This function is used to asynchronously read some message data.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. The program must ensure that no other
|
|
|
|
calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
|
|
|
|
are performed until this operation completes.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
2017-07-25 10:35:16 -07:00
|
|
|
to query the stream and determine the type of the last received message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the operation completes, the implementation will read incoming
|
2017-07-25 10:35:16 -07:00
|
|
|
control frames and handle them automatically as follows:
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-02-07 19:11:24 -05:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li If a close frame is received, the WebSocket close procedure is
|
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-02-06 20:07:03 -05:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Pong frames and close frames sent by the implementation while the
|
|
|
|
read operation is outstanding do not prevent the application from
|
|
|
|
also writing message data, sending pings, sending pongs, or sending
|
|
|
|
close frames.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffer A dynamic buffer to append message data to.
|
2017-07-25 10:35:16 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
@param limit An upper limit on the number of bytes this function
|
|
|
|
will append into the buffer. If this value is zero, then a reasonable
|
|
|
|
size will be chosen automatically.
|
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-25 10:35:16 -07:00
|
|
|
error_code const& ec, // Result of operation
|
|
|
|
std::size_t bytes_written // Number of bytes appended to buffer
|
2017-07-20 08:01:46 -07:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2016-05-28 09:23:54 -04:00
|
|
|
template<class DynamicBuffer, class ReadHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
|
2017-07-15 17:05:24 -07:00
|
|
|
async_read_some(
|
|
|
|
DynamicBuffer& buffer,
|
|
|
|
std::size_t limit,
|
|
|
|
ReadHandler&& handler);
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data.
|
|
|
|
|
|
|
|
This function is used to read some message data.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
|
|
|
to query the stream and determine the type of the last received message.
|
|
|
|
The function @ref is_message_done may be called to determine if the
|
|
|
|
message received by the last read operation is complete.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 10:35:16 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
|
|
|
|
|
|
|
@param buffers A buffer sequence to write message data into.
|
|
|
|
The previous contents of the buffers will be overwritten, starting
|
|
|
|
from the beginning.
|
2017-07-25 10:35:16 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-15 17:05:24 -07:00
|
|
|
*/
|
|
|
|
template<class MutableBufferSequence>
|
|
|
|
std::size_t
|
|
|
|
read_some(
|
|
|
|
MutableBufferSequence const& buffers);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data.
|
|
|
|
|
|
|
|
This function is used to read some message data.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `read_some` and `write_some`
|
|
|
|
functions.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
|
|
|
to query the stream and determine the type of the last received message.
|
|
|
|
The function @ref is_message_done may be called to determine if the
|
|
|
|
message received by the last read operation is complete.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the call returns, the implementation will read incoming control
|
|
|
|
frames and handle them automatically as follows:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li If a close frame is received, the WebSocket closing handshake is
|
2017-07-25 10:35:16 -07:00
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of message payload bytes appended to the buffer.
|
|
|
|
|
|
|
|
@param buffers A buffer sequence to write message data into.
|
|
|
|
The previous contents of the buffers will be overwritten, starting
|
|
|
|
from the beginning.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
2017-07-15 17:05:24 -07:00
|
|
|
*/
|
|
|
|
template<class MutableBufferSequence>
|
|
|
|
std::size_t
|
|
|
|
read_some(
|
|
|
|
MutableBufferSequence const& buffers,
|
|
|
|
error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Read some message data asynchronously.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to asynchronously read some message data.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
|
|
|
|
|
|
|
@li Some message data is received.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li A close frame is received. In this case the error indicated by
|
|
|
|
the function will be @ref error::closed.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li An error occurs.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's `async_read_some`
|
|
|
|
and `async_write_some` functions. The program must ensure that no other
|
|
|
|
calls to @ref read, @ref read_some, @ref async_read, or @ref async_read_some
|
|
|
|
are performed until this operation completes.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Received message data is appended to the buffer.
|
2017-07-25 10:35:16 -07:00
|
|
|
The functions @ref got_binary and @ref got_text may be used
|
|
|
|
to query the stream and determine the type of the last received message.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Until the operation completes, the implementation will read incoming
|
2017-07-25 10:35:16 -07:00
|
|
|
control frames and handle them automatically as follows:
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li The @ref control_callback will be invoked for each control frame.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li For each received ping frame, a pong frame will be
|
|
|
|
automatically sent.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2017-07-25 10:35:16 -07:00
|
|
|
@li If a close frame is received, the WebSocket close procedure is
|
|
|
|
performed. In this case, when the function returns, the error
|
|
|
|
@ref error::closed will be indicated.
|
2017-07-15 17:05:24 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
Pong frames and close frames sent by the implementation while the
|
|
|
|
read operation is outstanding do not prevent the application from
|
|
|
|
also writing message data, sending pings, sending pongs, or sending
|
|
|
|
close frames.
|
|
|
|
|
|
|
|
@param buffers A buffer sequence to write message data into.
|
|
|
|
The previous contents of the buffers will be overwritten, starting
|
|
|
|
from the beginning.
|
|
|
|
The implementation will make copies of this object as needed, but
|
|
|
|
but ownership of the underlying memory is not transferred. The
|
|
|
|
caller is responsible for ensuring that the memory locations
|
|
|
|
pointed to by the buffer sequence remain valid until the
|
|
|
|
completion handler is called.
|
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2017-07-15 17:05:24 -07:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-07-25 10:35:16 -07:00
|
|
|
error_code const& ec, // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
std::size_t bytes_written // Number of bytes written to the buffers
|
2017-07-15 17:05:24 -07:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2017-07-15 17:05:24 -07:00
|
|
|
*/
|
|
|
|
template<class MutableBufferSequence, class ReadHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT2(ReadHandler)
|
2017-07-15 17:05:24 -07:00
|
|
|
async_read_some(
|
|
|
|
MutableBufferSequence const& buffers,
|
|
|
|
ReadHandler&& handler);
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Writing
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write a complete message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to write a complete message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following is true:
|
|
|
|
|
|
|
|
@li The message is written.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
The current setting of the @ref binary option controls
|
2016-05-01 12:33:35 -04:00
|
|
|
whether the message opcode is set to text or binary. If the
|
2016-06-10 15:48:39 -04:00
|
|
|
@ref auto_fragment option is set, the message will be split
|
2016-05-01 12:33:35 -04:00
|
|
|
into one or more frames as necessary. The actual payload contents
|
|
|
|
sent may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers The buffers containing the message to send.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of bytes sent from the buffers.
|
2017-09-03 06:18:07 -07:00
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class ConstBufferSequence>
|
2017-09-03 06:18:07 -07:00
|
|
|
std::size_t
|
2016-04-30 13:00:33 -04:00
|
|
|
write(ConstBufferSequence const& buffers);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write a complete message.
|
|
|
|
|
|
|
|
This function is used to write a complete message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The complete message is written.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
The current setting of the @ref binary option controls
|
2016-05-01 12:33:35 -04:00
|
|
|
whether the message opcode is set to text or binary. If the
|
2016-06-10 15:48:39 -04:00
|
|
|
@ref auto_fragment option is set, the message will be split
|
2016-05-01 12:33:35 -04:00
|
|
|
into one or more frames as necessary. The actual payload contents
|
|
|
|
sent may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers The buffers containing the message to send.
|
2017-09-03 06:18:07 -07:00
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of bytes sent from the buffers.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class ConstBufferSequence>
|
2017-09-03 06:18:07 -07:00
|
|
|
std::size_t
|
2017-07-20 08:01:46 -07:00
|
|
|
write(ConstBufferSequence const& buffers, error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write a complete message asynchronously.
|
|
|
|
|
|
|
|
This function is used to asynchronously write a complete message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The complete message is written.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-01 12:33:35 -04:00
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's
|
|
|
|
`async_write_some` function. The program must ensure that no other
|
|
|
|
calls to @ref write, @ref write_some, @ref async_write, or
|
|
|
|
@ref async_write_some are performed until this operation completes.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2017-06-08 18:03:10 -07:00
|
|
|
The current setting of the @ref binary option controls
|
2016-05-01 12:33:35 -04:00
|
|
|
whether the message opcode is set to text or binary. If the
|
2016-06-10 15:48:39 -04:00
|
|
|
@ref auto_fragment option is set, the message will be split
|
2016-05-01 12:33:35 -04:00
|
|
|
into one or more frames as necessary. The actual payload contents
|
|
|
|
sent may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers A buffer sequence containing the entire message
|
2017-07-20 08:01:46 -07:00
|
|
|
payload. The implementation will make copies of this object
|
|
|
|
as needed, but ownership of the underlying memory is not
|
|
|
|
transferred. The caller is responsible for ensuring that
|
|
|
|
the memory locations pointed to by buffers remains valid
|
|
|
|
until the completion handler is called.
|
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2017-07-20 08:01:46 -07:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-09-03 06:18:07 -07:00
|
|
|
error_code const& ec, // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
std::size_t bytes_transferred // Number of bytes sent from the
|
2017-09-03 06:18:07 -07:00
|
|
|
// buffers. If an error occurred,
|
2019-02-08 13:26:55 -08:00
|
|
|
// this will be less than the buffer_size.
|
2017-07-20 08:01:46 -07:00
|
|
|
);
|
|
|
|
@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
|
2019-02-08 13:26:55 -08:00
|
|
|
manner equivalent to using `net::post`.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
2017-09-03 06:18:07 -07:00
|
|
|
template<
|
|
|
|
class ConstBufferSequence,
|
|
|
|
class WriteHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
|
2017-09-03 06:18:07 -07:00
|
|
|
async_write(
|
|
|
|
ConstBufferSequence const& buffers,
|
2017-07-20 08:01:46 -07:00
|
|
|
WriteHandler&& handler);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write some message data.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send part of a message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following is true:
|
2016-06-10 15:48:39 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The message data is written.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
If this is the beginning of a new message, the message opcode
|
2019-02-08 13:26:55 -08:00
|
|
|
will be set to text or binary based on the current setting of
|
|
|
|
the @ref binary (or @ref text) option. The actual payload sent
|
|
|
|
may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-09-03 06:18:07 -07:00
|
|
|
@param fin `true` if this is the last part of the message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers The buffers containing the message part to send.
|
2016-06-10 15:48:39 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of bytes sent from the buffers.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
2016-10-04 18:00:11 -04:00
|
|
|
@throws system_error Thrown on failure.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class ConstBufferSequence>
|
2017-09-03 06:18:07 -07:00
|
|
|
std::size_t
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(bool fin, ConstBufferSequence const& buffers);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write some message data.
|
2016-06-10 15:48:39 -04:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This function is used to send part of a message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The call blocks until one of the following is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The message data is written.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
@li An error occurs.
|
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
The algorithm, known as a <em>composed operation</em>, is implemented
|
2019-02-08 13:26:55 -08:00
|
|
|
in terms of calls to the next layer's `write_some` function.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
If this is the beginning of a new message, the message opcode
|
2019-02-08 13:26:55 -08:00
|
|
|
will be set to text or binary based on the current setting of
|
|
|
|
the @ref binary (or @ref text) option. The actual payload sent
|
|
|
|
may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-09-03 06:18:07 -07:00
|
|
|
@param fin `true` if this is the last part of the message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers The buffers containing the message part to send.
|
2017-09-12 13:49:45 -07:00
|
|
|
|
2019-02-09 05:15:48 -08:00
|
|
|
@param ec Set to indicate what error occurred, if any.
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@return The number of bytes sent from the buffers.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-06-10 15:48:39 -04:00
|
|
|
@return The number of bytes consumed in the input buffers.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class ConstBufferSequence>
|
2017-09-03 06:18:07 -07:00
|
|
|
std::size_t
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(bool fin,
|
2017-07-20 08:01:46 -07:00
|
|
|
ConstBufferSequence const& buffers, error_code& ec);
|
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
/** Write some message data asynchronously.
|
|
|
|
|
|
|
|
This function is used to asynchronously write part of a message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
This call always returns immediately. The asynchronous operation
|
|
|
|
will continue until one of the following conditions is true:
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@li The message data is written.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
@li An error occurs.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
The algorithm, known as a <em>composed asynchronous operation</em>,
|
|
|
|
is implemented in terms of calls to the next layer's
|
|
|
|
`async_write_some` function. The program must ensure that no other
|
|
|
|
calls to @ref write, @ref write_some, @ref async_write, or
|
|
|
|
@ref async_write_some are performed until this operation completes.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
If this is the beginning of a new message, the message opcode
|
2019-02-08 13:26:55 -08:00
|
|
|
will be set to text or binary based on the current setting of
|
|
|
|
the @ref binary (or @ref text) option. The actual payload sent
|
|
|
|
may be transformed as per the WebSocket protocol settings.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2017-09-03 06:18:07 -07:00
|
|
|
@param fin `true` if this is the last part of the message.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-08 13:26:55 -08:00
|
|
|
@param buffers The buffers containing the message part to send.
|
|
|
|
The implementation will make copies of this object
|
|
|
|
as needed, but ownership of the underlying memory is not
|
|
|
|
transferred. The caller is responsible for ensuring that
|
|
|
|
the memory locations pointed to by buffers remains valid
|
|
|
|
until the completion handler is called.
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2019-02-20 18:55:01 -08:00
|
|
|
@param handler The completion handler to invoke when the operation
|
|
|
|
completes. The implementation takes ownership of the handler by
|
|
|
|
performing a decay-copy. The equivalent function signature of
|
|
|
|
the handler must be:
|
2019-02-08 13:26:55 -08:00
|
|
|
@code
|
|
|
|
void handler(
|
2017-09-03 06:18:07 -07:00
|
|
|
error_code const& ec, // Result of operation
|
2019-02-08 13:26:55 -08:00
|
|
|
std::size_t bytes_transferred // Number of bytes sent from the
|
2017-09-03 06:18:07 -07:00
|
|
|
// buffers. If an error occurred,
|
2019-02-08 13:26:55 -08:00
|
|
|
// this will be less than the buffer_size.
|
|
|
|
);
|
|
|
|
@endcode
|
|
|
|
Regardless of whether the asynchronous operation completes
|
|
|
|
immediately or not, the handler will not be invoked from within
|
|
|
|
this function. Invocation of the handler will be performed in a
|
|
|
|
manner equivalent to using `net::post`.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
template<class ConstBufferSequence, class WriteHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT2(WriteHandler)
|
2017-07-15 17:05:24 -07:00
|
|
|
async_write_some(bool fin,
|
2017-07-20 08:01:46 -07:00
|
|
|
ConstBufferSequence const& buffers, WriteHandler&& handler);
|
|
|
|
|
2019-02-17 16:03:09 -08:00
|
|
|
//
|
|
|
|
// Deprecated
|
|
|
|
//
|
|
|
|
|
|
|
|
#if ! BOOST_BEAST_DOXYGEN
|
|
|
|
template<class RequestDecorator>
|
|
|
|
void
|
|
|
|
handshake_ex(
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator);
|
|
|
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
void
|
|
|
|
handshake_ex(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator);
|
|
|
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
void
|
|
|
|
handshake_ex(
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
template<class RequestDecorator>
|
|
|
|
void
|
|
|
|
handshake_ex(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
template<class RequestDecorator, class HandshakeHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
|
2019-02-17 16:03:09 -08:00
|
|
|
async_handshake_ex(
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
HandshakeHandler&& handler);
|
|
|
|
|
|
|
|
template<class RequestDecorator, class HandshakeHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(HandshakeHandler)
|
2019-02-17 16:03:09 -08:00
|
|
|
async_handshake_ex(
|
|
|
|
response_type& res,
|
|
|
|
string_view host,
|
|
|
|
string_view target,
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
HandshakeHandler&& handler);
|
|
|
|
|
|
|
|
template<class ResponseDecorator>
|
|
|
|
void
|
|
|
|
accept_ex(ResponseDecorator const& decorator);
|
|
|
|
|
|
|
|
template<class ResponseDecorator>
|
|
|
|
void
|
|
|
|
accept_ex(
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
template<class ConstBufferSequence,
|
|
|
|
class ResponseDecorator>
|
|
|
|
typename std::enable_if<! http::detail::is_header<
|
|
|
|
ConstBufferSequence>::value>::type
|
|
|
|
accept_ex(
|
|
|
|
ConstBufferSequence const& buffers,
|
|
|
|
ResponseDecorator const& decorator);
|
|
|
|
|
|
|
|
template<class ConstBufferSequence, class ResponseDecorator>
|
|
|
|
typename std::enable_if<! http::detail::is_header<
|
|
|
|
ConstBufferSequence>::value>::type
|
|
|
|
accept_ex(
|
|
|
|
ConstBufferSequence const& buffers,
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
template<class Body, class Allocator,
|
|
|
|
class ResponseDecorator>
|
|
|
|
void
|
|
|
|
accept_ex(http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
ResponseDecorator const& decorator);
|
|
|
|
|
|
|
|
template<class Body, class Allocator,
|
|
|
|
class ResponseDecorator>
|
|
|
|
void
|
|
|
|
accept_ex(http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
error_code& ec);
|
|
|
|
|
|
|
|
template<
|
|
|
|
class ResponseDecorator,
|
|
|
|
class AcceptHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
|
2019-02-17 16:03:09 -08:00
|
|
|
async_accept_ex(
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
AcceptHandler&& handler);
|
|
|
|
|
|
|
|
template<
|
|
|
|
class ConstBufferSequence,
|
|
|
|
class ResponseDecorator,
|
|
|
|
class AcceptHandler>
|
|
|
|
typename std::enable_if<
|
|
|
|
! http::detail::is_header<ConstBufferSequence>::value,
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)>::type
|
2019-02-17 16:03:09 -08:00
|
|
|
async_accept_ex(
|
|
|
|
ConstBufferSequence const& buffers,
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
AcceptHandler&& handler);
|
|
|
|
|
|
|
|
template<
|
|
|
|
class Body, class Allocator,
|
|
|
|
class ResponseDecorator,
|
|
|
|
class AcceptHandler>
|
2019-03-04 23:13:42 -08:00
|
|
|
BOOST_BEAST_ASYNC_RESULT1(AcceptHandler)
|
2019-02-17 16:03:09 -08:00
|
|
|
async_accept_ex(
|
|
|
|
http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
ResponseDecorator const& decorator,
|
|
|
|
AcceptHandler&& handler);
|
|
|
|
#endif
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
private:
|
2017-07-15 17:05:24 -07:00
|
|
|
template<class, class> class accept_op;
|
|
|
|
template<class> class close_op;
|
|
|
|
template<class> class handshake_op;
|
|
|
|
template<class> class ping_op;
|
2019-02-19 17:14:34 -08:00
|
|
|
template<class> class idle_ping_op;
|
2017-07-15 17:05:24 -07:00
|
|
|
template<class, class> class read_some_op;
|
|
|
|
template<class, class> class read_op;
|
|
|
|
template<class> class response_op;
|
|
|
|
template<class, class> class write_some_op;
|
|
|
|
template<class, class> class write_op;
|
2017-07-14 12:11:44 -07:00
|
|
|
|
2019-02-20 20:25:01 -08:00
|
|
|
struct run_accept_op;
|
|
|
|
struct run_close_op;
|
|
|
|
struct run_handshake_op;
|
|
|
|
struct run_ping_op;
|
|
|
|
struct run_idle_ping_op;
|
|
|
|
struct run_read_some_op;
|
|
|
|
struct run_read_op;
|
|
|
|
struct run_response_op;
|
|
|
|
struct run_write_some_op;
|
|
|
|
struct run_write_op;
|
|
|
|
|
2017-07-14 12:11:44 -07:00
|
|
|
static void default_decorate_req(request_type&) {}
|
|
|
|
static void default_decorate_res(response_type&) {}
|
|
|
|
|
2017-11-18 16:52:18 -08:00
|
|
|
//
|
|
|
|
// accept / handshake
|
|
|
|
//
|
|
|
|
|
2019-02-13 08:00:07 -08:00
|
|
|
template<class Buffers, class Decorator>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
void
|
2017-11-18 16:52:18 -08:00
|
|
|
do_accept(
|
2019-02-13 08:00:07 -08:00
|
|
|
Buffers const& buffers,
|
2017-11-18 16:52:18 -08:00
|
|
|
Decorator const& decorator,
|
2017-04-25 10:12:43 -07:00
|
|
|
error_code& ec);
|
|
|
|
|
2017-11-18 16:52:18 -08:00
|
|
|
template<
|
|
|
|
class Body, class Allocator,
|
2017-07-14 13:00:09 -07:00
|
|
|
class Decorator>
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
void
|
2017-11-18 16:52:18 -08:00
|
|
|
do_accept(
|
|
|
|
http::request<Body,
|
|
|
|
http::basic_fields<Allocator>> const& req,
|
|
|
|
Decorator const& decorator,
|
|
|
|
error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
template<class RequestDecorator>
|
|
|
|
void
|
|
|
|
do_handshake(response_type* res_p,
|
2017-07-14 13:00:09 -07:00
|
|
|
string_view host, string_view target,
|
|
|
|
RequestDecorator const& decorator,
|
|
|
|
error_code& ec);
|
Refactor websocket decorators (API Change):
fix #80, #212, fix #303, fix #314, fix #317
websocket::stream now provides the following families of
functions for performing handshakes:
When operating in the server role:
* stream::accept
* stream::accept_ex
* stream::async_accept
* stream::async_accept_ex
When operating in the client role:
* stream::handshake
* stream::handshake_ex
* stream::async_handshake
* stream::async_handshake_ex
Member functions ending with "_ex" allow an additional
RequestDecorator parameter (for the accept family of
functions) or ResponseDecorator parameter (for the
handshake family of functions).
The decorator is called to optionally modify the contents
of the HTTP request or HTTP response object generated by
the implementation, before the message is sent. This
permits callers to set the User-Agent or Server fields,
add or modify HTTP fields related to subprotocols, or
perform any required transformation of the HTTP message
for application-specific needs.
The handshake() family of functions now have an additional
set of overloads accepting a parameter of type response_type&,
allowing the caller to receive the HTTP Response to the
Upgrade handshake. This permits inspection of the response
to handle things like subprotocols, authentication, or
other application-specific needs.
The new implementation does not require any state to be
stored in the stream object. Therefore, websocket::stream
objects are now smaller in size.
The overload of set_option for setting a decorator on the
stream is removed. The only way to set decorators now is
with a suitable overload of accept or handshake.
2017-04-25 09:35:22 -07:00
|
|
|
|
2017-11-18 16:52:18 -08:00
|
|
|
//
|
|
|
|
// fail
|
|
|
|
//
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
void
|
2017-08-02 13:25:53 -07:00
|
|
|
do_fail(
|
2017-08-01 20:15:07 -07:00
|
|
|
std::uint16_t code,
|
2017-08-02 13:25:53 -07:00
|
|
|
error_code ev,
|
|
|
|
error_code& ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
};
|
|
|
|
|
2018-07-05 16:47:07 -07:00
|
|
|
/** Manually provide a one-time seed to initialize the PRNG
|
|
|
|
|
|
|
|
This function invokes the specified seed sequence to produce a seed
|
|
|
|
suitable for use with the pseudo-random number generator used to
|
|
|
|
create masks and perform WebSocket protocol handshakes.
|
|
|
|
|
|
|
|
If a seed is not manually provided, the implementation will
|
|
|
|
perform a one-time seed generation using `std::random_device`. This
|
|
|
|
function may be used when the application runs in an environment
|
|
|
|
where the random device is unreliable or does not provide sufficient
|
|
|
|
entropy.
|
|
|
|
|
|
|
|
@par Preconditions
|
|
|
|
|
|
|
|
This function may not be called after any websocket @ref stream objects
|
|
|
|
have been constructed.
|
|
|
|
|
|
|
|
@param ss A reference to a `std::seed_seq` which will be used to seed
|
|
|
|
the pseudo-random number generator. The seed sequence should have at
|
|
|
|
least 256 bits of entropy.
|
|
|
|
|
|
|
|
@see stream::secure_prng
|
|
|
|
*/
|
2019-02-22 20:08:20 -08:00
|
|
|
inline
|
2018-07-05 16:47:07 -07:00
|
|
|
void
|
|
|
|
seed_prng(std::seed_seq& ss)
|
|
|
|
{
|
2019-01-19 07:23:47 -08:00
|
|
|
detail::prng_seed(&ss);
|
2018-07-05 16:47:07 -07:00
|
|
|
}
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
} // websocket
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|
|
|
|
|
2019-02-17 05:23:40 -08:00
|
|
|
#include <boost/beast/websocket/impl/stream_impl.hpp> // must be first
|
2019-01-19 07:24:00 -08:00
|
|
|
#include <boost/beast/websocket/impl/accept.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/close.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/handshake.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/ping.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/read.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/stream.hpp>
|
|
|
|
#include <boost/beast/websocket/impl/write.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
#endif
|