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 (1 of 2 overloads)
PrevUpHomeNext

Disconnect the Client by sending a DISCONNECT packet with a specified Reason Code. 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(
    boost::mqtt5::disconnect_rc_e reason_code,
    const disconnect_props& props,
    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

reason_code

Reason Code to notify the Broker of the reason for the disconnection.

props

An instance of boost::mqtt5::disconnect_props.

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 sent a DISCONNECT packet.
  • 5 seconds have elapsed without a successful send.
  • 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