From caf5db85396fce2da624449f76a174534657425e Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Mon, 21 Jan 2019 19:43:08 -0800 Subject: [PATCH] Fix tunnels to also retry and write full buffer. Change the tunnel_socket_read() and tunnel_socket_write() as the raw sockets were adjusted in the previous commit. Retry on EINTR, and complete a full write so all the implementations have the same behavior. --- mutt_tunnel.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/mutt_tunnel.c b/mutt_tunnel.c index e199e4d6..179c8d0c 100644 --- a/mutt_tunnel.c +++ b/mutt_tunnel.c @@ -161,12 +161,17 @@ static int tunnel_socket_read (CONNECTION* conn, char* buf, size_t len) TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata; int rc; - rc = read (tunnel->readfd, buf, len); - if (rc == -1) + do + { + rc = read (tunnel->readfd, buf, len); + } while (rc < 0 && errno == EINTR); + + if (rc < 0) { mutt_error (_("Tunnel error talking to %s: %s"), conn->account.host, strerror (errno)); mutt_sleep (1); + return -1; } return rc; @@ -176,16 +181,27 @@ static int tunnel_socket_write (CONNECTION* conn, const char* buf, size_t len) { TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata; int rc; + size_t sent = 0; - rc = write (tunnel->writefd, buf, len); - if (rc == -1) + do { - mutt_error (_("Tunnel error talking to %s: %s"), conn->account.host, - strerror (errno)); - mutt_sleep (1); - } - - return rc; + do + { + rc = write (tunnel->writefd, buf + sent, len - sent); + } while (rc < 0 && errno == EINTR); + + if (rc < 0) + { + mutt_error (_("Tunnel error talking to %s: %s"), conn->account.host, + strerror (errno)); + mutt_sleep (1); + return -1; + } + + sent += rc; + } while (sent < len); + + return sent; } static int tunnel_socket_poll (CONNECTION* conn, time_t wait_secs) -- 2.40.0