]> granicus.if.org Git - mutt/commitdiff
Fix tunnels to also retry and write full buffer.
authorKevin McCarthy <kevin@8t8.us>
Tue, 22 Jan 2019 03:43:08 +0000 (19:43 -0800)
committerKevin McCarthy <kevin@8t8.us>
Tue, 22 Jan 2019 03:43:08 +0000 (19:43 -0800)
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

index e199e4d67072c6f8839ce8f8dcab392b7fbe952a..179c8d0ce9f3e6c20f684efd079232f50c42072b 100644 (file)
@@ -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)