From 18910cf4e2c6ca59830165e9b0916e5a19722694 Mon Sep 17 00:00:00 2001 From: Derek Hageman Date: Tue, 20 Aug 2019 17:21:20 -0600 Subject: [PATCH] asymcute: Reset keepalive counter on connection ACK When a keepalive timeout occurs keepalive_retry_cnt remains zero, so when the connection is re-established _on_keepalive_evt will immediately disconnect instead of actually sending a keepalive ping. The sequence looks like: 1. _on_connack: start con->keepalive_timer 2. Server does not respond to keepalive pings 3. _on_keepalive_evt: con->keepalive_retry_cnt reaches zero 4. Connection torn down and ASYMCUTE_DISCONNECTED sent to application 5. Application starts reconnection 6. _on_connack: start con->keepalive_timer again 7. First _on_keepalive_evt: con->keepalive_retry_cnt is still zero 8. Repeat from 4. So this simply resets keepalive_retry_cnt in _on_connack when the keepalive timer is restarted. It's a new connection, so resetting the keepalive retry counter make senses regardless. Signed-off-by: Derek Hageman --- sys/net/application_layer/asymcute/asymcute.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/net/application_layer/asymcute/asymcute.c b/sys/net/application_layer/asymcute/asymcute.c index 10dbf2e515..f387ff7d8a 100644 --- a/sys/net/application_layer/asymcute/asymcute.c +++ b/sys/net/application_layer/asymcute/asymcute.c @@ -325,6 +325,7 @@ static void _on_connack(asymcute_con_t *con, const uint8_t *data, size_t len) if (data[2] == MQTTSN_ACCEPTED) { con->state = CONNECTED; /* start keep alive timer */ + con->keepalive_retry_cnt = ASYMCUTE_N_RETRY; event_timeout_set(&con->keepalive_timer, KEEPALIVE_TO); ret = ASYMCUTE_CONNECTED; }