async_mqtt 4.1.0
Loading...
Searching...
No Matches
async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer > Class Template Reference

MQTT endpoint corresponding to the connection. More...

#include <endpoint.hpp>

Inherits std::enable_shared_from_this< basic_endpoint< Role, PacketIdBytes, NextLayer > >.

Public Types

using next_layer_type = NextLayer
 The type given as NextLayer.
 
using strand_type = typename stream_type::strand_type
 The type of stand that is used MQTT stream exclusive control.
 
using packet_variant_type = basic_packet_variant<PacketIdBytes>
 Type of packet_variant.
 
using packet_id_t = typename packet_id_type<PacketIdBytes>::type
 Type of MQTT Packet Identifier.
 

Public Member Functions

strand_type conststrand () const
 strand getter
 
strand_typestrand ()
 strand getter
 
bool in_strand () const
 strand checker
 
next_layer_type constnext_layer () const
 next_layer getter
 
next_layer_typenext_layer ()
 next_layer getter
 
auto constlowest_layer () const
 lowest_layer getter
 
autolowest_layer ()
 lowest_layer getter
 
void set_auto_pub_response (bool val)
 auto publish response setter. Should be called before send()/recv() call.
 
void set_auto_ping_response (bool val)
 auto pingreq response setter. Should be called before send()/recv() call.
 
void set_auto_map_topic_alias_send (bool val)
 auto map (allocate) topic alias on send PUBLISH packet. If all topic aliases are used, then overwrite by LRU algorithm.
This function should be called before send() call.
 
void set_auto_replace_topic_alias_send (bool val)
 auto replace topic with corresponding topic alias on send PUBLISH packet. Registering topic alias need to do manually.
This function should be called before send() call.
 
void set_pingresp_recv_timeout_ms (std::size_t ms)
 Set timeout for receiving PINGRESP packet after PINGREQ packet is sent. If the timer is fired, then the underlying layer is closed from the client side. If the protocol_version is v5, then send DISCONNECT packet with the reason code disconnect_reason_code::keep_alive_timeout automatically before underlying layer is closed.
This function should be called before send() call.
 
template<typename CompletionToken >
auto acquire_unique_packet_id (CompletionToken &&token)
 acuire unique packet_id.
 
template<typename CompletionToken >
auto acquire_unique_packet_id_wait_until (CompletionToken &&token)
 acuire unique packet_id. If packet_id is fully acquired, then wait until released.
 
template<typename CompletionToken >
auto register_packet_id (packet_id_t packet_id, CompletionToken &&token)
 register packet_id.
 
template<typename CompletionToken >
auto release_packet_id (packet_id_t packet_id, CompletionToken &&token)
 release packet_id.
 
template<typename Packet , typename CompletionToken >
auto send (Packet packet, CompletionToken &&token)
 send packet users can call send() before the previous send()'s CompletionToken is invoked
 
template<typename CompletionToken >
auto recv (CompletionToken &&token)
 receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked
 
template<typename CompletionToken >
auto recv (std::set< control_packet_type > types, CompletionToken &&token)
 receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked if packet is not filterd, then next recv() starts automatically. if receive error happenes, then token would be invoked.
 
template<typename CompletionToken >
auto recv (filter fil, std::set< control_packet_type > types, CompletionToken &&token)
 receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked if packet is not filterd, then next recv() starts automatically. if receive error happenes, then token would be invoked. @params fil if match then matched types are targets. if except then not matched types are targets.
 
template<typename CompletionToken >
auto close (CompletionToken &&token)
 close the underlying connection
 
template<typename CompletionToken >
auto restore_packets (std::vector< basic_store_packet_variant< PacketIdBytes > > pvs, CompletionToken &&token)
 restore packets the restored packets would automatically send when CONNACK packet is received
 
template<typename CompletionToken >
auto get_stored_packets (CompletionToken &&token) const
 get stored packets sotred packets mean inflight packets.
 
optional< packet_id_tacquire_unique_packet_id ()
 acuire unique packet_id.
 
