Need help understanding libmqtt code

Asked by dpux

Hello,
I am still learning mqtt, and while going through the source code for libmqtt, I am still unable to figure out some basics :

1. I expected mosquitto_connect to make the network connection to the broker - but it is not doing so. The mosquitto_connect_callback_set is getting called only if I call mosquitto_loop. If I am not in a network, I guessed mosquitto_connect would report this back to me immediately, but this is not happening.

2. Due to some issues I wanted mosquitto_loop not to be in an infinite loop. I called mosquitto_loop once and then scheduled it in a timertask after 5 seconds. mosquitto_connect_callback_set is getting called if I call mosquitto_loop "twice". I am wondering what is the correlation with calling it two times...this seems not a random number, I repeated this test for over 50 times.

3. What exactly is the code I should change if I want to know the network failure instantaneously - currently the mosquitto_disconnect_callback_set is not getting called instantaneously (infact it is not even getting called in my case on iOS).

I am trying to make this work on iOS. If someone has already done it, please share your experience. My basic problem is that the mosquitto_loop is continually running, and returning MOSQ_ERR_SUCCESS everytime, even if I go out of network.

Thanks!!

Question information

Language:
English Edit question
Status:
Expired
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

What does mosquitto_connect() return when you have no network?

The design of libmosquitto is that all network read/writes occur in mosquitto_loop(). Until you actually try to read/write it's not possible to tell if the network has dropped, so you won't know until you make the mosquitto_loop() call. It also means that callbacks only get called when you call mosquitto_loop().

The disconnect callback only gets called if you have a successful network connection in the first place. If you're having problems getting connected in the first place then it's no surprise it's not getting called :)

I still can't explain why mosquitto_loop() returns MOSQ_ERR_SUCCESS when you lose your network connection.

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Needs information' state without activity for the last 15 days.