Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
mqtt::connect_options Class Reference

Holds the set of options that control how the client connects to a server. More...

#include <connect_options.h>

Public Types

using ptr_t = std::shared_ptr< connect_options >
 Smart/shared pointer to an object of this class. More...
 
using const_ptr_t = std::shared_ptr< const connect_options >
 Smart/shared pointer to a const object of this class. More...
 

Public Member Functions

 connect_options ()
 Constructs a new object using the default values.
 
 connect_options (string_ref userName, binary_ref password)
 Constructs a new object using the specified user name and password. More...
 
 connect_options (const connect_options &opt)
 Copy constructor. More...
 
 connect_options (connect_options &&opt)
 Move constructor. More...
 
connect_optionsoperator= (const connect_options &opt)
 Copy assignment. More...
 
connect_optionsoperator= (connect_options &&opt)
 Move assignment. More...
 
std::chrono::seconds get_keep_alive_interval () const
 Gets the "keep alive" interval. More...
 
std::chrono::seconds get_connect_timeout () const
 Gets the connection timeout. More...
 
string get_user_name () const
 Gets the user name to use for the connection. More...
 
binary_ref get_password () const
 Gets the password to use for the connection. More...
 
string get_password_str () const
 Gets the password to use for the connection. More...
 
int get_max_inflight () const
 Gets the maximum number of messages that can be in-flight simultaneously. More...
 
string get_will_topic () const
 Gets the topic to be used for last will and testament (LWT). More...
 
const_message_ptr get_will_message () const
 Gets the message to be sent as last will and testament (LWT). More...
 
const will_optionsget_will_options () const
 Get the LWT options to use for the connection. More...
 
const ssl_optionsget_ssl_options () const
 Get the SSL options to use for the connection. More...
 
void set_ssl (const ssl_options &ssl)
 Sets the SSL for the connection. More...
 
bool is_clean_session () const
 Returns whether the server should remember state for the client across reconnects. More...
 
token_ptr get_token () const
 Gets the token used as the callback context. More...
 
const_string_collection_ptr get_servers () const
 Gets the list of servers to which the client will connect. More...
 
int get_mqtt_version () const
 Gets the version of MQTT to be used on the connect. More...
 
bool get_automatic_reconnect () const
 Determines if the options have been configured for automatic reconnect. More...
 
std::chrono::seconds get_min_retry_interval () const
 Gets the minimum retry interval for automatic reconnect. More...
 
std::chrono::seconds get_max_retry_interval () const
 Gets the maximum retry interval for automatic reconnect. More...
 
void set_clean_session (bool cleanSession)
 Sets whether the server should remember state for the client across reconnects. More...
 
void set_connection_timeout (int timeout)
 Sets the connection timeout value. More...
 
void set_keep_alive_interval (int keepAliveInterval)
 Sets the "keep alive" interval. More...
 
template<class Rep , class Period >
void set_keep_alive_interval (const std::chrono::duration< Rep, Period > &interval)
 Sets the "keep alive" interval with a chrono duration. More...
 
void set_connect_timeout (int to)
 Sets the connect timeout in seconds. More...
 
template<class Rep , class Period >
void set_connect_timeout (const std::chrono::duration< Rep, Period > &to)
 Sets the connect timeout with a chrono duration. More...
 
void set_user_name (string_ref userName)
 Sets the user name to use for the connection. More...
 
void set_password (binary_ref password)
 Sets the password to use for the connection.
 
void set_max_inflight (int n)
 Sets the maximum number of messages that can be in-flight simultaneously. More...
 
void set_will (const will_options &will)
 Sets the "Last Will and Testament" (LWT) for the connection. More...
 
void set_token (const token_ptr &tok)
 Sets the callback context to a delivery token. More...
 
void set_servers (const_string_collection_ptr serverURIs)
 Sets the list of servers to which the client will connect. More...
 
void set_mqtt_version (int mqttVersion)
 Sets the version of MQTT to be used on the connect. More...
 
void set_automatic_reconnect (bool on)
 Enable or disable automatic reconnects. More...
 
void set_automatic_reconnect (int minRetryInterval, int maxRetryInterval)
 Enable or disable automatic reconnects. More...
 
template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void set_automatic_reconnect (const std::chrono::duration< Rep1, Period1 > &minRetryInterval, const std::chrono::duration< Rep2, Period2 > &maxRetryInterval)
 Enable or disable automatic reconnects. More...
 
