From 1413fd46bcbd4a05c3e46113fbd7ae11b3d4a40a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 9 Oct 1996 16:03:23 +0000 Subject: Arrange for timeout by client if server connection is dropped. svn path=/trunk/; revision=260 --- socket.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'socket.c') diff --git a/socket.c b/socket.c index 8b79e818..3cfb9f0a 100644 --- a/socket.c +++ b/socket.c @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -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); } -- cgit v1.2.3