From: Paul Eggert Date: Thu, 30 Jun 2011 21:57:39 +0000 (-0700) Subject: pselect: new module X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b1ea5a514b6c42fd527d88261cb434122e9f1a1;p=pspp pselect: new module * lib/sys_select.in.h: Include , for 'sigset_t'. (pselect): New decls. * m4/sys_select_h.m4 (gl_HEADER_SYS_SELECT): Require AC_C_RESTRICT, since the standard pselect decl uses 'restrict'. (gl_SYS_SELECT_H_DEFAULTS): Add defaults for GNULIB_PSELECT, HAVE_PSELECT, REPLACE_PSELECT. * modules/sys_select (sys/select.h): Substitute GNULIB_PSELECT, HAVE_PSELECT, REPLACE_PSELECT. * lib/pselect.c, m4/pselect.m4, modules/pselect: New files. --- diff --git a/ChangeLog b/ChangeLog index e6b7400b04..e68d6767a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-06-30 Paul Eggert + pselect: new module + * lib/sys_select.in.h: Include , for 'sigset_t'. + (pselect): New decls. + * m4/sys_select_h.m4 (gl_HEADER_SYS_SELECT): Require AC_C_RESTRICT, + since the standard pselect decl uses 'restrict'. + (gl_SYS_SELECT_H_DEFAULTS): Add defaults for GNULIB_PSELECT, + HAVE_PSELECT, REPLACE_PSELECT. + * modules/sys_select (sys/select.h): Substitute GNULIB_PSELECT, + HAVE_PSELECT, REPLACE_PSELECT. + * lib/pselect.c, m4/pselect.m4, modules/pselect: New files. + sys_select: don't depend on sys_socket This is so that Emacs doesn't have to drag in m4/sockpfaf.m4 etc; see . diff --git a/lib/pselect.c b/lib/pselect.c new file mode 100644 index 0000000000..7eec89c851 --- /dev/null +++ b/lib/pselect.c @@ -0,0 +1,79 @@ +/* pselect - synchronous I/O multiplexing + + Copyright 2011 Free Software Foundation, Inc. + + This file is part of gnulib. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* written by Paul Eggert */ + +#include + +#include + +#include +#include + +#undef pselect + +/* Examine the size-NFDS file descriptor sets in RFDS, WFDS, and XFDS + to see whether some of their descriptors are ready for reading, + ready for writing, or have exceptions pending. Wait for at most + TIMEOUT seconds, and use signal mask SIGMASK while waiting. A null + pointer parameter stands for no descriptors, an infinite timeout, + or an unaffected signal mask. */ + +int +rpl_pselect (int nfds, fd_set *restrict rfds, + fd_set *restrict wfds, fd_set *restrict xfds, + struct timespec const *restrict timeout, + sigset_t const *restrict sigmask) +{ + int select_result; + sigset_t origmask; + struct timeval tv, *tvp; + + if (timeout) + { + if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000)) + { + errno = EINVAL; + return -1; + } + + tv.tv_sec = timeout->tv_sec; + tv.tv_usec = (timeout->tv_nsec + 999) / 1000; + tvp = &tv; + } + else + tvp = NULL; + + /* Signal mask munging should be atomic, but this is the best we can + do in this emulation. */ + if (sigmask) + sigprocmask (SIG_SETMASK, sigmask, &origmask); + + select_result = select (nfds, rfds, wfds, xfds, tvp); + + if (sigmask) + { + int select_errno = errno; + sigprocmask (SIG_SETMASK, &origmask, NULL); + errno = select_errno; + } + + return select_result; +} diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index ef4c6f3cf6..ada0311016 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -85,11 +85,48 @@ # endif #endif +/* Get definition of 'sigset_t'. + But avoid namespace pollution on glibc systems. */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ +#if @GNULIB_PSELECT@ +# if @REPLACE_PSELECT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef pselect +# define pselect rpl_pselect +# endif +_GL_FUNCDECL_RPL (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +_GL_CXXALIAS_RPL (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# else +# if !@HAVE_PSELECT@ +_GL_FUNCDECL_SYS (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# endif +_GL_CXXALIAS_SYS (pselect, int, + (int, fd_set *restrict, fd_set *restrict, fd_set *restrict, + struct timespec const *restrict, const sigset_t *restrict)); +# endif +_GL_CXXALIASWARN (pselect); +#elif defined GNULIB_POSIXCHECK +# undef pselect +# if HAVE_RAW_DECL_PSELECT +_GL_WARN_ON_USE (pselect, "pselect is not portable - " + "use gnulib module pselect for portability"); +# endif +#endif + #if @GNULIB_SELECT@ # if @REPLACE_SELECT@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/pselect.m4 b/m4/pselect.m4 new file mode 100644 index 0000000000..5a76a7b8d9 --- /dev/null +++ b/m4/pselect.m4 @@ -0,0 +1,31 @@ +# pselect.m4 +dnl Copyright (C) 2011 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_PSELECT], +[ + AC_REQUIRE([gl_HEADER_SYS_SELECT]) + AC_REQUIRE([AC_C_RESTRICT]) + AC_CHECK_FUNCS_ONCE([pselect]) + + if test $ac_cv_func_pselect = yes; then + AC_CACHE_CHECK([whether signature of pselect conforms to POSIX], + gl_cv_sig_pselect, + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[int (*p) (int, fd_set *, fd_set *, fd_set *restrict, + struct timespec const *restrict, + sigset_t const *restrict) = pselect; + return !p;]])], + [gl_cv_sig_pselect=yes], + [gl_cv_sig_pselect=no])]) + fi + + if test $ac_cv_func_pselect = no || test $gl_cv_sig_pselect = no; then + REPLACE_PSELECT=1 + fi +]) diff --git a/m4/sys_select_h.m4 b/m4/sys_select_h.m4 index 5b51af407c..7d5f477f7e 100644 --- a/m4/sys_select_h.m4 +++ b/m4/sys_select_h.m4 @@ -1,4 +1,4 @@ -# sys_select_h.m4 serial 17 +# sys_select_h.m4 serial 18 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -6,6 +6,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_HEADER_SYS_SELECT], [ + AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS]) AC_CACHE_CHECK([whether is self-contained], [gl_cv_header_sys_select_h_selfcontained], @@ -77,7 +78,10 @@ AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR], AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS], [ + GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT]) GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT]) dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT]) + REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT]) REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT]) ]) diff --git a/modules/pselect b/modules/pselect new file mode 100644 index 0000000000..b899198704 --- /dev/null +++ b/modules/pselect @@ -0,0 +1,29 @@ +Description: +pselect() function: synchronous I/O multiplexing. + +Files: +lib/pselect.c +m4/pselect.m4 + +Depends-on: +sys_select + +configure.ac: +gl_FUNC_PSELECT +if test $REPLACE_PSELECT = 1; then + AC_LIBOBJ([pselect]) +fi +gl_SYS_SELECT_MODULE_INDICATOR([pselect]) + +Makefile.am: + +Include: + + +Link: + +License: +LGPLv2+ + +Maintainer: +Paul Eggert diff --git a/modules/sys_select b/modules/sys_select index d0c020978c..cb3cb9956f 100644 --- a/modules/sys_select +++ b/modules/sys_select @@ -31,8 +31,11 @@ sys/select.h: sys_select.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_SYS_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \ -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \ + -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \ -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \ -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \ + -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \ -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \