MQTT-C
MQTT-C copied to clipboard
pal inconsistency among implementations
consider the underlying socket is non-blocking.
-
the socket version of mqtt_pal_sendall seems to return MQTT_ERROR_SOCKET_ERROR on any errors, including EAGAIN.
other implementations look similar. except the mbedtls version, which returns the bytes sent in case of EAGAIN-like conditions.
IMO, the behavior of mbedtls version is better because __mqtt_send needs to know who many bytes has been sent successfully. (to update send_offset)
-
the socket version of mqtt_pal_recvall ignores EAGAIN and keeps busy looping. the mbedtls version of it returns the bytes read on EAGAIN-like conditions. IMO, mbedtls behavior is better, to give the caller a chance to perform poll()-wait.
i think the ideal behavior (both fo send and recv) is:
- on an error, if some bytes have been sent/received already, return the number of bytes
- otherwise, if the error is EAGAIN equivalent, return 0. (or something distinguishable, like MQTT_ERROR_SOCKET_AGAIN)
- otherwise, return MQTT_ERROR_SOCKET_ERROR.
Thanks for raising this @yamt. Sorry for my delayed response. I like your suggestion. Are you able to make a PR for this?
i guess i can submit a patch. but the only implementation i can actually test by myself is mbedtls.
mbedtls and unix socket: https://github.com/LiamBindle/MQTT-C/pull/156