Sun, 22 Nov 2020 01:44:50 -0600
zephyr: Replace gettimeofday by GLib functions
* Use monotonic time for some timeouts.
* Use `g_get_real_time` instead of `gettimeofday` for remaining uses.
Testing Done:
Compile only
Reviewed at https://reviews.imfreedom.org/r/248/
| 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 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
7 | * "mit-copyright.h". |
| 2086 | 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 | #else | |
| 2086 | 15 | #include <sys/socket.h> |
| 10867 | 16 | #endif |
| 2086 | 17 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
18 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
19 | Z_WaitForNotice(ZNotice_t *notice, int (*pred)(ZNotice_t *, void *), void *arg, |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39829
diff
changeset
|
20 | int timeout) |
| 2086 | 21 | { |
| 22 | Code_t retval; | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
23 | gint64 t0, tdiff; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
24 | struct timeval tv; |
| 2086 | 25 | fd_set fdmask; |
| 26 | int i, fd; | |
| 27 | ||
| 28 | retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred, | |
| 29 | (char *) arg); | |
| 30 | if (retval == ZERR_NONE) | |
| 31 | return ZERR_NONE; | |
| 32 | if (retval != ZERR_NONOTICE) | |
| 33 | return retval; | |
| 34 | ||
| 35 | fd = ZGetFD (); | |
| 36 | FD_ZERO (&fdmask); | |
| 37 | tv.tv_sec = timeout; | |
| 38 | tv.tv_usec = 0; | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
39 | t0 = g_get_monotonic_time() + timeout * G_USEC_PER_SEC; |
| 2086 | 40 | while (1) { |
| 41 | FD_SET (fd, &fdmask); | |
| 42 | i = select (fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tv); | |
| 43 | if (i == 0) | |
| 44 | return ETIMEDOUT; | |
| 45 | if (i < 0 && errno != EINTR) | |
| 46 | return errno; | |
| 47 | if (i > 0) { | |
| 48 | retval = ZCheckIfNotice (notice, (struct sockaddr_in *) 0, pred, | |
| 49 | (char *) arg); | |
| 50 | if (retval != ZERR_NONOTICE) /* includes ZERR_NONE */ | |
| 51 | return retval; | |
| 52 | } | |
|
40623
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
53 | tdiff = t0 - g_get_monotonic_time(); |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
54 | tv.tv_sec = tdiff / G_USEC_PER_SEC; |
|
6260f39c7c65
zephyr: Replace gettimeofday by GLib functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40166
diff
changeset
|
55 | tv.tv_usec = tdiff - tv.tv_sec * G_USEC_PER_SEC; |
| 2086 | 56 | } |
| 57 | /*NOTREACHED*/ | |
| 58 | } |