bool register_packet_id (packet_id_t pid)
 register packet_id.
 
void release_packet_id (packet_id_t pid)
 release packet_id.
 
std::set< packet_id_tget_qos2_publish_handled_pids () const
 Get processed but not released QoS2 packet ids This function should be called after disconnection.
 
void restore_qos2_publish_handled_pids (std::set< packet_id_t > pids)
 Restore processed but not released QoS2 packet ids This function should be called before receive the first publish.
 
void restore_packets (std::vector< basic_store_packet_variant< PacketIdBytes > > pvs)
 restore packets the restored packets would automatically send when CONNACK packet is received
 
std::vector< basic_store_packet_variant< PacketIdBytes > > get_stored_packets () const
 get stored packets sotred packets mean inflight packets.
 
protocol_version get_protocol_version () const
 get MQTT protocol version
 
bool is_publish_processing (packet_id_t pid) const
 Get MQTT PUBLISH packet processing status.
 
void regulate_for_store (v5::basic_publish_packet< PacketIdBytes > &packet) const
 Regulate publish packet for store If topic is empty, extract topic from topic alias, and remove topic alias Otherwise, remove topic alias if exists.
 

Static Public Member Functions

template<typename... Args>
static std::shared_ptr< this_typecreate (protocol_version ver, Args &&... args)
 create
 

Static Public Attributes

static constexpr std::size_t packet_id_bytes = PacketIdBytes
 The value given as PacketIdBytes.
 

Related Symbols

(Note that these are not member symbols.)

template<role Role, typename NextLayer >
using endpoint = basic_endpoint<Role, 2, NextLayer>
 Type alias of basic_endpoint (PacketIdBytes=2).
 

Detailed Description

template<role Role, std::size_t PacketIdBytes, typename NextLayer>
class async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >

MQTT endpoint corresponding to the connection.

Template Parameters
Rolerole for packet sendable checking
PacketIdBytesMQTT spec is 2. You can use endpoint for that.
NextLayerJust next layer for basic_endpoint. mqtt, mqtts, ws, and wss are predefined.

Member Function Documentation

◆ acquire_unique_packet_id() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
optional< packet_id_t > async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::acquire_unique_packet_id ( )
inline

acuire unique packet_id.

Returns
optional<packet_id_t> if acquired return acquired packet id, otherwise nullopt
Note
This function is SYNC function that must only be called in the strand.

◆ acquire_unique_packet_id() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::acquire_unique_packet_id ( CompletionToken && token)
inline

acuire unique packet_id.

Parameters
tokenthe param is optional<packet_id_t>
Returns
deduced by token

◆ acquire_unique_packet_id_wait_until()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::acquire_unique_packet_id_wait_until ( CompletionToken && token)
inline

acuire unique packet_id. If packet_id is fully acquired, then wait until released.

Parameters
tokenthe param is packet_id_t
Returns
deduced by token

◆ close()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::close ( CompletionToken && token)
inline

close the underlying connection

Parameters
tokenthe param is void
Returns
deduced by token

◆ create()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
template<typename... Args>
static std::shared_ptr< this_type > async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::create ( protocol_version ver,
Args &&... args )
inlinestatic

create

Template Parameters
ArgsTypes for the next layer
Parameters
verMQTT protocol version client can set v5 or v3_1_1, in addition server can set undetermined
argsargs for the next layer. There are predefined next layer types:
protocol::mqtt, protocol::mqtts, protocol::ws, and protocol::wss.
Returns
shared_ptr of basic_endpoint.

◆ get_protocol_version()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
protocol_version async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::get_protocol_version ( ) const
inline

get MQTT protocol version

Returns
MQTT protocol version
Note
This function is SYNC function that must only be called in the strand.

◆ get_qos2_publish_handled_pids()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
std::set< packet_id_t > async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::get_qos2_publish_handled_pids ( ) const
inline

Get processed but not released QoS2 packet ids This function should be called after disconnection.

