From 3ac3003451be9d12a1083490005c1ffd712c71df Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Fri, 5 Jan 2024 14:09:23 +0000 Subject: socket: handle interrupted transmission in ssl_write According to the gnutls documentation, gnutls_record_send may indicate an interrupted write. In this case the caller should call the function again with the exact same parameters. Simplify the function and return the value verbatim to the callers. A return code of zero is not an error. Other code paths in sock_write do not consider this as an error either. Signed-off-by: Olaf Hering --- src/common/socket.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/common/socket.c b/src/common/socket.c index 6e8bb745b..b7e2c22bd 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1318,23 +1318,16 @@ gint fd_write(gint fd, const gchar *buf, gint len) #if USE_GNUTLS static gint ssl_write(gnutls_session_t ssl, const gchar *buf, gint len) { - gint ret; + ssize_t ret; if (fd_check_io(GPOINTER_TO_INT(gnutls_transport_get_ptr(ssl)), G_IO_OUT) < 0) return -1; - ret = gnutls_record_send(ssl, buf, len); - - switch (ret) { - case 0: - return -1; - case GNUTLS_E_AGAIN: - case GNUTLS_E_INTERRUPTED: - return 0; + do { + ret = gnutls_record_send(ssl, buf, len); + } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED); - default: - return ret; - } + return ret; } #endif base-commit: 1d2683a0f879a7e0245a437485d56b84a6088cd1