Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect_async and loop_start order matters when no network connection. #2576

Open
andrewwade opened this issue Jun 22, 2022 · 0 comments
Open

Comments

@andrewwade
Copy link

andrewwade commented Jun 22, 2022

If I start my client like this without a network connection then once the connection is available the client will connect and be happy. The problem is if I call mosquitto_disconnect then reconnect later calling init() again, I don't get a connect callback.

void init() {
    mosquitto_loop_start(mosq);
    mosquitto_connect_async(mosq);
}

If I start my client like this without a network connection then it doesn't automatically connect when the network becomes available:

void init() {
    mosquitto_connect_async(mosq);
    mosquitto_loop_start(mosq);
}

So to auto-connect correctly and still get a callback when called a second time, I have to do this:

void init() {
    mosquitto_loop_start(mosq);
    mosquitto_connect_async(mosq);
    mosquitto_loop_start(mosq);
}

This works in both scenarios for some reason even though the second mosquitto_loop_start returns MOSQ_ERR_INVAL. This doesn't makes sense to me because it looks like the second mosquitto_loop_start shouldn't do anything except return the error.
https://github.com/eclipse/mosquitto/blob/v2.0.14/lib/thread_mosq.c#L42

Mosquitto Version: 2.0.14
OS: Linux Ubuntu 20.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant