Skip to content

Commit 42e9d3b

Browse files
plskeggsbjarki-andreasen
authored andcommitted
[nrf noup] net: lib: coap: Make use of ZSOCK_MSG_TRUNC configurable
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]>
1 parent 6742813 commit 42e9d3b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

subsys/net/lib/coap/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ config COAP_CLIENT_MAX_REQUESTS
152152
help
153153
Maximum number of CoAP requests a single client can handle at a time
154154

155+
config COAP_CLIENT_TRUNCATE_MSGS
156+
bool "Truncate blocks larger than the buffer size"
157+
help
158+
Include ZSOCK_MSG_TRUNC in flags passed to zsock_recvfrom()
159+
155160
endif # COAP_CLIENT
156161

157162
config COAP_SERVER

subsys/net/lib/coap/coap_client.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,21 @@ static int recv_response(struct coap_client *client, struct coap_packet *respons
552552
int total_len;
553553
int available_len;
554554
int ret;
555+
int flags = ZSOCK_MSG_DONTWAIT;
556+
557+
if (IS_ENABLED(CONFIG_COAP_CLIENT_TRUNCATE_MSGS)) {
558+
flags |= ZSOCK_MSG_TRUNC;
559+
}
555560

556561
memset(client->recv_buf, 0, sizeof(client->recv_buf));
557562
total_len = receive(client->fd, client->recv_buf, sizeof(client->recv_buf),
558-
ZSOCK_MSG_DONTWAIT | ZSOCK_MSG_TRUNC, &client->address,
559-
&client->socklen);
563+
flags, &client->address, &client->socklen);
560564

561565
if (total_len < 0) {
562566
LOG_ERR("Error reading response: %d", errno);
567+
if (errno == EOPNOTSUPP) {
568+
return -errno;
569+
}
563570
return -EINVAL;
564571
} else if (total_len == 0) {
565572
LOG_ERR("Zero length recv");
@@ -896,6 +903,10 @@ static void coap_client_recv(void *coap_cl, void *a, void *b)
896903
LOG_ERR("Error receiving response");
897904
clients[i]->response_ready = false;
898905
k_mutex_unlock(&clients[i]->lock);
906+
if (ret == -EOPNOTSUPP) {
907+
LOG_ERR("Socket misconfigured.");
908+
goto idle;
909+
}
899910
continue;
900911
}
901912

0 commit comments

Comments
 (0)