From b1d305c84204784c00be4f31cafa6b1d4f3667c9 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 20 Jun 2024 10:54:13 +0100 Subject: [PATCH] dtls_writes: Handle write errors --- src/coap_gnutls.c | 9 ++++++++- src/coap_mbedtls.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/coap_gnutls.c b/src/coap_gnutls.c index f3325f733d..17d21b724f 100644 --- a/src/coap_gnutls.c +++ b/src/coap_gnutls.c @@ -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; diff --git a/src/coap_mbedtls.c b/src/coap_mbedtls.c index 10560aaae5..ab36963a0a 100644 --- a/src/coap_mbedtls.c +++ b/src/coap_mbedtls.c @@ -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);