| Home | Libraries | People | FAQ | More

###### websocket::stream::close (2 of 2 overloads)

Send a WebSocket close frame.

Synopsis

    void
    close(
        close_reason const& cr,
        error_code& ec);

Description

This function is used to synchronously send a close frame on the stream. The call blocks until one of the following is true:

- The close frame finishes sending.
- An error occurs on the stream.

This function is implemented in terms of one or more calls to the next layer's `write_some` functions.

If the close reason specifies a close code other than 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.

Callers should not attempt to write WebSocket data after initiating the close. Instead, callers should continue reading until an error occurs. A read returning `websocket::closed` indicates a successful connection closure.

Parameters

Name | Description
--- | ---
`cr` | The reason for the close.
`ec` | Set to indicate what error occurred, if any.