| Home | Libraries | People | FAQ | More

###### websocket::stream::read_some (4 of 4 overloads)

Read some message data.

###### Synopsis

    template<
        class MutableBufferSequence>
    std::size_t
    read_some(
        MutableBufferSequence const& buffers,
        error_code& ec);

###### Description

This function is used to read some message data.

The call blocks until one of the following is true:

- Some message data 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.

The functions `got_binary` and `got_text` may be used to query the stream and determine the type of the last received message. The function `is_message_done` may be called to determine if the message received by the last read operation is complete.

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
--- | ---
`buffers` | A buffer sequence to write message data into. The previous contents of the buffers will be overwritten, starting from the beginning.
`ec` | Set to indicate what error occurred, if any.

###### Per-Operation Cancellation

This asynchronous operation supports cancellation for the following net::cancellation_type values:

- `net::cancellation_type::terminal`
- `net::cancellation_type::total`

`total`cancellation succeeds if the operation is suspended due to ongoing control operations such as a ping/pong.

`terminal` cancellation succeeds when supported by the underlying stream.

`terminal` cancellation leaves the stream in an undefined state, so that only closing it is guaranteed to succeed.