Skip to content
Discussion options

You must be logged in to vote

Short answer:

Calling the next async_mqtt::endpoint::async_recv() in the completion handler (e.g. callback) of async_mqtt::endpoint::async_recv() is safe.

Detailed answer:

dispatch() and post() are different.

dispatch() executes the handler immediately if the caller is running in the same executor. Consequently, a recursive dispatch() call can cause a stack overflow. See https://godbolt.org/z/1Thd73EvP

In contrast, post() simply adds the handler to the tail of the executor's internal queue, and the handler is later invoked via ioc.run(), ensuring that the call stack is not increased. See https://godbolt.org/z/8nEcfe1zY


The key question is whether endpoint::async_recv() behaves like dispa…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Radagan
Comment options

@redboltz
Comment options

@Radagan
Comment options

Answer selected by Radagan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants