diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-10-09 16:03:23 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-10-09 16:03:23 +0000 |
commit | 1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a (patch) | |
tree | d31255f0c1f6d1820d79a512ed178a8e8abdad37 /socket.c | |
parent | df4a9dc9bea6d5ebe6d6c409af795f665c115787 (diff) | |
download | fetchmail-1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a.tar.gz fetchmail-1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a.tar.bz2 fetchmail-1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a.zip |
Arrange for timeout by client if server connection is dropped.
svn path=/trunk/; revision=260
Diffstat (limited to 'socket.c')
-rw-r--r-- | socket.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -13,6 +13,7 @@ #include <config.h> +#include <signal.h> #include <fcntl.h> #include <sys/types.h> #include <sys/socket.h> @@ -43,6 +44,8 @@ #define INTERNAL_BUFSIZE 2048 +extern int timeout; +extern void alarm_handler(); int Socket(host, clientPort) char *host; @@ -82,9 +85,17 @@ char *buf; int len; { int rdlen = 0; + RETSIGTYPE (*sigsave)(); while (--len) { + /* we have to push alarm in case we receive a large message */ + sigsave = signal (SIGALRM, alarm_handler); + if (sigsave == alarm_handler) + alarm (timeout); + else + signal (SIGALRM, sigsave); + if (SockInternalRead(socket, buf, 1) != 1) return -1; else @@ -134,6 +145,7 @@ int len; { int n; + while (len) { n = SockInternalRead(socket, buf, len); @@ -158,6 +170,8 @@ int len; if (sbuflen == 0) { /* buffer is empty; refresh. */ if ((sbuflen = read(socket,sbuf,INTERNAL_BUFSIZE)) < 0) { + if (errno = EINTR) + return -1; perror("SockInternalRead: read"); exit(9); } |