Beast Logo

PrevUpHomeNext

websocket::stream::async_write

Start an asynchronous operation to write a message to the stream.

template<
    class ConstBufferSequence,
    class WriteHandler>
void-or-deduced
async_write(
    ConstBufferSequence const& buffers,
    WriteHandler&& handler);

This function is used to asynchronously write a message to the stream. The 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_write_some functions, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as stream::async_write, stream::async_write_frame, or stream::async_close).

The current setting of the message_type option controls whether the message opcode is set to text or binary. If the auto_fragment option is set, the message will be split into one or more frames as necessary. The actual payload contents sent may be transformed as per the WebSocket protocol settings.

Parameters

buffers

The buffers containing the entire message payload. The implementation will make copies of this object as needed, but ownership of the underlying memory is not transferred. The caller is responsible for ensuring that the memory locations pointed to by buffers remains valid until the completion handler is called.

handler

The handler to be called when the write operation completes. Copies will be made of the handler as required. The function signature of the handler must be:

void handler(
    error_code const& error     // 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_service::post.


PrevUpHomeNext