net/gcoap: do not allocate RX buf on stack
This commit is contained in:
parent
ffe208a3a4
commit
17b1b19fda
@ -94,6 +94,7 @@ static gcoap_state_t _coap_state = {
|
|||||||
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
|
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
|
||||||
static char _msg_stack[GCOAP_STACK_SIZE];
|
static char _msg_stack[GCOAP_STACK_SIZE];
|
||||||
static msg_t _msg_queue[GCOAP_MSG_QUEUE_SIZE];
|
static msg_t _msg_queue[GCOAP_MSG_QUEUE_SIZE];
|
||||||
|
static uint8_t _listen_buf[GCOAP_PDU_BUF_SIZE];
|
||||||
static sock_udp_t _sock;
|
static sock_udp_t _sock;
|
||||||
|
|
||||||
|
|
||||||
@ -173,7 +174,6 @@ static void *_event_loop(void *arg)
|
|||||||
static void _listen(sock_udp_t *sock)
|
static void _listen(sock_udp_t *sock)
|
||||||
{
|
{
|
||||||
coap_pkt_t pdu;
|
coap_pkt_t pdu;
|
||||||
uint8_t buf[GCOAP_PDU_BUF_SIZE];
|
|
||||||
sock_udp_ep_t remote;
|
sock_udp_ep_t remote;
|
||||||
gcoap_request_memo_t *memo = NULL;
|
gcoap_request_memo_t *memo = NULL;
|
||||||
uint8_t open_reqs = gcoap_op_state();
|
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
|
* 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
|
* waiting so the request's timeout can be handled in a timely manner in
|
||||||
* _event_loop(). */
|
* _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,
|
open_reqs > 0 ? GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
|
||||||
&remote);
|
&remote);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
@ -195,7 +195,7 @@ static void _listen(sock_udp_t *sock)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = coap_parse(&pdu, buf, res);
|
res = coap_parse(&pdu, _listen_buf, res);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
DEBUG("gcoap: parse failure: %d\n", (int)res);
|
DEBUG("gcoap: parse failure: %d\n", (int)res);
|
||||||
/* If a response, can't clear memo, but it will timeout later. */
|
/* 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:
|
case COAP_CLASS_REQ:
|
||||||
if (coap_get_type(&pdu) == COAP_TYPE_NON
|
if (coap_get_type(&pdu) == COAP_TYPE_NON
|
||||||
|| coap_get_type(&pdu) == COAP_TYPE_CON) {
|
|| 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) {
|
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) {
|
if (bytes <= 0) {
|
||||||
DEBUG("gcoap: send response failed: %d\n", (int)bytes);
|
DEBUG("gcoap: send response failed: %d\n", (int)bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user