Mercurial > pidgin.yaz
diff src/protocols/zephyr/ZWait4Not.c @ 2086:424a40f12a6c
[gaim-migrate @ 2096]
moving protocols from plugins/ to src/protocols. making it so that you can select which protocols are compiled statically.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 31 Jul 2001 01:00:39 +0000 |
parents | |
children | 43d6c08d7e96 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/zephyr/ZWait4Not.c Tue Jul 31 01:00:39 2001 +0000 @@ -0,0 +1,71 @@ +/* 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: warmenhoven $ + * + * Copyright (c) 1991 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#include "mit-copyright.h" + +#ifndef lint +static char rcsid_ZWaitForNotice_c[] = "$Zephyr$"; +#endif + +#include <internal.h> +#include <sys/socket.h> + +Code_t Z_WaitForNotice (notice, pred, arg, timeout) + ZNotice_t *notice; + int (*pred) __P((ZNotice_t *, void *)); + void *arg; + int timeout; +{ + Code_t retval; + struct timeval tv, t0; + fd_set fdmask; + int i, fd; + + retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred, + (char *) arg); + 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 *) arg); + 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*/ +}