Per feedback from Kevin & David (thanks!), moved the timeout code into
socket_connect and updated the description to be more descriptive and
more closely match the existing connect_timeout.

There is some open question about where exactly in socket_connect to put
the timeout code. Currently I put it after the basic input validation
but it may be slightly better to wait until the socket is actually
opened? But being a global option anyways, I don't think it can hurt
anything.

Signed-off-by: Matthew Sotoudeh <matt...@masot.net>
---
 globals.h     | 1 +
 init.h        | 7 +++++++
 mutt_socket.c | 6 ++++++
 3 files changed, 14 insertions(+)

diff --git a/globals.h b/globals.h
index 06ce410e..b782114e 100644
--- a/globals.h
+++ b/globals.h
@@ -236,6 +236,7 @@ WHERE short PagerContext;
 WHERE short PagerIndexLines;
 WHERE short PagerSkipQuotedContext;
 WHERE short ReadInc;
+WHERE short ReceiveTimeout;
 WHERE short ReflowWrap;
 WHERE short SaveHist;
 WHERE short SendmailWait;
diff --git a/init.h b/init.h
index e160d3d3..e268d796 100644
--- a/init.h
+++ b/init.h
@@ -3221,6 +3221,13 @@ struct option_t MuttVars[] = {
   ** .pp
   ** Also see $$postponed variable.
   */
+  { "receive_timeout",  DT_NUM, R_NONE, {.p=&ReceiveTimeout}, {.l=0} },
+  /*
+  ** .pp
+  ** Causes Mutt to timeout any socket read operation (e.g. SSL_read) after
+  ** this many seconds.  A zero (default) or negative value causes Mutt to wait
+  ** indefinitely for the read to complete.
+  */
   { "record",          DT_PATH, R_NONE, {.p=&Outbox}, {.p="~/sent"} },
   /*
   ** .pp
diff --git a/mutt_socket.c b/mutt_socket.c
index 3e192072..4e1b7889 100644
--- a/mutt_socket.c
+++ b/mutt_socket.c
@@ -407,6 +407,12 @@ static int socket_connect (int fd, struct sockaddr* sa)
     return -1;
   }
 
+  if (ReceiveTimeout > 0)
+  {
+    struct timeval tv = { ReceiveTimeout, 0 };
+    setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
+  }
+
   /* Batch mode does not call mutt_signal_init(), so ensure the alarm
    * interrupts the connect call */
   if (ConnectTimeout > 0)
-- 
2.34.1

Reply via email to