string to_string () const
 Gets a string representation of the object. More...
 

Friends

class async_client
 The client has special access.
 
class connect_options_test
 
class token_test
 

Detailed Description

Holds the set of options that control how the client connects to a server.

Member Typedef Documentation

using mqtt::connect_options::const_ptr_t = std::shared_ptr<const connect_options>

Smart/shared pointer to a const object of this class.

Smart/shared pointer to an object of this class.

Constructor & Destructor Documentation

mqtt::connect_options::connect_options ( string_ref  userName,
binary_ref  password 
)

Constructs a new object using the specified user name and password.

Parameters
userNameThe name of the user for connecting to the server
passwordThe password for connecting to the server
mqtt::connect_options::connect_options ( const connect_options opt)

Copy constructor.

Parameters
optAnother object to copy.
mqtt::connect_options::connect_options ( connect_options &&  opt)

Move constructor.

Parameters
optAnother object to move into this new one.

Member Function Documentation

bool mqtt::connect_options::get_automatic_reconnect ( ) const
inline

Determines if the options have been configured for automatic reconnect.

Returns
true if configured for automatic reconnect, false if not.
std::chrono::seconds mqtt::connect_options::get_connect_timeout ( ) const
inline

Gets the connection timeout.

This is the amount of time the underlying library will wait for a timeout before failing.

Returns
The connect timeout in seconds.
std::chrono::seconds mqtt::connect_options::get_keep_alive_interval ( ) const
inline

Gets the "keep alive" interval.

Returns
The keep alive interval in seconds.
int mqtt::connect_options::get_max_inflight ( ) const
inline

Gets the maximum number of messages that can be in-flight simultaneously.

Returns
The maximum number of inflight messages.
std::chrono::seconds mqtt::connect_options::get_max_retry_interval ( ) const
inline

Gets the maximum retry interval for automatic reconnect.

Returns
The maximum retry interval for automatic reconnect, in seconds.
std::chrono::seconds mqtt::connect_options::get_min_retry_interval ( ) const
inline

Gets the minimum retry interval for automatic reconnect.

Returns
The minimum retry interval for automatic reconnect, in seconds.
int mqtt::connect_options::get_mqtt_version ( ) const
inline

Gets the version of MQTT to be used on the connect.

Returns
  • MQTTVERSION_DEFAULT (0) = default: start with 3.1.1, and if that fails, fall back to 3.1
  • MQTTVERSION_3_1 (3) = only try version 3.1
  • MQTTVERSION_3_1_1 (4) = only try version 3.1.1
binary_ref mqtt::connect_options::get_password ( ) const
inline

Gets the password to use for the connection.

Returns
The password to use for the connection.
string mqtt::connect_options::get_password_str ( ) const
inline

Gets the password to use for the connection.

Returns
The password to use for the connection.
const_string_collection_ptr mqtt::connect_options::get_servers ( ) const
inline

Gets the list of servers to which the client will connect.

Returns
A collection of server URI's. Each entry should be of the form protocol://host:port where protocol must be tcp or ssl. For host, you can specify either an IP address or a domain name.
const ssl_options& mqtt::connect_options::get_ssl_options ( ) const
inline

Get the SSL options to use for the connection.

Returns
The SSL options to use for the connection.
token_ptr mqtt::connect_options::get_token ( ) const
inline

Gets the token used as the callback context.

Returns
The delivery token used as the callback context.
string mqtt::connect_options::get_user_name ( ) const
inline

Gets the user name to use for the connection.

Returns
The user name to use for the connection.
const_message_ptr mqtt::connect_options::get_will_message ( ) const
inline

Gets the message to be sent as last will and testament (LWT).

Returns
The message to be sent as last will and testament (LWT).
const will_options& mqtt::connect_options::get_will_options ( ) const
inline

Get the LWT options to use for the connection.

Returns
The LWT options to use for the connection.
string mqtt::connect_options::get_will_topic ( ) const
inline

Gets the topic to be used for last will and testament (LWT).

Returns
The topic to be used for last will and testament (LWT).
bool mqtt::connect_options::is_clean_session ( ) const
inline

Returns whether the server should remember state for the client across reconnects.

Returns
true if requesting a clean session, false if not.
connect_options& mqtt::connect_options::operator= ( const connect_options opt)

Copy assignment.

Parameters
optAnother object to copy.
connect_options& mqtt::connect_options::operator= ( connect_options &&  opt)

