| Home | Libraries | People | FAQ | More

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

Read some message data.

<h7> Synopsis </h7>

    template<
        class DynamicBuffer>
    std::size_t
    read_some(
        DynamicBuffer& buffer,
        std::size_t limit);

<h7> Description </h7>

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 `websocket::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 `websocket::stream::got_binary` and `websocket::stream::got_text` may be used to query the stream and determine the type of the last received message. The function `websocket::stream::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 `websocket::stream::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 `websocket::closed` will be indicated.

<h7> Return Value </h7>

The number of message payload bytes appended to the buffer.

<h7> Parameters </h7>

Name | Description
--- | ---
`buffer` | A dynamic buffer to append message data to.
`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.

<h7> Exceptions </h7>

Type | Thrown On
--- | ---
`system_error` | Thrown on failure.