io, net: Pong response may have same timestamp as ping.

Because of time accuracy of COAP_TICKS_PER_SECOND (usually 1000
ticks per second on platform POSIX), the pong response may have
the same timestamp as the ping request. To be reliable, the pong
timestamp must be tracked separately from the general last RX/TX
timestamp.
This commit is contained in:
jcmichelou authored and Olaf Bergmann committed 2018-09-24 15:51:13 +02:00
1 parent 460c7248bb
commit 48d304e7ac
3 files changed
+4 -1

No files matched your search

+1
View File
@@ -77,6 +77,7 @@ typedef struct coap_session_t {
coap_tick_t last_rx_tx;
coap_tick_t last_tx_rst;
coap_tick_t last_ping;
coap_tick_t last_pong;
coap_tick_t csm_tx;
uint8_t *psk_identity;
size_t psk_identity_len;
+1 -1
View File
@@ -1105,7 +1105,7 @@ coap_write(coap_context_t *ctx,
) {
coap_tick_t s_timeout;
if (s->last_rx_tx + ctx->ping_timeout * COAP_TICKS_PER_SECOND <= now) {
if ( (s->last_ping > 0 && s->last_ping == s->last_rx_tx)
if ((s->last_ping > 0 && s->last_pong < s->last_ping)
|| coap_session_send_ping(s) == COAP_INVALID_TID)
{
/* Make sure the session object is not deleted in the callback */
+2
View File
@@ -694,6 +694,7 @@ coap_send_pdu(coap_session_t *session, coap_pdu_t *pdu, coap_queue_t *node) {
return -1;
}
session->last_ping = 0;
session->last_pong = 0;
session->csm_tx = 0;
coap_ticks( &session->last_rx_tx );
if ((session->sock.flags & COAP_SOCKET_WANT_CONNECT) != 0) {
@@ -2095,6 +2096,7 @@ handle_signaling(coap_context_t *context, coap_session_t *session,
coap_send(session, pong);
}
} else if (pdu->code == COAP_SIGNALING_PONG) {
session->last_pong = session->last_rx_tx;
if (context->pong_handler) {
context->pong_handler(context, session, pdu, pdu->tid);
}