Move assignment.

Parameters
optAnother object to move into this new one.
void mqtt::connect_options::set_automatic_reconnect ( bool  on)
inline

Enable or disable automatic reconnects.

The retry intervals are not affected.

Parameters
onWhether to turn reconnects on or off
void mqtt::connect_options::set_automatic_reconnect ( int  minRetryInterval,
int  maxRetryInterval 
)

Enable or disable automatic reconnects.

Parameters
minRetryIntervalMinimum retry interval in seconds. Doubled on each failed retry.
maxRetryIntervalMaximum retry interval in seconds. The doubling stops here on failed retries.
template<class Rep1 , class Period1 , class Rep2 , class Period2 >
void mqtt::connect_options::set_automatic_reconnect ( const std::chrono::duration< Rep1, Period1 > &  minRetryInterval,
const std::chrono::duration< Rep2, Period2 > &  maxRetryInterval 
)
inline

Enable or disable automatic reconnects.

Parameters
minRetryIntervalMinimum retry interval. Doubled on each failed retry.
maxRetryIntervalMaximum retry interval. The doubling stops here on failed retries.
void mqtt::connect_options::set_clean_session ( bool  cleanSession)
inline

Sets whether the server should remember state for the client across reconnects.

Parameters
cleanSession
void mqtt::connect_options::set_connect_timeout ( int  to)
inline

Sets the connect timeout in seconds.

This is the maximum time that the underlying library will wait for a connection before failing.

Parameters
toThe connect timeout in seconds.
template<class Rep , class Period >
void mqtt::connect_options::set_connect_timeout ( const std::chrono::duration< Rep, Period > &  to)
inline

Sets the connect timeout with a chrono duration.

This is the maximum time that the underlying library will wait for a connection before failing.

Parameters
toThe connect timeout in seconds.
void mqtt::connect_options::set_connection_timeout ( int  timeout)
inline

Sets the connection timeout value.

Parameters
timeout
void mqtt::connect_options::set_keep_alive_interval ( int  keepAliveInterval)
inline

Sets the "keep alive" interval.

This is the maximum time that should pass without communications between client and server. If no massages pass in this time, the client will ping the broker.

Parameters
keepAliveIntervalThe keep alive interval in seconds.
template<class Rep , class Period >
void mqtt::connect_options::set_keep_alive_interval ( const std::chrono::duration< Rep, Period > &  interval)
inline

Sets the "keep alive" interval with a chrono duration.

This is the maximum time that should pass without communications between client and server. If no massages pass in this time, the client will ping the broker.

Parameters
intervalThe keep alive interval.
void mqtt::connect_options::set_max_inflight ( int  n)
inline

Sets the maximum number of messages that can be in-flight simultaneously.

Parameters
nThe maximum number of inflight messages.
void mqtt::connect_options::set_mqtt_version ( int  mqttVersion)
inline

Sets the version of MQTT to be used on the connect.

Parameters
mqttVersionThe MQTT version to use for the connection:
  • MQTTVERSION_DEFAULT (0) = default: start with 3.1.1, and if that fails, fall back to 3.1
  • MQTTVERSION_3_1 (3) = only try version 3.1
  • MQTTVERSION_3_1_1 (4) = only try version 3.1.1
void mqtt::connect_options::set_servers ( const_string_collection_ptr  serverURIs)

Sets the list of servers to which the client will connect.

Parameters
serverURIsA pointer to a collection of server URI's. Each entry should be of the form protocol://host:port where protocol must be tcp or ssl. For host, you can specify either an IP address or a domain name.
void mqtt::connect_options::set_ssl ( const ssl_options ssl)

Sets the SSL for the connection.

These will only have an effect if compiled against the SSL version of the Paho C library.

Parameters
sslThe SSL options.
void mqtt::connect_options::set_token ( const token_ptr &  tok)

Sets the callback context to a delivery token.

Parameters
tokThe delivery token to be used as the callback context.
void mqtt::connect_options::set_user_name ( string_ref  userName)

Sets the user name to use for the connection.

Parameters
userName
void mqtt::connect_options::set_will ( const will_options will)

Sets the "Last Will and Testament" (LWT) for the connection.

Parameters
willThe LWT options.
string mqtt::connect_options::to_string ( ) const

Gets a string representation of the object.

Returns
A string representation of the object.

The documentation for this class was generated from the following file: