From 1615d4e3b7850556fe99852f5478fb4b23d75a3e Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 20:57:27 +0000 Subject: [PATCH] net.c: Include ping request / pong response handler support If the application needs to see CoAP ping requests or CoAP TCP pong responses then this update provides calling the configured handlers at the appropriate points. --- src/net.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/net.c b/src/net.c index bebbf3a1..3ff47163 100644 --- a/src/net.c +++ b/src/net.c @@ -2010,6 +2010,10 @@ handle_signaling(coap_context_t *context, coap_session_t *session, coap_add_option(pong, COAP_SIGNALING_OPTION_CUSTODY, 0, NULL); coap_send(session, pong); } + } else if (pdu->code == COAP_SIGNALING_PONG) { + if (context->pong_handler) { + context->pong_handler(context, session, pdu, pdu->tid); + } } else if (pdu->code == COAP_SIGNALING_RELEASE || pdu->code == COAP_SIGNALING_ABORT) { coap_session_disconnected(session, COAP_NACK_RST); @@ -2112,6 +2116,12 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, else if (COAP_PDU_IS_RESPONSE(pdu)) handle_response(context, session, sent ? sent->pdu : NULL, pdu); else { + if (COAP_PDU_IS_EMPTY(pdu)) { + if (context->ping_handler) { + context->ping_handler(context, session, + pdu, pdu->tid); + } + } debug("dropped message with invalid code (%d.%02d)\n", COAP_RESPONSE_CLASS(pdu->code), pdu->code & 0x1f);