Back to index

glibc  2.9
pselect.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <signal.h>
00022 #include <stddef.h>  /* For NULL.  */
00023 #include <sys/time.h>
00024 #include <sys/select.h>
00025 #include <sysdep-cancel.h>
00026 
00027 
00028 /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
00029    readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
00030    (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out
00031    after waiting the interval specified therein.  Additionally set the sigmask
00032    SIGMASK for this call.  Returns the number of ready descriptors, or -1 for
00033    errors.  */
00034 int
00035 __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
00036           const struct timespec *timeout, const sigset_t *sigmask)
00037 {
00038   struct timeval tval;
00039   int retval;
00040   sigset_t savemask;
00041 
00042   /* Change nanosecond number to microseconds.  This might mean losing
00043      precision and therefore the `pselect` should be available.  But
00044      for now it is hardly found.  */
00045   if (timeout != NULL)
00046     TIMESPEC_TO_TIMEVAL (&tval, timeout);
00047 
00048   /* The setting and restoring of the signal mask and the select call
00049      should be an atomic operation.  This can't be done without kernel
00050      help.  */
00051   if (sigmask != NULL)
00052     __sigprocmask (SIG_SETMASK, sigmask, &savemask);
00053 
00054   /* Note the pselect() is a cancellation point.  But since we call
00055      select() which itself is a cancellation point we do not have
00056      to do anything here.  */
00057   retval = __select (nfds, readfds, writefds, exceptfds,
00058                    timeout != NULL ? &tval : NULL);
00059 
00060   if (sigmask != NULL)
00061     __sigprocmask (SIG_SETMASK, &savemask, NULL);
00062 
00063   return retval;
00064 }
00065 #ifndef __pselect
00066 weak_alias (__pselect, pselect)
00067 strong_alias (__pselect, __libc_pselect)
00068 /* __select handles cancellation.  */
00069 LIBC_CANCEL_HANDLED ();
00070 #endif