Skip to content

Commit

Permalink
net/gcoap: do not allocate RX buf on stack
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Nov 26, 2019
1 parent ffe208a commit 17b1b19
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static gcoap_state_t _coap_state = {
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
static char _msg_stack[GCOAP_STACK_SIZE];
static msg_t _msg_queue[GCOAP_MSG_QUEUE_SIZE];
static uint8_t _listen_buf[GCOAP_PDU_BUF_SIZE];
static sock_udp_t _sock;


Expand Down Expand Up @@ -173,7 +174,6 @@ static void *_event_loop(void *arg)
static void _listen(sock_udp_t *sock)
{
coap_pkt_t pdu;
uint8_t buf[GCOAP_PDU_BUF_SIZE];
sock_udp_ep_t remote;
gcoap_request_memo_t *memo = NULL;
uint8_t open_reqs = gcoap_op_state();
Expand All @@ -183,7 +183,7 @@ static void _listen(sock_udp_t *sock)
* request is outstanding, sock_udp_recv() is called here with limited
* waiting so the request's timeout can be handled in a timely manner in
* _event_loop(). */
ssize_t res = sock_udp_recv(sock, buf, sizeof(buf),
ssize_t res = sock_udp_recv(sock, _listen_buf, sizeof(_listen_buf),
open_reqs > 0 ? GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
&remote);
if (res <= 0) {
Expand All @@ -195,7 +195,7 @@ static void _listen(sock_udp_t *sock)
return;
}

res = coap_parse(&pdu, buf, res);
res = coap_parse(&pdu, _listen_buf, res);
if (res < 0) {
DEBUG("gcoap: parse failure: %d\n", (int)res);
/* If a response, can't clear memo, but it will timeout later. */
Expand All @@ -213,9 +213,11 @@ static void _listen(sock_udp_t *sock)
case COAP_CLASS_REQ:
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);
size_t pdu_len = _handle_req(&pdu, _listen_buf, sizeof(_listen_buf),
&remote);
if (pdu_len > 0) {
ssize_t bytes = sock_udp_send(sock, buf, pdu_len, &remote);
ssize_t bytes = sock_udp_send(sock, _listen_buf, pdu_len,
&remote);
if (bytes <= 0) {
DEBUG("gcoap: send response failed: %d\n", (int)bytes);
}
Expand Down

0 comments on commit 17b1b19

Please sign in to comment.