diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c index 1af2bdc2..a3e9e507 100644 --- a/src/MQTTAsyncUtils.c +++ b/src/MQTTAsyncUtils.c @@ -906,28 +906,27 @@ int MQTTAsync_addCommand(MQTTAsync_queuedCommand* command, int command_size) #if !defined(NO_PERSISTENCE) if (command->client->c->persistence) MQTTAsync_unpersistCommand(first_publish); - #endif +#endif if (first_publish->command.onFailure) { - MQTTAsync_failureData data; + MQTTAsync_failureData data; - data.token = first_publish->command.token; - data.code = MQTTASYNC_MAX_BUFFERED_MESSAGES; - data.message = NULL; - Log(TRACE_MIN, -1, "Cache is full, messages have been removed."); - (*(first_publish->command.onFailure))(first_publish->command.context, &data); - } - else if (first_publish->command.onFailure5) + data.token = first_publish->command.token; + data.code = MQTTASYNC_MAX_BUFFERED_MESSAGES; + data.message = NULL; + Log(TRACE_MIN, -1, "Calling connect failure for client %s, rc %d", command->client->c->clientID, data.code); + (*(first_publish->command.onFailure))(first_publish->command.context, &data); + } else if (first_publish->command.onFailure5) { - MQTTAsync_failureData5 data; + MQTTAsync_failureData5 data; - data.token = first_publish->command.token; - data.code = MQTTASYNC_MAX_BUFFERED_MESSAGES; - data.message = NULL; - data.packet_type = PUBLISH; - Log(TRACE_MIN, -1, "Cache is full, messages have been removed."); - (*(first_publish->command.onFailure5))(first_publish->command.context, &data); - } + data.token = first_publish->command.token; + data.code = MQTTASYNC_MAX_BUFFERED_MESSAGES; + data.message = NULL; + data.packet_type = PUBLISH; + Log(TRACE_MIN, -1, "Calling connect failure for client %s, rc %d", command->client->c->clientID, data.code); + (*(first_publish->command.onFailure5))(first_publish->command.context, &data); + } MQTTAsync_freeCommand(first_publish); } } diff --git a/test/test9.c b/test/test9.c index 3b3a0baa..6a9e39f6 100644 --- a/test/test9.c +++ b/test/test9.c @@ -2501,6 +2501,24 @@ void test10cOnConnect(void* context, MQTTAsync_successData* response) test10cConnected = 1; } +int test10onSendFailureCalled = 0; +int test10onSendSuccessCalled = 0; + +void test10onSendFailure(void* context, MQTTAsync_failureData* response) +{ + MQTTAsync c = (MQTTAsync)context; + + MyLog(LOGA_INFO, "In send onFailure callback for client c rc %s", MQTTAsync_strerror(response->code)); + test10onSendFailureCalled++; +} + +void test10onSendSuccess(void* context, MQTTAsync_successData* response) +{ + MQTTAsync c = (MQTTAsync)context; + + MyLog(LOGA_DEBUG, "In send onSuccess callback for client c"); + test10onSendSuccessCalled++; +} int test10(struct Options options) { @@ -2523,6 +2541,8 @@ int test10(struct Options options) test10Finished = 0; failures = 0; + test10onSendFailureCalled = 0; + test10onSendSuccessCalled = 0; MyLog(LOGA_INFO, "Starting Offline buffering 10 - delete oldest buffered messages first"); fprintf(xml, "