MQTT-C icon indicating copy to clipboard operation
MQTT-C copied to clipboard

pal inconsistency among implementations

Open yamt opened this issue 3 years ago • 3 comments

consider the underlying socket is non-blocking.

  1. 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)

  2. 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.

yamt avatar Oct 12 '20 02:10 yamt

Thanks for raising this @yamt. Sorry for my delayed response. I like your suggestion. Are you able to make a PR for this?

LiamBindle avatar Nov 07 '20 19:11 LiamBindle

i guess i can submit a patch. but the only implementation i can actually test by myself is mbedtls.

yamt avatar Nov 13 '20 05:11 yamt

mbedtls and unix socket: https://github.com/LiamBindle/MQTT-C/pull/156

yamt avatar Feb 04 '22 04:02 yamt