summaryrefslogtreecommitdiff
path: root/lib/ZhmStat.c
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>1997-10-25 17:45:43 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>1997-10-25 17:45:43 +0000
commit304bb68ebcb9682d28b41d86d59e9ac5f9d7d4a3 (patch)
tree42f9ceb1ecccb53e4e54012133d3c96acadb89e4 /lib/ZhmStat.c
parentbed235d41ec91f86909f602838e88b303904db59 (diff)
Use select() instead of alarm() to wait for a response.
Diffstat (limited to 'lib/ZhmStat.c')
-rw-r--r--lib/ZhmStat.c43
1 files changed, 14 insertions, 29 deletions
diff --git a/lib/ZhmStat.c b/lib/ZhmStat.c
index 80f8ed4..84e6a82 100644
--- a/lib/ZhmStat.c
+++ b/lib/ZhmStat.c
@@ -14,13 +14,6 @@
#include <internal.h>
#include <sys/socket.h>
-static int outoftime = 0;
-
-static RETSIGTYPE timeout()
-{
- outoftime = 1;
-}
-
Code_t ZhmStat(hostaddr, notice)
struct in_addr *hostaddr;
ZNotice_t *notice;
@@ -29,9 +22,8 @@ Code_t ZhmStat(hostaddr, notice)
struct sockaddr_in sin;
ZNotice_t req;
Code_t code;
-#ifdef _POSIX_VERSION
- struct sigaction sa;
-#endif
+ struct timeval tv;
+ fd_set readers;
(void) memset((char *)&sin, 0, sizeof(struct sockaddr_in));
@@ -62,27 +54,20 @@ Code_t ZhmStat(hostaddr, notice)
if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE)
return(code);
-#ifdef _POSIX_VERSION
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
- sa.sa_handler = timeout;
- (void) sigaction(SIGALRM, &sa, (struct sigaction *)0);
-#else
- (void) signal(SIGALRM,timeout);
-#endif
-
- outoftime = 0;
- (void) alarm(10);
+ /* Wait up to ten seconds for a response. */
+ FD_ZERO(&readers);
+ FD_SET(ZGetFD(), &readers);
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
+ code = select(ZGetFD() + 1, &readers, NULL, NULL, &tv);
+ if (code < 0 && errno != EINTR)
+ return(errno);
+ if (code == 0 || (code < 0 && errno == EINTR) || ZPending() == 0)
+ return(ZERR_HMDEAD);
- if (((code = ZReceiveNotice(notice, (struct sockaddr_in *) 0))
- != ZERR_NONE) &&
- code != EINTR)
+ code = ZReceiveNotice(notice, (struct sockaddr_in *) 0);
+ if (code != EINTR)
return(code);
- (void) alarm(0);
-
- if (outoftime)
- return(ZERR_HMDEAD);
-
return(ZERR_NONE);
}