Skip to content

Commit 675ac33

Browse files
committed
[nrf fromtree] net: lib: coap_client: Return -errno from send_request()
Return the -errno when zsock_sendto() or zsock_recvfrom() fails, so rest of the code can deal with return values, instead of separately comparing errno and return value. Signed-off-by: Seppo Takalo <[email protected]> (cherry picked from commit 48434a3)
1 parent a8423b2 commit 675ac33

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ static struct coap_client_internal_request *get_request_with_mid(struct coap_cli
3636
static int send_request(int sock, const void *buf, size_t len, int flags,
3737
const struct sockaddr *dest_addr, socklen_t addrlen)
3838
{
39+
int ret;
40+
3941
LOG_HEXDUMP_DBG(buf, len, "Send CoAP Request:");
4042
if (addrlen == 0) {
41-
return zsock_sendto(sock, buf, len, flags, NULL, 0);
43+
ret = zsock_sendto(sock, buf, len, flags, NULL, 0);
4244
} else {
43-
return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
45+
ret = zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
4446
}
47+
48+
return ret >= 0 ? ret : -errno;
4549
}
4650

4751
static int receive(int sock, void *buf, size_t max_len, int flags,
@@ -57,7 +61,7 @@ static int receive(int sock, void *buf, size_t max_len, int flags,
5761
if (err > 0) {
5862
LOG_HEXDUMP_DBG(buf, err, "Receive CoAP Response:");
5963
}
60-
return err;
64+
return err >= 0 ? err : -errno;
6165
}
6266

6367
/** Reset all fields to zero.
@@ -493,13 +497,12 @@ static int resend_request(struct coap_client *client,
493497
client->socklen);
494498
if (ret > 0) {
495499
ret = 0;
496-
} else if (ret == -1 && errno == EAGAIN) {
500+
} else if (ret == -EAGAIN) {
497501
/* Restore the pending structure, retry later */
498502
internal_req->pending = tmp;
499503
/* Not a fatal socket error, will trigger a retry */
500504
ret = 0;
501505
} else {
502-
ret = -errno;
503506
LOG_ERR("Failed to resend request, %d", ret);
504507
}
505508
} else {

0 commit comments

Comments
 (0)