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

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

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.

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:

  • The Client has attempted to send a DISCONNECT packet, regardless of whether the sending was successful or not.
  • An error occurred. This is indicated by an associated boost::mqtt5::error_code in the handler.
Error codes

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

  • boost::system::errc::errc_t::success
  • boost::asio::error::operation_aborted[footnote This error code can appear if the Client fails to send the DISCONNECT packet to the Server. Regardless, the connection to the Server is terminated, and the Client is cancelled. ]
  • boost::mqtt5::client::error::malformed_packet

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