Sun, 15 Apr 2007 02:10:37 +0000
propagate from branch 'im.pidgin.gaim' (head b2836a24d81e7a1bd1d21b3aea8794b094391344)
to branch 'im.pidgin.rlaager.merging.soc-msnp13-to-svn18164' (head 463b4fa9f067b279f843520d95a822adc86a0a1b)
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains the ZCheckIfNotice/select loop used for waiting for | |
| 3 | * a notice, with a timeout. | |
| 4 | * | |
| 5 | * Copyright (c) 1991 by the Massachusetts Institute of Technology. | |
| 6 | * For copying and distribution information, see the file | |
| 7 | * "mit-copyright.h". | |
| 8 | */ | |
| 9 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
10 | #include "internal.h" |
| 10867 | 11 | |
| 12 | #ifdef WIN32 | |
| 13 | #include <winsock2.h> | |
| 14 | ||
| 15 | #ifndef ZEPHYR_USES_KERBEROS | |
| 16 | static int gettimeofday(struct timeval* tv, struct timezone* tz){ | |
| 17 | union { | |
| 18 | long long ns100; /*time since 1 Jan 1601 in 100ns units */ | |
| 19 | FILETIME ft; | |
| 20 | } _now; | |
| 21 | ||
| 22 | GetSystemTimeAsFileTime( &(_now.ft) ); | |
| 23 | tv->tv_usec=(long)((_now.ns100 / 10LL) % 1000000LL ); | |
| 24 | tv->tv_sec= (long)((_now.ns100-(116444736000000000LL))/10000000LL); | |
| 25 | return 0; | |
| 26 | } | |
| 27 | #endif | |
| 28 | ||
| 29 | #else | |
| 2086 | 30 | #include <sys/socket.h> |
| 10867 | 31 | #endif |
| 2086 | 32 | |
| 33 | Code_t Z_WaitForNotice (notice, pred, arg, timeout) | |
| 34 | ZNotice_t *notice; | |
| 35 | int (*pred) __P((ZNotice_t *, void *)); | |
| 36 | void *arg; | |
| 37 | int timeout; | |
| 38 | { | |
| 39 | Code_t retval; | |
| 40 | struct timeval tv, t0; | |
| 41 | fd_set fdmask; | |
| 42 | int i, fd; | |
| 43 | ||
| 44 | retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred, | |
| 45 | (char *) arg); | |
| 46 | if (retval == ZERR_NONE) | |
| 47 | return ZERR_NONE; | |
| 48 | if (retval != ZERR_NONOTICE) | |
| 49 | return retval; | |
| 50 | ||
| 51 | fd = ZGetFD (); | |
| 52 | FD_ZERO (&fdmask); | |
| 53 | tv.tv_sec = timeout; | |
| 54 | tv.tv_usec = 0; | |
| 10867 | 55 | gettimeofday (&t0, (struct timezone *)NULL); |
| 2086 | 56 | t0.tv_sec += timeout; |
| 57 | while (1) { | |
| 58 | FD_SET (fd, &fdmask); | |
| 59 | i = select (fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tv); | |
| 60 | if (i == 0) | |
| 61 | return ETIMEDOUT; | |
| 62 | if (i < 0 && errno != EINTR) | |
| 63 | return errno; | |
| 64 | if (i > 0) { | |
| 65 | retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred, | |
| 66 | (char *) arg); | |
| 67 | if (retval != ZERR_NONOTICE) /* includes ZERR_NONE */ | |
| 68 | return retval; | |
| 69 | } | |
| 10867 | 70 | gettimeofday (&tv, (struct timezone *) NULL); |
| 2086 | 71 | tv.tv_usec = t0.tv_usec - tv.tv_usec; |
| 72 | if (tv.tv_usec < 0) { | |
| 73 | tv.tv_usec += 1000000; | |
| 74 | tv.tv_sec = t0.tv_sec - tv.tv_sec - 1; | |
| 75 | } | |
| 76 | else | |
| 77 | tv.tv_sec = t0.tv_sec - tv.tv_sec; | |
| 78 | } | |
| 79 | /*NOTREACHED*/ | |
| 80 | } |