Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/gcoap: do not allocate RX buf on stack #12774

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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