aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-10-09 16:03:23 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-10-09 16:03:23 +0000
commit1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a (patch)
treed31255f0c1f6d1820d79a512ed178a8e8abdad37 /socket.c
parentdf4a9dc9bea6d5ebe6d6c409af795f665c115787 (diff)
downloadfetchmail-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.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/socket.c b/socket.c
index 8b79e818..3cfb9f0a 100644
--- a/socket.c
+++ b/socket.c
@@ -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);
}