10 #ifndef BOOST_BEAST_WEBSOCKET_STREAM_HPP 11 #define BOOST_BEAST_WEBSOCKET_STREAM_HPP 34 #include <boost/asio/error.hpp> 39 #include <type_traits> 116 template<
class NextLayer>
119 friend class close_test;
120 friend class frame_test;
121 friend class ping_test;
122 friend class read_test;
123 friend class stream_test;
124 friend class write_test;
130 static std::size_t constexpr max_control_frame_size = 2 + 8 + 4 + 125;
131 static std::size_t constexpr tcp_frame_size = 1536;
135 using control_cb_type =
136 std::function<void(frame_type, string_view)>;
141 unsigned char id_ = 0;
144 token(token
const&) =
default;
145 explicit token(
unsigned char id) : id_(id) {}
146 operator bool()
const {
return id_ != 0; }
147 bool operator==(token
const& t) {
return id_ == t.id_; }
148 bool operator!=(token
const& t) {
return id_ != t.id_; }
149 token unique() { token t{id_++};
if(id_ == 0) ++id_;
return t; }
150 void reset() { id_ = 0; }
173 control_cb_type ctrl_cb_;
175 std::size_t rd_msg_max_
177 std::uint64_t rd_size_
179 std::uint64_t rd_remain_
187 +tcp_frame_size> rd_buf_;
218 std::uint8_t[]> wr_buf_;
219 std::size_t wr_buf_size_
221 std::size_t wr_buf_opt_
233 std::unique_ptr<pmd_t> pmd_;
240 typename std::remove_reference<NextLayer>::type;
286 template<
class... Args>
301 boost::asio::io_service&
304 return stream_.get_io_service();
346 return stream_.lowest_layer();
360 return stream_.lowest_layer();
377 return status_ == status::open;
407 return ! got_binary();
442 std::size_t initial_size = +tcp_frame_size)
const;
457 template<
class DynamicBuffer
458 #if ! BOOST_BEAST_DOXYGEN 459 ,
class =
typename std::enable_if<
460 ! std::is_integral<DynamicBuffer>::value>::type
465 DynamicBuffer& buffer)
const;
506 wr_frag_opt_ = value;
590 template<
class Callback>
596 BOOST_STATIC_ASSERT(! std::is_const<Callback>::value);
598 ctrl_cb_ = std::ref(cb);
631 rd_msg_max_ = amount;
670 BOOST_THROW_EXCEPTION(std::invalid_argument{
671 "write buffer size underflow"});
672 wr_buf_opt_ = amount;
867 template<
class RequestDecorator>
872 RequestDecorator
const& decorator);
930 template<
class RequestDecorator>
936 RequestDecorator
const& decorator);
1080 template<
class RequestDecorator>
1085 RequestDecorator
const& decorator,
1143 template<
class RequestDecorator>
1149 RequestDecorator
const& decorator,
1192 template<
class HandshakeHandler>
1193 #if BOOST_BEAST_DOXYGEN 1202 HandshakeHandler&& handler);
1248 template<
class HandshakeHandler>
1249 #if BOOST_BEAST_DOXYGEN 1259 HandshakeHandler&& handler);
1310 template<
class RequestDecorator,
class HandshakeHandler>
1311 #if BOOST_BEAST_DOXYGEN 1320 RequestDecorator
const& decorator,
1321 HandshakeHandler&& handler);
1376 template<
class RequestDecorator,
class HandshakeHandler>
1377 #if BOOST_BEAST_DOXYGEN 1387 RequestDecorator
const& decorator,
1388 HandshakeHandler&& handler);
1470 template<
class ResponseDecorator>
1472 accept_ex(ResponseDecorator
const& decorator);
1548 template<
class ResponseDecorator>
1551 ResponseDecorator
const& decorator,
1589 template<
class ConstBufferSequence>
1590 #if BOOST_BEAST_DOXYGEN 1643 class ResponseDecorator>
1644 #if BOOST_BEAST_DOXYGEN 1652 ResponseDecorator
const& decorator);
1689 template<
class ConstBufferSequence>
1690 #if BOOST_BEAST_DOXYGEN 1744 template<
class ConstBufferSequence,
class ResponseDecorator>
1745 #if BOOST_BEAST_DOXYGEN 1753 ResponseDecorator
const& decorator,
1783 template<
class Body,
class Allocator>
1824 template<
class Body,
class Allocator,
1825 class ResponseDecorator>
1829 ResponseDecorator
const& decorator);
1858 template<
class Body,
class Allocator>
1900 template<
class Body,
class Allocator,
1901 class ResponseDecorator>
1905 ResponseDecorator
const& decorator,
1955 template<
class AcceptHandler>
1956 #if BOOST_BEAST_DOXYGEN 1962 async_accept(AcceptHandler&& handler);
2021 class ResponseDecorator,
2022 class AcceptHandler>
2023 #if BOOST_BEAST_DOXYGEN 2030 ResponseDecorator
const& decorator,
2031 AcceptHandler&& handler);
2089 class AcceptHandler>
2090 #if BOOST_BEAST_DOXYGEN 2093 typename std::enable_if<
2099 AcceptHandler&& handler);
2166 class ResponseDecorator,
2167 class AcceptHandler>
2168 #if BOOST_BEAST_DOXYGEN 2171 typename std::enable_if<
2177 ResponseDecorator
const& decorator,
2178 AcceptHandler&& handler);
2225 class Body,
class Allocator,
2226 class AcceptHandler>
2227 #if BOOST_BEAST_DOXYGEN 2236 AcceptHandler&& handler);
2292 class Body,
class Allocator,
2293 class ResponseDecorator,
2294 class AcceptHandler>
2295 #if BOOST_BEAST_DOXYGEN 2304 ResponseDecorator
const& decorator,
2305 AcceptHandler&& handler);
2414 template<
class CloseHandler>
2415 #if BOOST_BEAST_DOXYGEN 2421 async_close(
close_reason const& cr, CloseHandler&& handler);
2496 template<
class WriteHandler>
2497 #if BOOST_BEAST_DOXYGEN 2503 async_ping(
ping_data const& payload, WriteHandler&& handler);
2593 template<
class WriteHandler>
2594 #if BOOST_BEAST_DOXYGEN 2600 async_pong(
ping_data const& payload, WriteHandler&& handler);
2648 template<
class DynamicBuffer>
2650 read(DynamicBuffer& buffer);
2691 template<
class DynamicBuffer>
2756 template<
class DynamicBuffer,
class ReadHandler>
2757 #if BOOST_BEAST_DOXYGEN 2765 DynamicBuffer& buffer,
2766 ReadHandler&& handler);
2816 template<
class DynamicBuffer>
2819 DynamicBuffer& buffer,
2867 template<
class DynamicBuffer>
2870 DynamicBuffer& buffer,
2941 template<
class DynamicBuffer,
class ReadHandler>
2942 #if BOOST_BEAST_DOXYGEN 2949 DynamicBuffer& buffer,
2951 ReadHandler&& handler);
2998 template<
class MutableBufferSequence>
3045 template<
class MutableBufferSequence>
3118 template<
class MutableBufferSequence,
class ReadHandler>
3119 #if BOOST_BEAST_DOXYGEN 3126 ReadHandler&& handler);
3169 template<
class ConstBufferSequence>
3210 template<
class ConstBufferSequence>
3265 #if BOOST_BEAST_DOXYGEN 3274 WriteHandler&& handler);
3306 template<
class ConstBufferSequence>
3340 template<
class ConstBufferSequence>
3389 template<
class ConstBufferSequence,
class WriteHandler>
3390 #if BOOST_BEAST_DOXYGEN 3402 template<
class>
class fail_op;
3404 template<
class>
class ping_op;
3405 template<
class>
class read_fh_op;
3407 template<
class,
class>
class read_op;
3410 template<
class,
class>
class write_op;
3423 if(status_ != status::open)
3425 ec = boost::asio::error::operation_aborted;
3428 ec.assign(0, ec.category());
3444 template<
class DynamicBuffer>
3449 template<
class DynamicBuffer>
3453 template<
class DynamicBuffer>
3455 write_ping(DynamicBuffer& b,
3458 template<
class Decorator>
3463 Decorator
const& decorator);
3465 template<
class Body,
3466 class Allocator,
class Decorator>
3470 Decorator
const& decorator);
3476 template<
class Decorator>
3478 do_accept(Decorator
const& decorator,
3481 template<
class Body,
class Allocator,
3488 template<
class RequestDecorator>
3492 RequestDecorator
const& decorator,
BufferSequence< boost::asio::const_buffer > ConstBufferSequence
Definition: type_traits.hpp:280
StreamHandler WriteHandler
Definition: type_traits.hpp:357
Definition: inflate_stream.hpp:64
StreamHandler ReadHandler
Definition: type_traits.hpp:356
void binary(bool value)
Definition: stream.hpp:536
Definition: async_result.hpp:20
std::size_t write_some(SyncWriteStream &stream, serializer< isRequest, Body, Fields > &sr, error_code &ec)
Definition: write.ipp:468
typename get_lowest_layer< next_layer_type >::type lowest_layer_type
The type of the lowest layer.
Definition: stream.hpp:244
role_type
Definition: role.hpp:46
Definition: type_traits.hpp:25
bool got_text() const
Definition: stream.hpp:405
detail::buffers_helper< ConstBufferSequence > buffers(ConstBufferSequence const &b)
Definition: ostream.hpp:50
The stream is operating as a client.
Definition: option.hpp:36
void write_buffer_size(std::size_t amount)
Definition: stream.hpp:667
Definition: handshake.ipp:38
void read_message_max(std::size_t amount)
Definition: stream.hpp:629
async_return_type< ReadHandler, void(error_code, std::size_t)> async_read_some(AsyncReadStream &stream, DynamicBuffer &buffer, basic_parser< isRequest, Derived > &parser, ReadHandler &&handler)
Definition: read.ipp:546
Definition: deflate_stream.hpp:59
T type
Definition: type_traits.hpp:302
async_return_type< WriteHandler, void(error_code, std::size_t)> async_write(AsyncWriteStream &stream, serializer< isRequest, Body, Fields > &sr, WriteHandler &&handler)
Definition: write.ipp:730
bool auto_fragment() const
Returns true if the automatic fragmentation option is set.
Definition: stream.hpp:511
Definition: utf8_checker.hpp:31
void write(DynamicBuffer &db, frame_header const &fh)
Definition: frame.hpp:185
Both sides performed a WebSocket close.
Definition: rfc6455.hpp:160
next_layer_type const & next_layer() const
Definition: stream.hpp:330
lowest_layer_type & lowest_layer()
Definition: stream.hpp:344
lowest_layer_type const & lowest_layer() const
Definition: stream.hpp:358
boost::system::error_code error_code
The type of error code used by the library.
Definition: error.hpp:21
Definition: static_buffer.hpp:166
bool binary() const
Returns true if the binary message option is set.
Definition: stream.hpp:545
Definition: fields.hpp:53
next_layer_type & next_layer()
Definition: stream.hpp:316
std::size_t read_message_max() const
Returns the maximum incoming message size setting.
Definition: stream.hpp:636
bool is_open() const
Definition: stream.hpp:375
bool got_binary() const
Definition: stream.hpp:390
Definition: pmd_extension.hpp:33
boost::asio::io_service & get_io_service()
Definition: stream.hpp:302
bool is_message_done() const
Returns true if the last completed read finished the current message.
Definition: stream.hpp:412
typename is_header_impl< T >::type is_header
Definition: type_traits.hpp:44
Definition: pausation.hpp:30
void control_callback(Callback &cb)
Definition: stream.hpp:592
close_code
Definition: rfc6455.hpp:67
Definition: stream.hpp:117
void control_callback()
Definition: stream.hpp:606
async_return_type< WriteHandler, void(error_code, std::size_t)> async_write_some(AsyncWriteStream &stream, serializer< isRequest, Body, Fields > &sr, WriteHandler &&handler)
Definition: write.ipp:500
std::size_t read_some(SyncReadStream &stream, DynamicBuffer &buffer, basic_parser< isRequest, Derived > &parser)
Definition: read.ipp:454
frame_type
Definition: stream.hpp:60
async_return_type< ReadHandler, void(error_code, std::size_t)> async_read(AsyncReadStream &stream, DynamicBuffer &buffer, basic_parser< isRequest, Derived > &parser, ReadHandler &&handler)
Definition: read.ipp:715
void text(bool value)
Definition: stream.hpp:702
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
Definition: accept.ipp:38
typename beast::async_result< typename std::decay< CompletionToken >::type, Signature >::return_type async_return_type
Definition: async_result.hpp:204
std::size_t write_buffer_size() const
Returns the size of the write buffer.
Definition: stream.hpp:677
Definition: static_string.hpp:44
close_reason const & reason() const
Definition: stream.hpp:422
opcode
Definition: frame.hpp:79
void get_option(permessage_deflate &o)
Get the permessage-deflate extension options.
Definition: stream.hpp:479
std::conditional< sizeof(void *)==8, std::uint64_t, std::uint32_t >::type prepared_key
Definition: mask.hpp:87
bool operator!=(static_string< N, CharT, Traits > const &lhs, static_string< M, CharT, Traits > const &rhs)
Definition: static_string.hpp:875
typename std::remove_reference< NextLayer >::type next_layer_type
The type of the next layer.
Definition: stream.hpp:240
bool text() const
Returns true if the text message option is set.
Definition: stream.hpp:711
Definition: accept.ipp:144
bool operator==(static_string< N, CharT, Traits > const &lhs, static_string< M, CharT, Traits > const &rhs)
Definition: static_string.hpp:865
void auto_fragment(bool value)
Definition: stream.hpp:504
WebSocket connection failed, protocol violation.
BufferSequence< boost::asio::mutable_buffer > MutableBufferSequence
Definition: type_traits.hpp:282