Skip to content

Commit 39ad164

Browse files
committed
net: lib: coap: coap_client: improve error handling
In coap_client_resend_handler(), return an error if any resend_request() calls fail for any client. Other than logging it, do not return it as an error in handle_poll(), or else coap_client_recv() might go to idle and exit prematurely before ready responses are processed. Signed-off-by: Pete Skeggs <[email protected]>
1 parent 6ccfcdc commit 39ad164

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,17 @@ static int resend_request(struct coap_client *client,
458458
static int coap_client_resend_handler(void)
459459
{
460460
int ret = 0;
461+
int err;
461462

462463
for (int i = 0; i < num_clients; i++) {
463464
k_mutex_lock(&clients[i]->lock, K_FOREVER);
464465

465466
for (int j = 0; j < CONFIG_COAP_CLIENT_MAX_REQUESTS; j++) {
466467
if (timeout_expired(&clients[i]->requests[j])) {
467-
ret = resend_request(clients[i], &clients[i]->requests[j]);
468+
err = resend_request(clients[i], &clients[i]->requests[j]);
469+
if (err) {
470+
ret = err;
471+
}
468472
}
469473
}
470474

@@ -505,7 +509,8 @@ static int handle_poll(void)
505509
}
506510

507511
if (!has_ongoing_requests()) {
508-
return ret;
512+
/* Resend errors should not be considered poll errors */
513+
return 0;
509514
}
510515

511516
} else {

0 commit comments

Comments
 (0)