Skip to content

Commit

Permalink
examples/cord_ep: use coap_opt_finish()
Browse files Browse the repository at this point in the history
  • Loading branch information
kb2ma committed Mar 13, 2019
1 parent 682c1e9 commit 34e8804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions examples/cord_ep/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ static ssize_t _handler_dummy(coap_pkt_t *pdu,
int16_t val = 23;

gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
size_t plen = fmt_s16_dec((char *)pdu->payload, val);
return gcoap_finish(pdu, plen, COAP_FORMAT_TEXT);
size_t resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD);
resp_len += fmt_s16_dec((char *)pdu->payload, val);
return resp_len;
}

static ssize_t _handler_info(coap_pkt_t *pdu,
Expand All @@ -66,9 +67,10 @@ static ssize_t _handler_info(coap_pkt_t *pdu,
(void)ctx;

gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
size_t resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD);
size_t slen = sizeof("SOME NODE INFOMRATION");
memcpy(pdu->payload, "SOME NODE INFOMRATION", slen);
return gcoap_finish(pdu, slen, COAP_FORMAT_TEXT);
return resp_len + slen;
}

static const coap_resource_t _resources[] = {
Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/cord/ep/cord_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static int _update_remove(unsigned code, gcoap_resp_handler_t handle)
return CORD_EP_ERR;
}
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
ssize_t pkt_len = gcoap_finish(&pkt, 0, COAP_FORMAT_NONE);
ssize_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);

/* send request */
gcoap_req_send2(buf, pkt_len, &_rd_remote, handle);
Expand Down Expand Up @@ -220,7 +220,7 @@ static int _discover_internal(const sock_udp_ep_t *remote,
}
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
gcoap_add_qstring(&pkt, "rt", "core.rd");
size_t pkt_len = gcoap_finish(&pkt, 0, COAP_FORMAT_NONE);
size_t pkt_len = coap_opt_finish(&pkt, COAP_OPT_FINISH_NONE);
res = gcoap_req_send2(buf, pkt_len, remote, _on_discover);
if (res < 0) {
return CORD_EP_ERR;
Expand Down

0 comments on commit 34e8804

Please sign in to comment.