| Home | Libraries | People | FAQ | More

###### websocket::stream::accept_ex (6 of 6 overloads)

Respond to a WebSocket HTTP Upgrade request.

Synopsis

    template<
        class Body,
        class Allocator,
        class ResponseDecorator>
    void
    accept_ex(
        http::request< Body, http::basic_fields< Allocator >> const& req,
        ResponseDecorator const& decorator,
        error_code& ec);

Description

This function is used to synchronously send the HTTP response to an HTTP request possibly containing a WebSocket Upgrade. The call blocks until one of the following conditions is true:

- The response finishes sending.
- An error occurs on the stream.

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

If the stream receives a valid HTTP WebSocket Upgrade request, an HTTP response is sent back indicating a successful upgrade. When this call returns, the stream is then ready to send and receive WebSocket protocol frames and messages. If the HTTP Upgrade request is invalid or cannot be satisfied, an HTTP response is sent indicating the reason and status code (typically 400, "Bad Request"). This counts as a failure.

Parameters

Name | Description
--- | ---
`req` | An object containing the HTTP Upgrade request. Ownership is not transferred, the implementation will not access this object from other threads.
`decorator` | A function object which will be called to modify the HTTP response object delivered by the implementation. This could be used to set the Server field, subprotocols, or other application or HTTP specific fields. The object will be called with this equivalent signature:
     void decorator(
        response_type& res
    );
`ec` | Set to indicate what error occurred, if any.