diff options
| author | Paul Eggert | 2012-06-22 14:26:37 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-06-22 14:26:37 -0700 |
| commit | c8fff8630133fea7c4e279458d10d825e5028c62 (patch) | |
| tree | f8b8261fdf3596e1306a3d072e13ec572c9e3e65 /lib/pselect.c | |
| parent | 36cec983d4e680e28e7066fda505910cd549f509 (diff) | |
| download | emacs-c8fff8630133fea7c4e279458d10d825e5028c62.tar.gz emacs-c8fff8630133fea7c4e279458d10d825e5028c62.zip | |
Add gnulib files to support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'lib/pselect.c')
| -rw-r--r-- | lib/pselect.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/pselect.c b/lib/pselect.c new file mode 100644 index 00000000000..d8ebc70f6c6 --- /dev/null +++ b/lib/pselect.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* pselect - synchronous I/O multiplexing | ||
| 2 | |||
| 3 | Copyright 2011-2012 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This file is part of gnulib. | ||
| 6 | |||
| 7 | This program is free software; you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License as published by | ||
| 9 | the Free Software Foundation; either version 3, or (at your option) | ||
| 10 | any later version. | ||
| 11 | |||
| 12 | This program is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License along | ||
| 18 | with this program; if not, see <http://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | /* written by Paul Eggert */ | ||
| 21 | |||
| 22 | #include <config.h> | ||
| 23 | |||
| 24 | #include <sys/select.h> | ||
| 25 | |||
| 26 | #include <errno.h> | ||
| 27 | #include <signal.h> | ||
| 28 | |||
| 29 | /* Examine the size-NFDS file descriptor sets in RFDS, WFDS, and XFDS | ||
| 30 | to see whether some of their descriptors are ready for reading, | ||
| 31 | ready for writing, or have exceptions pending. Wait for at most | ||
| 32 | TIMEOUT seconds, and use signal mask SIGMASK while waiting. A null | ||
| 33 | pointer parameter stands for no descriptors, an infinite timeout, | ||
| 34 | or an unaffected signal mask. */ | ||
| 35 | |||
| 36 | int | ||
| 37 | pselect (int nfds, fd_set *restrict rfds, | ||
| 38 | fd_set *restrict wfds, fd_set *restrict xfds, | ||
| 39 | struct timespec const *restrict timeout, | ||
| 40 | sigset_t const *restrict sigmask) | ||
| 41 | { | ||
| 42 | int select_result; | ||
| 43 | sigset_t origmask; | ||
| 44 | struct timeval tv, *tvp; | ||
| 45 | |||
| 46 | if (timeout) | ||
| 47 | { | ||
| 48 | if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000)) | ||
| 49 | { | ||
| 50 | errno = EINVAL; | ||
| 51 | return -1; | ||
| 52 | } | ||
| 53 | |||
| 54 | tv.tv_sec = timeout->tv_sec; | ||
| 55 | tv.tv_usec = (timeout->tv_nsec + 999) / 1000; | ||
| 56 | tvp = &tv; | ||
| 57 | } | ||
| 58 | else | ||
| 59 | tvp = NULL; | ||
| 60 | |||
| 61 | /* Signal mask munging should be atomic, but this is the best we can | ||
| 62 | do in this emulation. */ | ||
| 63 | if (sigmask) | ||
| 64 | pthread_sigmask (SIG_SETMASK, sigmask, &origmask); | ||
| 65 | |||
| 66 | select_result = select (nfds, rfds, wfds, xfds, tvp); | ||
| 67 | |||
| 68 | if (sigmask) | ||
| 69 | { | ||
| 70 | int select_errno = errno; | ||
| 71 | pthread_sigmask (SIG_SETMASK, &origmask, NULL); | ||
| 72 | errno = select_errno; | ||
| 73 | } | ||
| 74 | |||
| 75 | return select_result; | ||
| 76 | } | ||