Skip to content

Commit

Permalink
[nrf noup] net: lib: coap: Make use of ZSOCK_MSG_TRUNC configurable
Browse files Browse the repository at this point in the history
Not all offloaded network stacks support this socket option.

Go back to previous behavior that it is not used, but allow it
to be enabled using CONFIG_COAP_CLIENT_TRUNCATE_MSGS.

Signed-off-by: Pete Skeggs <[email protected]>
(cherry picked from commit fddbbd1)
  • Loading branch information
plskeggs authored and rlubos committed Oct 24, 2024
1 parent dfae996 commit adcffa8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions subsys/net/lib/coap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ config COAP_CLIENT_MAX_REQUESTS
help
Maximum number of CoAP requests a single client can handle at a time

config COAP_CLIENT_TRUNCATE_MSGS
bool "Truncate blocks larger than the buffer size"
help
Include ZSOCK_MSG_TRUNC in flags passed to zsock_recvfrom()

endif # COAP_CLIENT

config COAP_SERVER
Expand Down
15 changes: 13 additions & 2 deletions subsys/net/lib/coap/coap_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,21 @@ static int recv_response(struct coap_client *client, struct coap_packet *respons
int total_len;
int available_len;
int ret;
int flags = ZSOCK_MSG_DONTWAIT;

if (IS_ENABLED(CONFIG_COAP_CLIENT_TRUNCATE_MSGS)) {
flags |= ZSOCK_MSG_TRUNC;
}

memset(client->recv_buf, 0, sizeof(client->recv_buf));
total_len = receive(client->fd, client->recv_buf, sizeof(client->recv_buf),
ZSOCK_MSG_DONTWAIT | ZSOCK_MSG_TRUNC, &client->address,
&client->socklen);
flags, &client->address, &client->socklen);

if (total_len < 0) {
LOG_ERR("Error reading response: %d", errno);
if (errno == EOPNOTSUPP) {
return -errno;
}
return -EINVAL;
} else if (total_len == 0) {
LOG_ERR("Zero length recv");
Expand Down Expand Up @@ -896,6 +903,10 @@ static void coap_client_recv(void *coap_cl, void *a, void *b)
LOG_ERR("Error receiving response");
clients[i]->response_ready = false;
k_mutex_unlock(&clients[i]->lock);
if (ret == -EOPNOTSUPP) {
LOG_ERR("Socket misconfigured.");
goto idle;
}
continue;
}

Expand Down

0 comments on commit adcffa8

Please sign in to comment.