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

This is the documentation for a snapshot of the develop branch, built from commit a6871e801d.
PrevUpHomeNext
websocket::stream::async_close

Send a websocket close control frame asynchronously.

Synopsis
template<
    class CloseHandler = net::default_completion_token_t<executor_type>>
DEDUCED
async_close(
    close_reason const& cr,
    CloseHandler&& handler = net::default_completion_token_t< executor_type >{});
Description

This function is used to asynchronously send a close frame, which begins the websocket closing handshake. The session ends when both ends of the connection have sent and received a close frame. This call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

The algorithm, known as a composed asynchronous operation, is implemented in terms of calls to the next layer's async_write_some function. No other operations except for message reading operations should be initiated on the stream after a close operation is started. After beginning the closing handshake, the program should not write further message data, pings, or pongs. Instead, the program should continue reading message data until an error occurs. A read returning error::closed indicates a successful connection closure.

Parameters

Name

Description

cr

The reason for the close. 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.

handler

The completion handler to invoke when the operation completes. The implementation takes ownership of the handler by performing a decay-copy. The equivalent function signature of the handler must be:

void handler(
    error_code const& ec     // Result of operation
);

Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using net::post.

See Also

PrevUpHomeNext