Hi David,
i'm very sorry, it was a mistake i currently use v0.12, you can check it looking the code on my first post, it is extracted from v0.12
i see that you are one of the author of the wolfMQTT, thank to you for all the effort from you and your team.
Also a MQTT_CODE_ERROR_TIMEOUT is considered a failure
if the timeout is a failure why in the example file (mqttclient.c) the publish of a new message and the ping is under the condition:
if (rc == MQTT_CODE_ERROR_TIMEOUT)
?
mqttclient.c
rc = MqttClient_WaitMessage(&mqttCtx->client,
mqttCtx->cmd_timeout_ms);
...................
/* check return code */
if (rc == MQTT_CODE_CONTINUE) {
return rc;
}
else if (rc == MQTT_CODE_ERROR_TIMEOUT) {
...................
rc = MqttClient_Publish(&mqttCtx->client, &mqttCtx->publish);
...................
rc = MqttClient_Ping(&mqttCtx->client);
...................
}
it send ping or publish only in case of failure? misunderstanding?
is there a reason you aren't returning the MQTT_CODE_CONTINUE return code in non-blocking mode from your NetRead function?
yes
mqtt_socket.c
static int MqttSocket_TlsSocketReceive(WOLFSSL* ssl, char *buf, int sz,
void *ptr)
{
int rc;
MqttClient *client = (MqttClient*)ptr;
(void)ssl; /* Not used */
rc = client->net->read(client->net->context, (byte*)buf, sz,
client->cmd_timeout_ms);
if (rc == 0) {
rc = WOLFSSL_CBIO_ERR_WANT_READ;
}
else if (rc < 0) {
rc = WOLFSSL_CBIO_ERR_GENERAL;
}
return rc;
}
if NetRead return MQTT_CODE_CONTINUE (aka -101) the function MqttSocket_TlsSocketReceive return WOLFSSL_CBIO_ERR_GENERAL and THIS for sure is a failure ERROR
return case on my NetRead implementation:
int NetRead(void *context, byte* buf, int buf_len, int timeout_ms)
case [ nothing to read, continue ]:
return 0
case [ read byte from the incoming buffer ]:
return data_len
case [ network error( ex. socket close, overflow, ecc ]
return MQTT_CODE_ERROR_NETWORK;
case [timeout_ms expired]
return MQTT_CODE_ERROR_TIMEOUT;
if i totally misunderstood the right return case, please can suggest me what is the right one?