7 years ago.

Client cycle

Hello, when calling Yeld, with socket timed out, the cycle function detects negative values from socket recv as an error and 0 as socket timeout (see code fragment below):

int packet_type = readPacket(timer); read the socket, see what work is due

switch (packet_type) { default: no more data to read, unrecoverable. Or read packet fails due to unexpected network error rc = packet_type; goto exit; case 0: timed out reading packet break;

While the Mbed recv specs says: "By default, recv blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately."

So, in the case of socket time out, the returned value, if the brocker has nothing to send, will be NSAPI_ERROR_WOULD_BLOCK wich is not an error but just an indication of no incoming data. Unfortunatly the readPacket interpret it as an error causing the MQTT client to close the connection. Is this the correct behaviour? Thank you, best regards

Question relating to:

Deprecated This team is no longer maintained, please use: https://github.com/ARMmbed/mbed-mqtt instead.

The MQTT library has been updated in the last week with changes that should address this situation.

posted by Ian Craggs 07 Nov 2017

Hello, thank you for commenting, i already checked the latest Rev 59 https://os.mbed.com/teams/mqtt/code/MQTT/rev/9cff7b6bbd01 it seems it has the same issue.

posted by Licio Mapelli 08 Nov 2017

This is the proposed patch on file MQTTClient.h: @@ -590,7 +590,8 @@ no more data to read, unrecoverable. Or read packet fails due to unexpected network error rc = packet_type; goto exit; - case 0: timed out reading packet + case NSAPI_ERROR_WOULD_BLOCK: + case NSAPI_ERROR_OK: timed out reading packet

posted by Licio Mapelli 08 Nov 2017

All OS specific code goes into the modules below MQTTClient.h. The changes dealing with these error codes are in MQTTSocket.h.

posted by Ian Craggs 24 Nov 2017

MQTTSocket(EthernetInterface *anet) how to pass NetworkInterface * from easy-connect?

posted by Licio Mapelli 27 Nov 2017
Be the first to answer this question.

Assigned to Jan Jongboom 7 years ago.

This means that the question has been accepted and is being worked on.