Mercurial > hg > octave-lojdl > gnulib-hg
changeset 15329:e121c7cef4a9
pselect: new module
* lib/sys_select.in.h: Include <signal.h>, 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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 30 Jun 2011 14:57:39 -0700 |
parents | c7ae1577bd26 |
children | 15ab18909697 |
files | ChangeLog lib/pselect.c lib/sys_select.in.h m4/pselect.m4 m4/sys_select_h.m4 modules/pselect modules/sys_select |
diffstat | 7 files changed, 195 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-06-30 Paul Eggert <eggert@cs.ucla.edu> + pselect: new module + * lib/sys_select.in.h: Include <signal.h>, 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 <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00358.html>.
new file mode 100644 --- /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 <config.h> + +#include <sys/select.h> + +#include <errno.h> +#include <signal.h> + +#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; +}
--- 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 <signal.h> +#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)
new file mode 100644 --- /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 <sys/select.h> + ]], + [[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 +])
--- 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 @@ AC_DEFUN([gl_HEADER_SYS_SELECT], [ + AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS]) AC_CACHE_CHECK([whether <sys/select.h> is self-contained], [gl_cv_header_sys_select_h_selfcontained], @@ -77,7 +78,10 @@ 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]) ])
new file mode 100644 --- /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: +<sys/select.h> + +Link: + +License: +LGPLv2+ + +Maintainer: +Paul Eggert
--- a/modules/sys_select +++ b/modules/sys_select @@ -31,8 +31,11 @@ -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)' \