summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2022-12-03 17:55:36 -0800
committerKevin McCarthy <kevin@8t8.us>2022-12-03 17:55:36 -0800
commit185346ad778f85f7889cff662516e2121bb1edbb (patch)
treec6b3b005f12381c0899424464be6cfe7c7e0d65d
parentc79959e15388da4529569156e674eaa7b55c012e (diff)
Add socket send/receive timeout options
On an unreliable connection (e.g., laptop put to sleep and changing wifi networks) I've had mutt fairly regularly become stuck in SSL_read and have to be killed. Per some of the comments on https://stackoverflow.com/questions/46517875/ssl-read-blocks-indefinitely adding a timeout to the socket should carry over to the SSL_read call. Using this socket_receive_timeout option appears to resolve the issue for me.
-rw-r--r--globals.h2
-rw-r--r--init.h16
-rw-r--r--mutt_socket.c16
3 files changed, 34 insertions, 0 deletions
diff --git a/globals.h b/globals.h
index 06ce410e..3f22ad35 100644
--- a/globals.h
+++ b/globals.h
@@ -103,6 +103,8 @@ WHERE char *MsgFmt;
WHERE char *Preconnect;
WHERE char *Tunnel;
WHERE short NetInc;
+WHERE short SocketReceiveTimeout;
+WHERE short SocketSendTimeout;
#endif /* USE_SOCKET */
#ifdef MIXMASTER
diff --git a/init.h b/init.h
index e160d3d3..ea0bb975 100644
--- a/init.h
+++ b/init.h
@@ -4150,6 +4150,22 @@ struct option_t MuttVars[] = {
** Also see $$write_bcc.
*/
#endif /* USE_SMTP */
+#ifdef USE_SOCKET
+ { "socket_receive_timeout", DT_NUM, R_NONE, {.p=&SocketReceiveTimeout}, {.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.
+ */
+ { "socket_send_timeout", DT_NUM, R_NONE, {.p=&SocketSendTimeout}, {.l=0} },
+ /*
+ ** .pp
+ ** Causes Mutt to timeout any socket write operation (e.g. SSL_write) after
+ ** this many seconds. A zero (default) or negative value causes Mutt to wait
+ ** indefinitely for the write to complete.
+ */
+#endif /* USE_SOCKET */
{ "sort", DT_SORT, R_INDEX|R_RESORT, {.p=&Sort}, {.l=SORT_DATE} },
/*
** .pp
diff --git a/mutt_socket.c b/mutt_socket.c
index 3e192072..898faa07 100644
--- a/mutt_socket.c
+++ b/mutt_socket.c
@@ -433,6 +433,22 @@ static int socket_connect (int fd, struct sockaddr* sa)
save_errno = 0;
+ if (SocketReceiveTimeout > 0)
+ {
+ struct timeval tv = { SocketReceiveTimeout, 0 };
+ if (setsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)
+ dprint (1, (debugfile, "socket_connect: error setting receive timeout (%s)\n",
+ strerror(errno)));
+ }
+
+ if (SocketSendTimeout > 0)
+ {
+ struct timeval tv = { SocketSendTimeout, 0 };
+ if (setsockopt (fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)) < 0)
+ dprint (1, (debugfile, "socket_connect: error setting send timeout (%s)\n",
+ strerror(errno)));
+ }
+
if (connect (fd, sa, sa_size) < 0)
{
save_errno = errno;