What is max_packets used for when calling mosquitto_loop / mosquitto_loop_read / mosquitto_loop_write

Asked by Yun Wu

Inside mosquitto_loop(), max_packets appears in 3 places:
1) if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL;
2) rc = mosquitto_loop_read(mosq, max_packets);
3) rc = mosquitto_loop_write(mosq, max_packets);

Inside mosquitto_loop_read() and mosquitto_loop_write(), max_packets is firstly checked:
 if(max_packets < 1) return MOSQ_ERR_INVAL;
then replaced with mosq->queue_len.

It seems that value of max_packets is not really used.
So, what is the meaning of existence of max_packets? Why not simply remove it?

It seems that the value of max_packets is never really used.

Question information

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

You're correct that max packets passed to the function is ignored. If
you check the history you'll see that it was originally used to
determine how much effort (i.e. number of packets) the loop call would
attempt to process in a single call. This is now handled automatically
by the library.

Removing the argument would break both API and ABI compatibility. I
would not consider doing this unless there was another reason to break
API/ABI compatibility because it isn't that important. If some other
important breaking changes came along then it would be a good
opportunity to remove max_packets at the same time.

On Wed, Jul 30, 2014 at 5:46 AM, Yun Wu
<email address hidden> wrote:
> New question #252382 on mosquitto:
> https://answers.launchpad.net/mosquitto/+question/252382
>
> Inside mosquitto_loop(), max_packets appears in 3 places:
> 1) if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL;
> 2) rc = mosquitto_loop_read(mosq, max_packets);
> 3) rc = mosquitto_loop_write(mosq, max_packets);
>
> Inside mosquitto_loop_read() and mosquitto_loop_write(), max_packets is firstly checked:
> if(max_packets < 1) return MOSQ_ERR_INVAL;
> then replaced with mosq->queue_len.
>
> It seems that value of max_packets is not really used.
> So, what is the meaning of existence of max_packets? Why not simply remove it?
>
>
>
>
> It seems that the value of max_packets is never really used.
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
Yun Wu (wuyun1984-1984) said :
#2

OK. Just because of compatibility.
Thanks for the answer.

Revision history for this message
Yun Wu (wuyun1984-1984) said :
#3

Thanks Roger Light, that solved my question.