Skip to content

Commit

Permalink
update documentation and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-scislowicz committed Jun 1, 2022
1 parent f632e57 commit 1c42a79
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/doxygen/pages.dox
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ In this library, @ref mqtt_processloop_function handles sending of PINGREQs and
The standard does not specify the time duration within which the server has to respond to a ping request, noting only a "reasonable amount of time". If the response to a ping request is not received within @ref MQTT_PINGRESP_TIMEOUT_MS, this library assumes that the connection is dead.

If @ref mqtt_receiveloop_function is used instead of @ref mqtt_processloop_function, then no ping requests are sent. The application must ensure the connection does not remain idle for more than the keep-alive interval by calling @ref mqtt_ping_function to send ping requests.
The timestamp in @ref MQTTContext_t.lastPacketTime indicates when a packet was last sent by the library.
The timestamp in @ref MQTTContext_t.lastPacketTxTime indicates when a packet was last sent by the library.

Sending any ping request sets the @ref MQTTContext_t.waitingForPingResp flag. This flag is cleared by @ref mqtt_processloop_function when a ping response is received. If @ref mqtt_receiveloop_function is used instead, then this flag must be cleared manually by the application's callback.
*/
Expand Down
2 changes: 1 addition & 1 deletion source/include/core_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ MQTTStatus_t MQTT_ProcessLoop( MQTTContext_t * pContext,
* {
* // Since this function does not send pings, the application may need
* // to in order to comply with keep alive.
* if( ( pContext->getTime() - pContext->lastPacketTime ) > keepAliveMs )
* if( ( pContext->getTime() - pContext->lastPacketTxTime ) > keepAliveMs )
* {
* status = MQTT_Ping( pContext );
* }
Expand Down
12 changes: 6 additions & 6 deletions test/unit-test/core_mqtt_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ static void expectProcessLoopCalls( MQTTContext_t * const pContext,
{
if( ( pContext->waitingForPingResp == false ) &&
( pContext->keepAliveIntervalSec != 0U ) &&
( ( globalEntryTime - pContext->lastPacketTime ) > ( 1000U * pContext->keepAliveIntervalSec ) ) )
( ( globalEntryTime - pContext->lastPacketTxTime ) > ( 1000U * pContext->keepAliveIntervalSec ) ) )
{
MQTT_GetPingreqPacketSize_ExpectAnyArgsAndReturn( MQTTSuccess );
/* Replace pointer parameter being passed to the method. */
Expand Down Expand Up @@ -1934,7 +1934,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Happy_Paths( void )
mqttStatus = MQTT_Init( &context, &transport, getTime, eventCallback, &networkBuffer );
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
context.keepAliveIntervalSec = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;
context.lastPacketTime = getTime();
context.lastPacketTxTime = getTime();
/* Set expected return values in the loop. All success. */
resetProcessLoopParams( &expectParams );
expectProcessLoopCalls( &context, &expectParams );
Expand All @@ -1944,7 +1944,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Happy_Paths( void )
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
context.waitingForPingResp = true;
context.keepAliveIntervalSec = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;
context.lastPacketTime = MQTT_ONE_SECOND_TO_MS;
context.lastPacketTxTime = MQTT_ONE_SECOND_TO_MS;
context.pingReqSendTimeMs = MQTT_ONE_SECOND_TO_MS;
/* Set expected return values in the loop. All success. */
resetProcessLoopParams( &expectParams );
Expand All @@ -1955,7 +1955,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Happy_Paths( void )
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
context.waitingForPingResp = false;
context.keepAliveIntervalSec = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;
context.lastPacketTime = 0;
context.lastPacketTxTime = 0;
/* Set expected return values in the loop. All success. */
resetProcessLoopParams( &expectParams );
expectProcessLoopCalls( &context, &expectParams );
Expand Down Expand Up @@ -1983,7 +1983,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Error_Paths( void )
mqttStatus = MQTT_Init( &context, &transport, getTime, eventCallback, &networkBuffer );
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
context.keepAliveIntervalSec = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;
context.lastPacketTime = 0;
context.lastPacketTxTime = 0;
context.pingReqSendTimeMs = 0;
context.waitingForPingResp = true;
/* Set expected return values in the loop. */
Expand Down Expand Up @@ -2391,7 +2391,7 @@ void test_MQTT_Ping_happy_path( void )
mqttStatus = MQTT_Ping( &context );
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );

TEST_ASSERT_EQUAL( context.lastPacketTime, context.pingReqSendTimeMs );
TEST_ASSERT_EQUAL( context.lastPacketTxTime, context.pingReqSendTimeMs );
TEST_ASSERT_TRUE( context.waitingForPingResp );
}

Expand Down

0 comments on commit 1c42a79

Please sign in to comment.