summaryrefslogtreecommitdiffstats
path: root/mutt_socket.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2017-07-22 19:48:49 -0700
committerKevin McCarthy <kevin@8t8.us>2017-07-22 19:48:49 -0700
commit75e7e18d35aea137c4a16d3edc98cb32fa6e16b6 (patch)
treef84d2dd128f70456609ee72e80735c46fe59b431 /mutt_socket.c
parent2aa03f79892aa193f3e8bbb2037fe666a8122071 (diff)
Add timeout parameter to mutt_socket_poll.
This will be used in the next commit to add a timeout when polling for new mail.
Diffstat (limited to 'mutt_socket.c')
-rw-r--r--mutt_socket.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/mutt_socket.c b/mutt_socket.c
index 08f21533..d4b22973 100644
--- a/mutt_socket.c
+++ b/mutt_socket.c
@@ -153,13 +153,13 @@ int mutt_socket_write_d (CONNECTION *conn, const char *buf, int len, int dbg)
* Returns: >0 if there is data to read,
* 0 if a read would block,
* -1 if this connection doesn't support polling */
-int mutt_socket_poll (CONNECTION* conn)
+int mutt_socket_poll (CONNECTION* conn, time_t wait_secs)
{
if (conn->bufpos < conn->available)
return conn->available - conn->bufpos;
if (conn->conn_poll)
- return conn->conn_poll (conn);
+ return conn->conn_poll (conn, wait_secs);
return -1;
}
@@ -431,18 +431,41 @@ int raw_socket_write (CONNECTION* conn, const char* buf, size_t count)
return rc;
}
-int raw_socket_poll (CONNECTION* conn)
+int raw_socket_poll (CONNECTION* conn, time_t wait_secs)
{
fd_set rfds;
- struct timeval tv = { 0, 0 };
+ struct timeval tv;
+ struct timespec pre_t, post_t;
+ time_t sleep_secs;
+ int rv;
if (conn->fd < 0)
return -1;
- FD_ZERO (&rfds);
- FD_SET (conn->fd, &rfds);
-
- return select (conn->fd + 1, &rfds, NULL, NULL, &tv);
+ FOREVER
+ {
+ tv.tv_sec = wait_secs;
+ tv.tv_usec = 0;
+
+ FD_ZERO (&rfds);
+ FD_SET (conn->fd, &rfds);
+
+ clock_gettime (CLOCK_MONOTONIC, &pre_t);
+ rv = select (conn->fd + 1, &rfds, NULL, NULL, &tv);
+ clock_gettime (CLOCK_MONOTONIC, &post_t);
+
+ if (rv > 0 ||
+ (rv < 0 && errno != EINTR))
+ return rv;
+
+ if (SigInt)
+ mutt_query_exit ();
+
+ sleep_secs = post_t.tv_sec - pre_t.tv_sec;
+ if (wait_secs <= sleep_secs)
+ return 0;
+ wait_secs -= sleep_secs;
+ }
}
int raw_socket_open (CONNECTION* conn)