diff options
author | Kevin McCarthy <kevin@8t8.us> | 2019-01-21 19:43:08 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2019-01-21 19:43:08 -0800 |
commit | caf5db85396fce2da624449f76a174534657425e (patch) | |
tree | d0e396c1c42e597e1aba79e71bb2382ad27d70ec /mutt_tunnel.c | |
parent | 688e27a93b9c2ed377e097b921e3cb43f6dd1057 (diff) |
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.
Diffstat (limited to 'mutt_tunnel.c')
-rw-r--r-- | mutt_tunnel.c | 36 |
1 files 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) |