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 for the latest Boost documentation.
PrevUpHomeNext
websocket::stream::async_handshake_ex (2 of 2 overloads)

Start an asynchronous operation to send an upgrade request and receive the response.

Synopsis
template<
    class RequestDecorator,
    class HandshakeHandler>
DEDUCED
async_handshake_ex(
    response_type& res,
    string_view host,
    string_view target,
    RequestDecorator const& decorator,
    HandshakeHandler&& handler);
Description

This function is used to asynchronously send the HTTP WebSocket upgrade request and receive the HTTP WebSocket Upgrade response. This function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

This operation is implemented in terms of one or more calls to the next layer's async_read_some and async_write_some functions, and is known as a composed operation. The program must ensure that the stream performs no other operations until this operation completes.

The operation is successful if the received HTTP response indicates a successful HTTP Upgrade (represented by a Status-Code of 101, "switching protocols").

Parameters

Name

Description

res

The HTTP Upgrade response returned by the remote endpoint. The caller must ensure this object is valid for at least until the completion handler is invoked.

host

The name of the remote host, required by the HTTP protocol. Copies may be made as needed.

target

The Request Target, which may not be empty, required by the HTTP protocol. Copies of this parameter may be made as needed.

decorator

A function object which will be called to modify the HTTP request object generated by the implementation. This could be used to set the User-Agent field, subprotocols, or other application or HTTP specific fields. The object will be called with this equivalent signature:

 void decorator(
    request_type& req
);

handler

Invoked when the operation completes. The handler may be moved or copied as needed. 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 boost::asio::io_context::post.


PrevUpHomeNext