diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index c15e46d465..e00c1ccf4a 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -574,7 +574,7 @@ static inline ssize_t gcoap_request(coap_pkt_t *pdu, uint8_t *buf, size_t len, * @param[in] buf Buffer containing the PDU * @param[in] len Length of the buffer * @param[in] remote Destination for the packet - * @param[in] resp_handler Callback when response received + * @param[in] resp_handler Callback when response received, may be NULL * * @return length of the packet * @return 0 if cannot send @@ -592,7 +592,7 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len, * @param[in] len Length of the buffer * @param[in] addr Destination for the packet * @param[in] port Port at the destination - * @param[in] resp_handler Callback when response received + * @param[in] resp_handler Callback when response received, may be NULL * * @return length of the packet * @return 0 if cannot send diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 36a06aace3..168a9de566 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -200,7 +200,9 @@ static void _listen(sock_udp_t *sock) case COAP_TYPE_ACK: xtimer_remove(&memo->response_timer); memo->state = GCOAP_MEMO_RESP; - memo->resp_handler(memo->state, &pdu, &remote); + if (memo->resp_handler) { + memo->resp_handler(memo->state, &pdu, &remote); + } if (memo->send_limit >= 0) { /* if confirmable */ *memo->msg.data.pdu_buf = 0; /* clear resend PDU buffer */ @@ -749,7 +751,6 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len, { gcoap_request_memo_t *memo = NULL; assert(remote != NULL); - assert(resp_handler != NULL); /* Find empty slot in list of open requests. */ mutex_lock(&_coap_state.lock);