2018-01-01 00:32:25 +00:00
|
|
|
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
1997-06-23 21:55:26 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
1996-07-04 00:07:18 +00:00
|
|
|
|
1997-06-23 21:55:26 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1996-07-04 00:07:18 +00:00
|
|
|
|
1997-06-23 21:55:26 +00:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1996-07-04 00:07:18 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1996-07-04 00:07:18 +00:00
|
|
|
|
|
|
|
|
#include <errno.h>
|
1998-11-26 12:02:23 +00:00
|
|
|
#include <signal.h>
|
2001-01-28 00:00:08 +00:00
|
|
|
#include <stddef.h> /* For NULL. */
|
1996-07-12 02:01:17 +00:00
|
|
|
#include <sys/time.h>
|
1996-07-04 00:07:18 +00:00
|
|
|
#include <sys/select.h>
|
2006-01-19 15:52:01 +00:00
|
|
|
#include <sysdep-cancel.h>
|
2006-01-19 07:50:20 +00:00
|
|
|
|
1996-07-04 00:07:18 +00:00
|
|
|
|
|
|
|
|
/* Check the first NFDS descriptors each in READFDS (if not NULL) for read
|
|
|
|
|
readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
|
|
|
|
|
(if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
|
1998-11-26 12:02:23 +00:00
|
|
|
after waiting the interval specified therein. Additionally set the sigmask
|
|
|
|
|
SIGMASK for this call. Returns the number of ready descriptors, or -1 for
|
|
|
|
|
errors. */
|
2006-01-19 15:24:31 +00:00
|
|
|
int
|
2006-01-19 07:50:20 +00:00
|
|
|
__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
|
|
|
|
|
const struct timespec *timeout, const sigset_t *sigmask)
|
1996-07-04 00:07:18 +00:00
|
|
|
{
|
|
|
|
|
struct timeval tval;
|
|
|
|
|
int retval;
|
1998-11-26 12:02:23 +00:00
|
|
|
sigset_t savemask;
|
1996-07-04 00:07:18 +00:00
|
|
|
|
2002-10-11 07:14:39 +00:00
|
|
|
/* Change nanosecond number to microseconds. This might mean losing
|
1996-07-04 00:07:18 +00:00
|
|
|
precision and therefore the `pselect` should be available. But
|
|
|
|
|
for now it is hardly found. */
|
|
|
|
|
if (timeout != NULL)
|
2011-05-16 09:35:51 -04:00
|
|
|
{
|
|
|
|
|
/* Catch bugs which would be hidden by the TIMESPEC_TO_TIMEVAL
|
|
|
|
|
computations. The division by 1000 truncates values. */
|
2014-02-10 14:45:42 +01:00
|
|
|
if (__glibc_unlikely (timeout->tv_nsec < 0))
|
2011-05-16 09:35:51 -04:00
|
|
|
{
|
|
|
|
|
__set_errno (EINVAL);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TIMESPEC_TO_TIMEVAL (&tval, timeout);
|
|
|
|
|
}
|
1996-07-04 00:07:18 +00:00
|
|
|
|
1998-11-26 12:02:23 +00:00
|
|
|
/* The setting and restoring of the signal mask and the select call
|
|
|
|
|
should be an atomic operation. This can't be done without kernel
|
|
|
|
|
help. */
|
2002-10-11 07:14:39 +00:00
|
|
|
if (sigmask != NULL)
|
|
|
|
|
__sigprocmask (SIG_SETMASK, sigmask, &savemask);
|
|
|
|
|
|
2003-06-15 21:22:26 +00:00
|
|
|
/* Note the pselect() is a cancellation point. But since we call
|
|
|
|
|
select() which itself is a cancellation point we do not have
|
|
|
|
|
to do anything here. */
|
1996-07-04 00:07:18 +00:00
|
|
|
retval = __select (nfds, readfds, writefds, exceptfds,
|
|
|
|
|
timeout != NULL ? &tval : NULL);
|
2002-10-11 07:14:39 +00:00
|
|
|
|
|
|
|
|
if (sigmask != NULL)
|
|
|
|
|
__sigprocmask (SIG_SETMASK, &savemask, NULL);
|
1996-07-04 00:07:18 +00:00
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2006-01-20 07:08:05 +00:00
|
|
|
#ifndef __pselect
|
1996-07-04 00:07:18 +00:00
|
|
|
weak_alias (__pselect, pselect)
|
2006-01-19 15:52:01 +00:00
|
|
|
/* __select handles cancellation. */
|
|
|
|
|
LIBC_CANCEL_HANDLED ();
|
2006-01-20 07:08:05 +00:00
|
|
|
#endif
|