Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
boost::mqtt5::mqtt_client::async_disconnect (2 of 2 overloads)

Disconnect the Client by sending a DISCONNECT packet with a Reason Code of reason_codes.normal_disconnection. This function has terminal effects.

Synopsis
template<
    typename CompletionToken = typename asio::default_completion_token<boost::mqtt5::mqtt_client::executor_type>::type>
decltype(auto)
async_disconnect(
    CompletionToken&& token = {});
Description

The Client will attempt to send a DISCONNECT packet to the Broker with a Reason Code describing the reason for disconnection. If the DISCONNECT packet is successfully transmitted, or if 5 seconds elapsed without a successful send, the Client will terminate the connection.

This call immediately leaves the mqtt_client object in a stopped, reusable state while the disconnect operation continues on the previous connection. Communication operations initiated after this call complete with boost::asio::error::operation_aborted until async_run is called again. Calling cancel afterwards affects the current state of the mqtt_client; it does not shorten this disconnect operation. To cancel this operation, associate a cancellation slot with its completion token and emit a terminal cancellation signal.

Attention

This function has terminal effects and will close the Client. See mqtt_client::cancel.

Parameters

Name

Description

token

Completion token that will be used to produce a completion handler. The handler will be invoked when the operation completes.

Handler signature

The handler signature for this operation:

void (
    boost::mqtt5::error_code // Result of operation.
)
Completion condition

The asynchronous operation will complete when one of the following conditions is true:

Error codes

The list of all possible error codes that this operation can finish with:

Refer to the section on Error handling to find the underlying causes for each error code.

Per-Operation Cancellation

This asynchronous operation supports cancellation for the following boost::asio::cancellation_type values:


PrevUpHomeNext