Skip to content

Commit bf532bc

Browse files
committed
Put MQTT 5 reason code into the connect failure reason code field #1596
1 parent 5f3343c commit bf532bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/MQTTAsyncUtils.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,15 @@ static void nextOrClose(MQTTAsyncs* m, int rc, char* message)
17631763
MQTTAsync_failureData5 data = MQTTAsync_failureData5_initializer;
17641764

17651765
data.token = 0;
1766-
data.code = rc;
1766+
if (rc > 0) /* MQTT Reason Codes are > 0; C client return codes are < 0 */
1767+
{
1768+
/* MQTT 5 reason codes >= 0x00 and < 0x80 are successful,
1769+
* but in that case we should not get here but be calling
1770+
* onSuccess instead. */
1771+
data.reasonCode = rc;
1772+
data.code = MQTTASYNC_FAILURE;
1773+
} else
1774+
data.code = rc;
17671775
data.message = message;
17681776
Log(TRACE_MIN, -1, "Calling connect failure for client %s", m->c->clientID);
17691777
(*(m->connect.onFailure5))(m->connect.context, &data);

0 commit comments

Comments
 (0)