From: Kevin McCarthy Date: Tue, 22 Jan 2019 03:43:08 +0000 (-0800) Subject: Fix tunnels to also retry and write full buffer. X-Git-Tag: mutt-1-11-3-rel~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=caf5db85396fce2da624449f76a174534657425e;p=mutt 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. --- 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)