Skip to content

Commit

Permalink
dtls_writes: Handle write errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jun 21, 2024
1 parent 5fbbd27 commit b1d305c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/coap_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1959,9 +1959,16 @@ coap_dgram_write(gnutls_transport_ptr_t context, const void *send_buffer,
result = c_session->sock.lfunc[COAP_LAYER_TLS].l_write(c_session,
send_buffer, send_buffer_length);
if (result != (int)send_buffer_length) {
int keep_errno = errno;

coap_log_warn("coap_netif_dgrm_write failed (%zd != %zu)\n",
result, send_buffer_length);
result = 0;
errno = keep_errno;
if (result < 0) {
return -1;
} else {
result = 0;
}
}
} else {
result = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/coap_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,16 @@ coap_dgram_write(void *ctx, const unsigned char *send_buffer,
result = (int)c_session->sock.lfunc[COAP_LAYER_TLS].l_write(c_session,
send_buffer, send_buffer_length);
if (result != (ssize_t)send_buffer_length) {
int keep_errno = errno;

coap_log_warn("coap_netif_dgrm_write failed (%zd != %zu)\n",
result, send_buffer_length);
result = 0;
errno = keep_errno;
if (result < 0) {
return -1;
} else {
result = 0;
}
} else if (m_env) {
coap_tick_t now;
coap_ticks(&now);
Expand Down

0 comments on commit b1d305c

Please sign in to comment.