Hello,
Paho client is preferred MQTT
client for our future project. But we have an issue with
client connection time, it is more than 100 mS.
We are using C paho client
library.
We know the root cause of the
issue:
While connecting
(MQTTClient_connect method) the client uses MQTTClient_waitfor
method to check if the socket is ready for writing:
MQTTClient.c, line 826
MQTTClient_waitfor(handle,
CONNECT, &rc, millisecsTimeout -
MQTTClient_elapsed(start));
The MQTTClient_waitfor method in
turn executes MQTTClient_cycle with a hard-coded delay:
MQTTClient.c, line 1682:
pack = MQTTClient_cycle(&sock,
100L, rc);
The delay is used as a timeout
parameter for the select method waiting for any socket ready
for reading data:
Socket.c, line 241:
select(s.maxfdp1, &(s.rset),
&pwset, NULL, &timeout)
The problem is that as soon as we
are still connecting there are no any incoming messages so
there is no data to read and the select method gets blocked
for the specified timeout which is 100 mS.
As a result MQTTClient_connect
method runs for more than 100 mS.
I wonder was there an intention to
block the MQTTClient_connect method for 100 mS or that is a
bug? Without the hard-coded timeout the connection time can be
reduced to a 0.5 mS.
If that is a bug, could that be
fixed in one of the next releases?
Thanks you very much.