Remove unused poll(2) emulation

Closes #235.
This commit is contained in:
Keegan McAllister
2012-04-30 23:36:54 -04:00
committed by Keith Winstein
parent 043f9af260
commit bb651581a7
11 changed files with 11 additions and 607 deletions
-61
View File
@@ -250,66 +250,6 @@ AC_CHECK_DECL([forkpty],
, [[#include <sys/types.h> , [[#include <sys/types.h>
#include <libutil.h>]]) #include <libutil.h>]])
AC_ARG_VAR([poll_CFLAGS], [C compiler flags for poll])
AC_ARG_VAR([poll_LIBS], [linker flags for poll])
AS_IF([test -z "$poll_LIBS"], [
AC_CHECK_LIB([poll], [poll], [poll_LIBS="-lpoll"])
])
# Check to make sure poll() can handle stdin and ptys
AC_CACHE_CHECK([whether poll can handle ptys],
[ac_cv_poll_pty],
[
save_CFLAGS="$CFLAGS"
save_LIBS="$LIBS"
AS_IF([test "x$poll_CFLAGS" != "x"],
[CFLAGS="$CFLAGS $poll_CFLAGS"])
AS_IF([test "x$poll_LIBS" != "x"],
[LIBS="$LIBS $poll_LIBS"])
LIBS="$LIBS -lutil"
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#if HAVE_PTY_H
#include <pty.h>
#elif HAVE_UTIL_H
#include <util.h>
#endif
#if FORKPTY_IN_LIBUTIL
#include <libutil.h>
#endif
#include <sys/poll.h>
int master, slave;
struct pollfd pollfds[ 1 ];
]], [[
if ( openpty( &master, &slave, NULL, NULL, NULL ) < 0 ) {
perror( "openpty" );
exit( 1 );
}
pollfds[ 0 ].fd = master;
pollfds[ 0 ].events = POLLIN;
int active_fds = poll( pollfds, 1, 100 );
if ( active_fds < 0 ) {
perror( "poll" );
exit( 1 );
}
if ( pollfds[ 0 ].revents & (POLLERR | POLLHUP | POLLNVAL) ) {
exit( 2 );
}
]])],
[ac_cv_poll_pty=yes],
[ac_cv_poll_pty=no])
CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"
])
AM_CONDITIONAL([COND_THIRD_POLL], [test "x$ac_cv_poll_pty" = "xno"])
AC_MSG_CHECKING([whether pipe2(..., O_CLOEXEC) is supported]) AC_MSG_CHECKING([whether pipe2(..., O_CLOEXEC) is supported])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define _GNU_SOURCE AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define _GNU_SOURCE
#include <unistd.h> #include <unistd.h>
@@ -365,7 +305,6 @@ AC_CONFIG_FILES([
Makefile Makefile
third/Makefile third/Makefile
third/libstddjb/Makefile third/libstddjb/Makefile
third/poll/Makefile
src/Makefile src/Makefile
src/crypto/Makefile src/crypto/Makefile
src/frontend/Makefile src/frontend/Makefile
-29
View File
@@ -189,32 +189,3 @@ License: ISC
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Files: third/poll/*
Copyright: 1995-2011, Brian M. Clapper
License: BSD-3-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
.
* Neither the name of the clapper.org nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
+1 -36
View File
@@ -249,39 +249,4 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
\ \
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.\ You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.\
\ \
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.\ The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.}
\
===========================================================================\
\
The third/poll software is released under the following BSD license,\
adapted from http://opensource.org/licenses/bsd-license.php\
---------------------------------------------------------------------------\
\
Copyright (c) 1995-2011, Brian M. Clapper\
All rights reserved.\
\
Redistribution and use in source and binary forms, with or without\
modification, are permitted provided that the following conditions are met:\
\
* Redistributions of source code must retain the above copyright notice,\
this list of conditions and the following disclaimer.\
\
* Redistributions in binary form must reproduce the above copyright notice,\
this list of conditions and the following disclaimer in the documentation\
and/or other materials provided with the distribution.\
\
* Neither the name of the clapper.org nor the names of its contributors may\
be used to endorse or promote products derived from this software without\
specific prior written permission.\
\
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\
POSSIBILITY OF SUCH DAMAGE.}
+8 -15
View File
@@ -3,13 +3,6 @@ if COND_THIRD_LIBSTDDJB
STDDJB_LDFLAGS += $(top_builddir)/third/libstddjb/libstddjb.a STDDJB_LDFLAGS += $(top_builddir)/third/libstddjb/libstddjb.a
STDDJB_CPPFLAGS += -I$(top_srcdir)/third/libstddjb STDDJB_CPPFLAGS += -I$(top_srcdir)/third/libstddjb
endif endif
if COND_THIRD_POLL
working_poll_LIBS = $(top_builddir)/third/poll/libpoll.a
working_poll_CFLAGS = -I$(top_srcdir)/third/poll
else
working_poll_LIBS = $(poll_LIBS)
working_poll_CFLAGS = $(poll_CFLAGS)
endif
AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS) AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS)
AM_LDFLAGS = $(HARDEN_LDFLAGS) AM_LDFLAGS = $(HARDEN_LDFLAGS)
@@ -27,17 +20,17 @@ decrypt_CPPFLAGS = -I$(srcdir)/../crypto
decrypt_LDADD = ../crypto/libmoshcrypto.a decrypt_LDADD = ../crypto/libmoshcrypto.a
parse_SOURCES = parse.cc parse_SOURCES = parse.cc
parse_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util $(working_poll_CFLAGS) parse_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util
parse_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a -lutil $(working_poll_LIBS) parse_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a -lutil
termemu_SOURCES = termemu.cc termemu_SOURCES = termemu.cc
termemu_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util -I$(srcdir)/../statesync -I../protobufs $(STDDJB_CPPFLAGS) $(working_poll_CFLAGS) termemu_CPPFLAGS = -I$(srcdir)/../terminal -I$(srcdir)/../util -I$(srcdir)/../statesync -I../protobufs $(STDDJB_CPPFLAGS)
termemu_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a ../statesync/libmoshstatesync.a ../protobufs/libmoshprotos.a -lutil $(STDDJB_LDFLAGS) $(TINFO_LIBS) $(protobuf_LIBS) $(working_poll_LIBS) termemu_LDADD = ../terminal/libmoshterminal.a ../util/libmoshutil.a ../statesync/libmoshstatesync.a ../protobufs/libmoshprotos.a -lutil $(STDDJB_LDFLAGS) $(TINFO_LIBS) $(protobuf_LIBS)
ntester_SOURCES = ntester.cc ntester_SOURCES = ntester.cc
ntester_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I../protobufs $(working_poll_CFLAGS) $(protobuf_CFLAGS) ntester_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I../protobufs $(protobuf_CFLAGS)
ntester_LDADD = ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../protobufs/libmoshprotos.a $(working_poll_LIBS) -lutil -lm $(protobuf_LIBS) ntester_LDADD = ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../protobufs/libmoshprotos.a -lutil -lm $(protobuf_LIBS)
benchmark_SOURCES = benchmark.cc benchmark_SOURCES = benchmark.cc
benchmark_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I../protobufs -I$(srcdir)/../frontend -I$(srcdir)/../crypto -I$(srcdir)/../network $(STDDJB_CPPFLAGS) $(working_poll_CFLAGS) $(protobuf_CFLAGS) benchmark_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I../protobufs -I$(srcdir)/../frontend -I$(srcdir)/../crypto -I$(srcdir)/../network $(STDDJB_CPPFLAGS) $(protobuf_CFLAGS)
benchmark_LDADD = ../frontend/terminaloverlay.o ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../protobufs/libmoshprotos.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../util/libmoshutil.a $(STDDJB_LDFLAGS) $(working_poll_LIBS) -lutil -lm $(TINFO_LIBS) $(protobuf_LIBS) benchmark_LDADD = ../frontend/terminaloverlay.o ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../protobufs/libmoshprotos.a ../network/libmoshnetwork.a ../crypto/libmoshcrypto.a ../util/libmoshutil.a $(STDDJB_LDFLAGS) -lutil -lm $(TINFO_LIBS) $(protobuf_LIBS)
+2 -9
View File
@@ -3,18 +3,11 @@ if COND_THIRD_LIBSTDDJB
STDDJB_LDFLAGS += $(top_builddir)/third/libstddjb/libstddjb.a STDDJB_LDFLAGS += $(top_builddir)/third/libstddjb/libstddjb.a
STDDJB_CPPFLAGS += -I$(top_srcdir)/third/libstddjb STDDJB_CPPFLAGS += -I$(top_srcdir)/third/libstddjb
endif endif
if COND_THIRD_POLL
working_poll_LIBS = $(top_builddir)/third/poll/libpoll.a
working_poll_CFLAGS = -I$(top_srcdir)/third/poll
else
working_poll_LIBS = $(poll_LIBS)
working_poll_CFLAGS = $(poll_CFLAGS)
endif
AM_CPPFLAGS = -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I../protobufs -I$(srcdir)/../util $(STDDJB_CPPFLAGS) $(TINFO_CFLAGS) $(protobuf_CFLAGS) $(working_poll_CFLAGS) AM_CPPFLAGS = -I$(srcdir)/../statesync -I$(srcdir)/../terminal -I$(srcdir)/../network -I$(srcdir)/../crypto -I../protobufs -I$(srcdir)/../util $(STDDJB_CPPFLAGS) $(TINFO_CFLAGS) $(protobuf_CFLAGS)
AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS) AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS)
AM_LDFLAGS = $(HARDEN_LDFLAGS) AM_LDFLAGS = $(HARDEN_LDFLAGS)
LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a $(STDDJB_LDFLAGS) $(working_poll_LIBS) -lm $(TINFO_LIBS) $(protobuf_LIBS) LDADD = ../crypto/libmoshcrypto.a ../network/libmoshnetwork.a ../statesync/libmoshstatesync.a ../terminal/libmoshterminal.a ../util/libmoshutil.a ../protobufs/libmoshprotos.a $(STDDJB_LDFLAGS) -lm $(TINFO_LIBS) $(protobuf_LIBS)
mosh_server_LDADD = $(LDADD) -lutil mosh_server_LDADD = $(LDADD) -lutil
-3
View File
@@ -2,6 +2,3 @@ SUBDIRS =
if COND_THIRD_LIBSTDDJB if COND_THIRD_LIBSTDDJB
SUBDIRS += libstddjb SUBDIRS += libstddjb
endif endif
if COND_THIRD_POLL
SUBDIRS += poll
endif
-32
View File
@@ -1,32 +0,0 @@
This software is released under the following BSD license, adapted from
http://opensource.org/licenses/bsd-license.php
---------------------------------------------------------------------------
Copyright (c) 1995-2011, Brian M. Clapper
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the clapper.org nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-10
View File
@@ -1,10 +0,0 @@
AM_CFLAGS = -pedantic -Wall -Wextra -pipe $(HARDEN_CFLAGS)
noinst_LIBRARIES = libpoll.a
libpoll_a_SOURCES = \
sys/poll.h \
poll.h \
poll.c
EXTRA_DIST = LICENSE
-306
View File
@@ -1,306 +0,0 @@
/*---------------------------------------------------------------------------*\
$Id$
NAME
poll - select(2)-based poll() emulation function for BSD systems.
SYNOPSIS
#include "poll.h"
struct pollfd
{
int fd;
short events;
short revents;
}
int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)
DESCRIPTION
This file, and the accompanying "poll.h", implement the System V
poll(2) system call for BSD systems (which typically do not provide
poll()). Poll() provides a method for multiplexing input and output
on multiple open file descriptors; in traditional BSD systems, that
capability is provided by select(). While the semantics of select()
differ from those of poll(), poll() can be readily emulated in terms
of select() -- which is how this function is implemented.
REFERENCES
Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990.
NOTES
1. This software requires an ANSI C compiler.
LICENSE
This software is released under the following BSD license, adapted from
http://opensource.org/licenses/bsd-license.php
Copyright (c) 1995-2011, Brian M. Clapper
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the clapper.org nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*\
Includes
\*---------------------------------------------------------------------------*/
#include <unistd.h> /* standard Unix definitions */
#include <sys/types.h> /* system types */
#include <sys/time.h> /* time definitions */
#include <assert.h> /* assertion macros */
#include <string.h> /* string functions */
#include "poll.h" /* this package */
/*---------------------------------------------------------------------------*\
Macros
\*---------------------------------------------------------------------------*/
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/*---------------------------------------------------------------------------*\
Private Functions
\*---------------------------------------------------------------------------*/
static int map_poll_spec
#if __STDC__ > 0
(struct pollfd *pArray,
nfds_t n_fds,
fd_set *pReadSet,
fd_set *pWriteSet,
fd_set *pExceptSet)
#else
(pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
struct pollfd *pArray;
nfds_t n_fds,
fd_set *pReadSet;
fd_set *pWriteSet;
fd_set *pExceptSet;
#endif
{
register nfds_t i; /* loop control */
register struct pollfd *pCur; /* current array element */
register int max_fd = -1; /* return value */
/*
Map the poll() structures into the file descriptor sets required
by select().
*/
for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
{
/* Skip any bad FDs in the array. */
if (pCur->fd < 0)
continue;
if (pCur->events & POLLIN)
{
/* "Input Ready" notification desired. */
FD_SET (pCur->fd, pReadSet);
}
if (pCur->events & POLLOUT)
{
/* "Output Possible" notification desired. */
FD_SET (pCur->fd, pWriteSet);
}
if (pCur->events & POLLPRI)
{
/*
"Exception Occurred" notification desired. (Exceptions
include out of band data.
*/
FD_SET (pCur->fd, pExceptSet);
}
max_fd = MAX (max_fd, pCur->fd);
}
return max_fd;
}
static struct timeval *map_timeout
#if __STDC__ > 0
(int poll_timeout, struct timeval *pSelTimeout)
#else
(poll_timeout, pSelTimeout)
int poll_timeout;
struct timeval *pSelTimeout;
#endif
{
struct timeval *pResult;
/*
Map the poll() timeout value into a select() timeout. The possible
values of the poll() timeout value, and their meanings, are:
VALUE MEANING
-1 wait indefinitely (until signal occurs)
0 return immediately, don't block
>0 wait specified number of milliseconds
select() uses a "struct timeval", which specifies the timeout in
seconds and microseconds, so the milliseconds value has to be mapped
accordingly.
*/
assert (pSelTimeout != (struct timeval *) NULL);
switch (poll_timeout)
{
case -1:
/*
A NULL timeout structure tells select() to wait indefinitely.
*/
pResult = (struct timeval *) NULL;
break;
case 0:
/*
"Return immediately" (test) is specified by all zeros in
a timeval structure.
*/
pSelTimeout->tv_sec = 0;
pSelTimeout->tv_usec = 0;
pResult = pSelTimeout;
break;
default:
/* Wait the specified number of milliseconds. */
pSelTimeout->tv_sec = poll_timeout / 1000; /* get seconds */
poll_timeout %= 1000; /* remove seconds */
pSelTimeout->tv_usec = poll_timeout * 1000; /* get microseconds */
pResult = pSelTimeout;
break;
}
return pResult;
}
static void map_select_results
#if __STDC__ > 0
(struct pollfd *pArray,
unsigned long n_fds,
fd_set *pReadSet,
fd_set *pWriteSet,
fd_set *pExceptSet)
#else
(pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
struct pollfd *pArray;
unsigned long n_fds;
fd_set *pReadSet;
fd_set *pWriteSet;
fd_set *pExceptSet;
#endif
{
register unsigned long i; /* loop control */
register struct pollfd *pCur; /* current array element */
for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
{
/* Skip any bad FDs in the array. */
if (pCur->fd < 0)
continue;
/* Exception events take priority over input events. */
pCur->revents = 0;
if (FD_ISSET (pCur->fd, pExceptSet))
pCur->revents |= POLLPRI;
else if (FD_ISSET (pCur->fd, pReadSet))
pCur->revents |= POLLIN;
if (FD_ISSET (pCur->fd, pWriteSet))
pCur->revents |= POLLOUT;
}
return;
}
/*---------------------------------------------------------------------------*\
Public Functions
\*---------------------------------------------------------------------------*/
int poll
#if __STDC__ > 0
(struct pollfd *pArray, unsigned long n_fds, int timeout)
#else
(pArray, n_fds, timeout)
struct pollfd *pArray;
unsigned long n_fds;
int timeout;
#endif
{
fd_set read_descs; /* input file descs */
fd_set write_descs; /* output file descs */
fd_set except_descs; /* exception descs */
struct timeval stime; /* select() timeout value */
int ready_descriptors; /* function result */
int max_fd; /* maximum fd value */
struct timeval *pTimeout; /* actually passed */
FD_ZERO (&read_descs);
FD_ZERO (&write_descs);
FD_ZERO (&except_descs);
assert (pArray != (struct pollfd *) NULL);
/* Map the poll() file descriptor list in the select() data structures. */
max_fd = map_poll_spec (pArray, n_fds,
&read_descs, &write_descs, &except_descs);
/* Map the poll() timeout value in the select() timeout structure. */
pTimeout = map_timeout (timeout, &stime);
/* Make the select() call. */
ready_descriptors = select (max_fd + 1, &read_descs, &write_descs,
&except_descs, pTimeout);
if (ready_descriptors >= 0)
{
map_select_results (pArray, n_fds,
&read_descs, &write_descs, &except_descs);
}
return ready_descriptors;
}
-105
View File
@@ -1,105 +0,0 @@
/*---------------------------------------------------------------------------*\
$Id$
NAME
poll - select(2)-based poll() emulation function for BSD systems.
SYNOPSIS
#include "poll.h"
struct pollfd
{
int fd;
short events;
short revents;
}
int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)
DESCRIPTION
This file, and the accompanying "poll.c", implement the System V
poll(2) system call for BSD systems (which typically do not provide
poll()). Poll() provides a method for multiplexing input and output
on multiple open file descriptors; in traditional BSD systems, that
capability is provided by select(). While the semantics of select()
differ from those of poll(), poll() can be readily emulated in terms
of select() -- which is how this function is implemented.
REFERENCES
Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990.
NOTES
1. This software requires an ANSI C compiler.
LICENSE
This software is released under the following BSD license, adapted from
http://opensource.org/licenses/bsd-license.php
Copyright (c) 1995-2011, Brian M. Clapper
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the clapper.org nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*---------------------------------------------------------------------------*/
#ifndef _POLL_EMUL_H_
#define _POLL_EMUL_H_
#define POLLIN 0x01
#define POLLPRI 0x02
#define POLLOUT 0x04
#define POLLERR 0x08
#define POLLHUP 0x10
#define POLLNVAL 0x20
struct pollfd
{
int fd;
short events;
short revents;
};
typedef unsigned long nfds_t;
#ifdef __cplusplus
extern "C"
{
#endif
#if (__STDC__ > 0) || defined(__cplusplus)
extern int poll (struct pollfd *pArray, nfds_t n_fds, int timeout);
#else
extern int poll();
#endif
#ifdef __cplusplus
}
#endif
#endif /* _POLL_EMUL_H_ */
-1
View File
@@ -1 +0,0 @@
#include <poll.h>