Returns
set of packet_ids
Note
This function is SYNC function that must only be called in the strand.

◆ get_stored_packets() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
std::vector< basic_store_packet_variant< PacketIdBytes > > async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::get_stored_packets ( ) const
inline

get stored packets sotred packets mean inflight packets.

  • PUBLISH packet (QoS1) not received PUBACK packet
  • PUBLISH packet (QoS1) not received PUBREC packet
  • PUBREL packet not received PUBCOMP packet
    Returns
    std::vector<basic_store_packet_variant<PacketIdBytes>>
    Note
    This function is SYNC function that must only be called in the strand.

◆ get_stored_packets() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::get_stored_packets ( CompletionToken && token) const
inline

get stored packets sotred packets mean inflight packets.

  • PUBLISH packet (QoS1) not received PUBACK packet
  • PUBLISH packet (QoS1) not received PUBREC packet
  • PUBREL packet not received PUBCOMP packet
    Parameters
    tokenthe param is std::vector<basic_store_packet_variant<PacketIdBytes>>
    Returns
    deduced by token

◆ in_strand()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
bool async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::in_strand ( ) const
inline

strand checker

Returns
true if the current context running in the strand, otherwise false

◆ is_publish_processing()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
bool async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::is_publish_processing ( packet_id_t pid) const
inline

Get MQTT PUBLISH packet processing status.

Parameters
pidpacket_id corresponding to the publish packet.
Returns
If the packet is processing, then true, otherwise false.
Note
This function is SYNC function that must only be called in the strand.

◆ lowest_layer() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::lowest_layer ( )
inline

lowest_layer getter

Returns
reference of the lowest_layer

◆ lowest_layer() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto const & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::lowest_layer ( ) const
inline

lowest_layer getter

Returns
const reference of the lowest_layer

◆ next_layer() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
next_layer_type & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::next_layer ( )
inline

next_layer getter

Returns
reference of the next_layer

◆ next_layer() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
next_layer_type const & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::next_layer ( ) const
inline

next_layer getter

Returns
const reference of the next_layer

◆ recv() [1/3]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::recv ( CompletionToken && token)
inline

receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked

Parameters
tokenthe param is packet_variant_type
Returns
deduced by token

◆ recv() [2/3]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::recv ( filter fil,
std::set< control_packet_type > types,
CompletionToken && token )
inline

receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked if packet is not filterd, then next recv() starts automatically. if receive error happenes, then token would be invoked. @params fil if match then matched types are targets. if except then not matched types are targets.

Parameters
typestarget control_packet_types
tokenthe param is packet_variant_type
Returns
deduced by token

◆ recv() [3/3]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::recv ( std::set< control_packet_type > types,
CompletionToken && token )
inline

receive packet users CANNOT call recv() before the previous recv()'s CompletionToken is invoked if packet is not filterd, then next recv() starts automatically. if receive error happenes, then token would be invoked.

Parameters
typestarget control_packet_types
tokenthe param is packet_variant_type
Returns
deduced by token

◆ register_packet_id() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::register_packet_id ( packet_id_t packet_id,
CompletionToken && token )
inline

register packet_id.

Parameters
packet_idpacket_id to register
tokenthe param is bool. If true, success, otherwise the packet_id has already been used.
Returns
deduced by token

◆ register_packet_id() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
bool async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::register_packet_id ( packet_id_t pid)
inline

register packet_id.

Parameters
packet_idpacket_id to register
Returns
If true, success, otherwise the packet_id has already been used.
Note
This function is SYNC function that must only be called in the strand.

◆ regulate_for_store()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::regulate_for_store ( v5::basic_publish_packet< PacketIdBytes > & packet) const
inline

Regulate publish packet for store If topic is empty, extract topic from topic alias, and remove topic alias Otherwise, remove topic alias if exists.

Parameters
packetpacket to regulate
Note
This function is SYNC function that must only be called in the strand.

◆ release_packet_id() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::release_packet_id ( packet_id_t packet_id,
CompletionToken && token )
inline

release packet_id.

