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 an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
websocket::stream::control_callback (1 of 2 overloads)

Set a callback to be invoked on each incoming control frame.

Synopsis
template<
    class Callback>
void
control_callback(
    Callback& cb);
Description

Sets the callback to be invoked whenever a ping, pong, or close control frame is received during a call to one of the following functions:

Unlike completion handlers, the callback will be invoked for each control frame during a call to any synchronous or asynchronous read function. The operation is passive, with no associated error code, and triggered by reads.

For close frames, the close reason code may be obtained by calling the function websocket::stream::reason.

Parameters

Name

Description

cb

The function object to call, which must be invocable with this equivalent signature:

void
callback(
    frame_type kind,       // The type of frame
    string_view payload    // The payload in the frame
);

The implementation type-erases the callback without requiring a dynamic allocation. For this reason, the callback object is passed by a non-constant reference. If the read operation which receives the control frame is an asynchronous operation, the callback will be invoked using the same method as that used to invoke the final handler.

Remarks

It is not necessary to send a close frame upon receipt of a close frame. The implementation does this automatically. Attempting to send a close frame after a close frame is received will result in undefined behavior.


PrevUpHomeNext