annotate src/protocols/zephyr/ZWait4Not.c @ 12154:24bde295d755

[gaim-migrate @ 14455] Migrate the old idle reporting preference in a way to cause least confusion committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 19 Nov 2005 13:52:03 +0000
parents 64895571248f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* This file is part of the Project Athena Zephyr Notification System.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * It contains the ZCheckIfNotice/select loop used for waiting for
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 * a notice, with a timeout.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 * Copyright (c) 1991 by the Massachusetts Institute of Technology.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * For copying and distribution information, see the file
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * "mit-copyright.h".
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9
8792
43d6c08d7e96 [gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents: 2086
diff changeset
10 #include "internal.h"
10867
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
11
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
12 #ifdef WIN32
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
13 #include <winsock2.h>
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
14
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
15 #ifndef ZEPHYR_USES_KERBEROS
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
16 static int gettimeofday(struct timeval* tv, struct timezone* tz){
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
17 union {
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
18 long long ns100; /*time since 1 Jan 1601 in 100ns units */
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
19 FILETIME ft;
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
20 } _now;
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
21
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
22 GetSystemTimeAsFileTime( &(_now.ft) );
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
23 tv->tv_usec=(long)((_now.ns100 / 10LL) % 1000000LL );
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
24 tv->tv_sec= (long)((_now.ns100-(116444736000000000LL))/10000000LL);
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
25 return 0;
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
26 }
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
27 #endif
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
28
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
29 #else
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <sys/socket.h>
10867
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
31 #endif
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 Code_t Z_WaitForNotice (notice, pred, arg, timeout)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 ZNotice_t *notice;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 int (*pred) __P((ZNotice_t *, void *));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 void *arg;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 int timeout;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 Code_t retval;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 struct timeval tv, t0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 fd_set fdmask;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 int i, fd;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 (char *) arg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 if (retval == ZERR_NONE)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 return ZERR_NONE;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 if (retval != ZERR_NONOTICE)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 return retval;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 fd = ZGetFD ();
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 FD_ZERO (&fdmask);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 tv.tv_sec = timeout;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 tv.tv_usec = 0;
10867
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
55 gettimeofday (&t0, (struct timezone *)NULL);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 t0.tv_sec += timeout;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 while (1) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 FD_SET (fd, &fdmask);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 i = select (fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tv);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 if (i == 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 return ETIMEDOUT;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 if (i < 0 && errno != EINTR)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 return errno;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 if (i > 0) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred,
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 (char *) arg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 if (retval != ZERR_NONOTICE) /* includes ZERR_NONE */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 return retval;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 }
10867
5727afad0fb8 [gaim-migrate @ 12553]
Mark Doliner <mark@kingant.net>
parents: 8792
diff changeset
70 gettimeofday (&tv, (struct timezone *) NULL);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 tv.tv_usec = t0.tv_usec - tv.tv_usec;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 if (tv.tv_usec < 0) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 tv.tv_usec += 1000000;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 tv.tv_sec = t0.tv_sec - tv.tv_sec - 1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 tv.tv_sec = t0.tv_sec - tv.tv_sec;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 /*NOTREACHED*/
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 }