Skip to content

Commit

Permalink
Remove reset of ping timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
muneebahmed10 committed Jun 30, 2021
1 parent 07ac5d3 commit e95fb56
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
11 changes: 2 additions & 9 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,28 +995,21 @@ static MQTTStatus_t handleKeepAlive( MQTTContext_t * pContext )
{
MQTTStatus_t status = MQTTSuccess;
uint32_t now = 0U, keepAliveMs = 0U;
uint32_t pingrespTimeoutMs = MQTT_PINGRESP_TIMEOUT_MS;

assert( pContext != NULL );
assert( pContext->getTime != NULL );

now = pContext->getTime();
keepAliveMs = 1000U * ( uint32_t ) pContext->keepAliveIntervalSec;

/* It is not useful for the ping response timeout to be greater than half
* the keep alive, as the server will have disconnected us by that point. */
if( pingrespTimeoutMs > ( keepAliveMs / 2 ) )
{
pingrespTimeoutMs = keepAliveMs / 2;
}

/* If keep alive interval is 0, it is disabled. */
if( keepAliveMs != 0U )
{
if( pContext->waitingForPingResp == true )
{
/* Has time expired? */
if( calculateElapsedTime( now, pContext->pingReqSendTimeMs ) > pingrespTimeoutMs )
if( calculateElapsedTime( now, pContext->pingReqSendTimeMs ) >
MQTT_PINGRESP_TIMEOUT_MS )
{
status = MQTTKeepAliveTimeout;
}
Expand Down
8 changes: 2 additions & 6 deletions test/unit-test/core_mqtt_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1943,11 +1943,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Happy_Paths( void )
mqttStatus = MQTT_Init( &context, &transport, getTime, eventCallback, &networkBuffer );
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
context.waitingForPingResp = true;

/* Use a large keep alive interval for this test so that the ping response
* timeout will be #MQTT_PINGRESP_TIMEOUT_MS and not keep alive interval / 2.
* We use 4 * ping response timeout, so timeout / 1000 * 4 = timeout / 250. */
context.keepAliveIntervalSec = MQTT_PINGRESP_TIMEOUT_MS / 250;
context.keepAliveIntervalSec = MQTT_SAMPLE_KEEPALIVE_INTERVAL_S;
context.lastPacketTime = MQTT_ONE_SECOND_TO_MS;
context.pingReqSendTimeMs = MQTT_ONE_SECOND_TO_MS;
/* Set expected return values in the loop. All success. */
Expand Down Expand Up @@ -1981,7 +1977,7 @@ void test_MQTT_ProcessLoop_handleKeepAlive_Error_Paths( void )
setupTransportInterface( &transport );

modifyIncomingPacketStatus = MQTTNoDataAvailable;
globalEntryTime = MQTT_ONE_SECOND_TO_MS;
globalEntryTime = MQTT_PINGRESP_TIMEOUT_MS + 1;

/* Coverage for the branch path where PINGRESP timeout interval has expired. */
mqttStatus = MQTT_Init( &context, &transport, getTime, eventCallback, &networkBuffer );
Expand Down

0 comments on commit e95fb56

Please sign in to comment.