1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

net/gcoap: do not allocate RX buf on stack

This commit is contained in:
Hauke Petersen 2019-11-21 16:51:27 +01:00
parent ffe208a3a4
commit 17b1b19fda

View File

@ -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;
@ -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();
@ -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) {
@ -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. */
@ -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);
}