Beast Logo

PrevUpHomeNext

bind_handler

Bind parameters to a completion handler, creating a new handler.

Synopsis

Defined in header <beast/core/bind_handler.hpp>

template<
    class Handler,
    class... Args>
implementation-defined
bind_handler(
    Handler&& handler,
    Args&&... args);
Description

This function creates a new handler which, when invoked, calls the original handler with the list of bound arguments. Any parameters passed in the invocation will be subtituted for placeholders present in the list of bound arguments. Parameters which are not matched to placeholders are silently discarded. The passed handler and arguments are forwarded into the returned handler, which provides the same io_service execution guarantees as the original handler.

Unlike boost::asio::io_service::wrap, the returned handler can be used in a subsequent call to boost::asio::io_service::post instead of boost::asio::io_service::dispatch, to ensure that the handler will not be invoked immediately by the calling function.

Example:

template<class AsyncReadStream, class ReadHandler>
void
signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
{
    stream.get_io_service().post(
        bind_handler(std::forward<ReadHandler>(handler),
            boost::asio::error::operation_aborted, 0));
}
Parameters

Name

Description

handler

The handler to wrap.

args

A list of arguments to bind to the handler. The arguments are forwarded into the returned object.

Convenience header <beast/core.hpp>


PrevUpHomeNext