endpoint has boost asio’s strand internally.CompletionToken is called in the endpoint’s strand. Strand is useful to avoid locks and mutexes.
You can get the strand from the endpoint using strand()
function and use it as the executor for Boost.Asio’s async functions like steady_timer
.
It could be annoying calling async APIs from obiously in the strand context. e.g. in the recv() CompletionToken. async_mqtt provides some of sync APIs. Here is the list of sync APIs that can be called only in the strand.
endpoint member function | effects |
---|---|
Acquire the new unique packet_id |
|
Register the packet_id |
|
Release the packet_id |
|
Get already PUBLISH recv CompletionToken is invoked packet_ids |
|
Restore already PUBLISH recv CompletionToken is invoked packet_ids |
|
Restore pacets as stored packets |
|
Get stored packets |
|
Get MQTT protocol version |
acquire_unique_packet_id, register_packet_id, release_packet_id, restore_packets, and get_stored_packets have async version (the same name overload) to call out of strand.