Skip to content

Commit 6481b0e

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: lib: coap_client: Forward recv() errors to handling loop
Forward recv() errors to handle_poll(), so there is only one place to handle error codes. Signed-off-by: Seppo Takalo <[email protected]>
1 parent 4c6dd4c commit 6481b0e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,17 @@ static int handle_poll(void)
557557
struct coap_packet response;
558558
bool response_truncated = false;
559559

560-
k_mutex_lock(&clients[i]->lock, K_FOREVER);
561-
562560
ret = recv_response(clients[i], &response, &response_truncated);
563561
if (ret < 0) {
562+
if (ret == -EAGAIN) {
563+
continue;
564+
}
564565
LOG_ERR("Error receiving response");
565566
cancel_requests_with(clients[i], -EIO);
566-
k_mutex_unlock(&clients[i]->lock);
567567
continue;
568568
}
569569

570+
k_mutex_lock(&clients[i]->lock, K_FOREVER);
570571
ret = handle_response(clients[i], &response, response_truncated);
571572
if (ret < 0) {
572573
LOG_ERR("Error handling response");
@@ -622,14 +623,11 @@ static int recv_response(struct coap_client *client, struct coap_packet *respons
622623
&client->address, &client->socklen);
623624

624625
if (total_len < 0) {
625-
LOG_ERR("Error reading response: %d", errno);
626-
if (errno == EOPNOTSUPP) {
627-
return -errno;
628-
}
629-
return -EINVAL;
626+
ret = -errno;
627+
return ret;
630628
} else if (total_len == 0) {
631-
LOG_ERR("Zero length recv");
632-
return -EINVAL;
629+
/* Ignore, UDP can be zero length, but it is not CoAP anymore */
630+
return 0;
633631
}
634632

635633
available_len = MIN(total_len, sizeof(client->recv_buf));
@@ -640,7 +638,6 @@ static int recv_response(struct coap_client *client, struct coap_packet *respons
640638
ret = coap_packet_parse(response, client->recv_buf, available_len, NULL, 0);
641639
if (ret < 0) {
642640
LOG_ERR("Invalid data received");
643-
return ret;
644641
}
645642

646643
return ret;

0 commit comments

Comments
 (0)