Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

websocket::stream::read (2 of 2 overloads)
PrevUpHomeNext

Read a complete message.

Synopsis
template<
    class DynamicBuffer>
std::size_t
read(
    DynamicBuffer& buffer,
    error_code& ec);
Description

This function is used to read a complete message. The call blocks until one of the following is true:

  • A complete message is received.
  • A close frame is received. In this case the error indicated by the function will be error::closed.
  • An error occurs.

The algorithm, known as a composed operation, is implemented in terms of calls to the next layer's read_some and write_some functions. Received message data is appended to the buffer. The functions got_binary and got_text may be used to query the stream and determine the type of the last received message. Until the call returns, the implementation will read incoming control frames and handle them automatically as follows:

  • The control_callback will be invoked for each control frame.
  • For each received ping frame, a pong frame will be automatically sent.
  • If a close frame is received, the WebSocket closing handshake is performed. In this case, when the function returns, the error error::closed will be indicated.
Return Value

The number of message payload bytes appended to the buffer.

Parameters

Name

Description

buffer

A dynamic buffer to append message data to.

ec

Set to indicate what error occurred, if any.


PrevUpHomeNext