summaryrefslogtreecommitdiff
path: root/lib/ZWait4Not.c
diff options
context:
space:
mode:
authorGravatar Kenneth G Raeburn <raeburn@mit.edu>1991-03-21 07:05:21 +0000
committerGravatar Kenneth G Raeburn <raeburn@mit.edu>1991-03-21 07:05:21 +0000
commitb3bdf359c6466abd7d18867be8bb3e0e21f3c887 (patch)
treee9e063a97a9f45d35898e1f6f64f8f55100f3efc /lib/ZWait4Not.c
parente3ebca76c257ff8b8e8ef7c53fbbf7ce94a1facc (diff)
Initial revision
Diffstat (limited to 'lib/ZWait4Not.c')
-rw-r--r--lib/ZWait4Not.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/ZWait4Not.c b/lib/ZWait4Not.c
new file mode 100644
index 0000000..c550ae0
--- /dev/null
+++ b/lib/ZWait4Not.c
@@ -0,0 +1,75 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains the ZCheckIfNotice/select loop used for waiting for
+ * a notice, with a timeout.
+ *
+ * Created by: <Joe Random Hacker>
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1991 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+
+#include <zephyr/mit-copyright.h>
+
+#ifndef lint
+static char rcsid_ZWaitForNotice_c[] =
+ "$Zephyr$";
+#endif
+
+#include <zephyr/zephyr.h>
+#ifdef _AIX
+#include <sys/select.h>
+#endif
+
+Code_t
+Z_WaitForNotice (notice, pred, uid, timeout)
+ ZNotice_t *notice;
+ int (*pred) ();
+ ZUnique_Id_t *uid;
+ int timeout;
+{
+ Code_t retval;
+ struct timeval tv, t0;
+ fd_set fdmask;
+ int i, fd;
+
+ retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
+ (char *) uid);
+ if (retval == ZERR_NONE)
+ return ZERR_NONE;
+ if (retval != ZERR_NONOTICE)
+ return retval;
+
+ fd = ZGetFD ();
+ FD_ZERO (&fdmask);
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
+ gettimeofday (&t0, (struct timezone *) 0);
+ t0.tv_sec += timeout;
+ while (1) {
+ FD_SET (fd, &fdmask);
+ i = select (fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tv);
+ if (i == 0)
+ return ETIMEDOUT;
+ if (i < 0 && errno != EINTR)
+ return errno;
+ if (i > 0) {
+ retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
+ (char *) uid);
+ if (retval != ZERR_NONOTICE) /* includes ZERR_NONE */
+ return retval;
+ }
+ gettimeofday (&tv, (struct timezone *) 0);
+ tv.tv_usec = t0.tv_usec - tv.tv_usec;
+ if (tv.tv_usec < 0) {
+ tv.tv_usec += 1000000;
+ tv.tv_sec = t0.tv_sec - tv.tv_sec - 1;
+ }
+ else
+ tv.tv_sec = t0.tv_sec - tv.tv_sec;
+ }
+ /*NOTREACHED*/
+}