net/gcoap: Add server piggybacked ACK response to a CON request
This commit is contained in:
parent
30be4f7673
commit
19ba56b96f
@ -184,7 +184,8 @@
|
||||
* gcoap includes server and client capability. Available features include:
|
||||
*
|
||||
* - Message Type: Supports non-confirmable (NON) messaging. Additionally
|
||||
* provides a callback on timeout.
|
||||
* provides a callback on timeout. Provides piggybacked ACK response to a
|
||||
* confirmable (CON) request.
|
||||
* - Observe extension: Provides server-side registration and notifications.
|
||||
* - Server and Client provide helper functions for writing the
|
||||
* response/request. See the CoAP topic in the source documentation for
|
||||
|
||||
@ -137,9 +137,16 @@ static void _listen(sock_udp_t *sock)
|
||||
|
||||
/* incoming request */
|
||||
if (coap_get_code_class(&pdu) == COAP_CLASS_REQ) {
|
||||
size_t pdu_len = _handle_req(&pdu, buf, sizeof(buf), &remote);
|
||||
if (pdu_len > 0) {
|
||||
sock_udp_send(sock, buf, pdu_len, &remote);
|
||||
if (coap_get_type(&pdu) == COAP_TYPE_NON
|
||||
|| coap_get_type(&pdu) == COAP_TYPE_CON) {
|
||||
size_t pdu_len = _handle_req(&pdu, buf, sizeof(buf), &remote);
|
||||
if (pdu_len > 0) {
|
||||
sock_udp_send(sock, buf, pdu_len, &remote);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUG("gcoap: illegal request type: %u\n", coap_get_type(&pdu));
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* incoming response */
|
||||
@ -730,9 +737,10 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len,
|
||||
|
||||
int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
|
||||
{
|
||||
/* Assume NON type request, so response type is the same. */
|
||||
if (coap_get_type(pdu) == COAP_TYPE_CON) {
|
||||
coap_hdr_set_type(pdu->hdr, COAP_TYPE_ACK);
|
||||
}
|
||||
coap_hdr_set_code(pdu->hdr, code);
|
||||
/* Create message ID since NON? */
|
||||
|
||||
/* Reserve some space between the header and payload to write options later */
|
||||
pdu->payload = buf + coap_get_total_hdr_len(pdu) + GCOAP_RESP_OPTIONS_BUF;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user