Parameters
packet_idpacket_id to release
tokenthe param is void
Returns
deduced by token

◆ release_packet_id() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::release_packet_id ( packet_id_t pid)
inline

release packet_id.

Parameters
packet_idpacket_id to release
Note
This function is SYNC function that must only be called in the strand.

◆ restore_packets() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::restore_packets ( std::vector< basic_store_packet_variant< PacketIdBytes > > pvs)
inline

restore packets the restored packets would automatically send when CONNACK packet is received

Parameters
pvspackets to restore
Note
This function is SYNC function that must only be called in the strand.

◆ restore_packets() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::restore_packets ( std::vector< basic_store_packet_variant< PacketIdBytes > > pvs,
CompletionToken && token )
inline

restore packets the restored packets would automatically send when CONNACK packet is received

Parameters
pvspackets to restore
tokenthe param is void
Returns
deduced by token

◆ restore_qos2_publish_handled_pids()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::restore_qos2_publish_handled_pids ( std::set< packet_id_t > pids)
inline

Restore processed but not released QoS2 packet ids This function should be called before receive the first publish.

Parameters
pidspacket ids
Note
This function is SYNC function that must only be called in the strand.

◆ send()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
auto async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::send ( Packet packet,
CompletionToken && token )
inline

send packet users can call send() before the previous send()'s CompletionToken is invoked

Parameters
packetpacket to send
tokenthe param is system_error
Returns
deduced by token

◆ set_auto_map_topic_alias_send()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::set_auto_map_topic_alias_send ( bool val)
inline

auto map (allocate) topic alias on send PUBLISH packet. If all topic aliases are used, then overwrite by LRU algorithm.
This function should be called before send() call.

Note
By default not automatically mapping.
Parameters
valif true, enable auto mapping, otherwise disable.

◆ set_auto_ping_response()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::set_auto_ping_response ( bool val)
inline

auto pingreq response setter. Should be called before send()/recv() call.

Note
By default not automatically sending.
Parameters
valif true, puback, pubrec, pubrel, and pubcomp are automatically sent

◆ set_auto_pub_response()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::set_auto_pub_response ( bool val)
inline

auto publish response setter. Should be called before send()/recv() call.

Note
By default not automatically sending.
Parameters
valif true, puback, pubrec, pubrel, and pubcomp are automatically sent

◆ set_auto_replace_topic_alias_send()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::set_auto_replace_topic_alias_send ( bool val)
inline

auto replace topic with corresponding topic alias on send PUBLISH packet. Registering topic alias need to do manually.
This function should be called before send() call.

Note
By default not automatically replacing.
Parameters
valif true, enable auto replacing, otherwise disable.

◆ set_pingresp_recv_timeout_ms()

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
void async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::set_pingresp_recv_timeout_ms ( std::size_t ms)
inline

Set timeout for receiving PINGRESP packet after PINGREQ packet is sent. If the timer is fired, then the underlying layer is closed from the client side. If the protocol_version is v5, then send DISCONNECT packet with the reason code disconnect_reason_code::keep_alive_timeout automatically before underlying layer is closed.
This function should be called before send() call.

Note
By default timeout is not set.
Parameters
valif 0, timer is not set, otherwise set val milliseconds.

◆ strand() [1/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
strand_type & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::strand ( )
inline

strand getter

Returns
reference of the strand

◆ strand() [2/2]

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
strand_type const & async_mqtt::basic_endpoint< Role, PacketIdBytes, NextLayer >::strand ( ) const
inline

strand getter

Returns
const reference of the strand

Friends And Related Symbol Documentation

◆ endpoint

template<role Role, std::size_t PacketIdBytes, typename NextLayer >
template<role Role, typename NextLayer >
using endpoint = basic_endpoint<Role, 2, NextLayer>
related

Type alias of basic_endpoint (PacketIdBytes=2).

Template Parameters
Rolerole for packet sendable checking
NextLayerJust next layer for basic_endpoint. mqtt, mqtts, ws, and wss are predefined.

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