From 357a20ef6feae94c033eed392b025e57fe8eaa81 Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Mon, 30 Apr 2012 21:14:04 +0200 Subject: Conditionally include header files required by select() and poll() Feature checks are introduced to check for all the headers required by the select() and poll() calls. Include files are then included conditionally without the use of any OS-specific directive. The change also fixes a couple of problems: - Fixed compilation under FreeBSD, NetBSD and OpenBSD when forcing the use of select() in the poller - Quieted a warning mixed-sign comparison warning on FreeBSD caused by FD_SETSIZE being declared as an unsigned constant on that OS - Removed the obsolescent AC_HEADER_TIME macro from the configure script Signed-off-by: Gabriele Svelto --- configure.ac | 2 +- src/pgm_socket.cpp | 16 ++++++++++++---- src/poll.cpp | 4 ---- src/poll.hpp | 16 +++++++++++++++- src/select.cpp | 12 ++---------- src/select.hpp | 23 +++++++++++++++++------ src/signaler.hpp | 43 ++++++++++++++++++++++++++++++------------- src/upoll.cpp | 26 ++++++++++++++++++++++---- 8 files changed, 99 insertions(+), 43 deletions(-) diff --git a/configure.ac b/configure.ac index 0d8b404..339cc37 100644 --- a/configure.ac +++ b/configure.ac @@ -200,6 +200,7 @@ AC_CHECK_HEADERS([ \ string.h \ sys/socket.h \ sys/time.h \ + sys/types.h \ time.h \ unistd.h \ limits.h @@ -359,7 +360,6 @@ AS_IF([test "x$libxs_cv_[]_AC_LANG_ABBREV[]_intel_compiler" = "xyes"], [ AC_TYPE_SSIZE_T ]) -AC_HEADER_TIME AC_TYPE_UINT32_T AC_C_VOLATILE diff --git a/src/pgm_socket.cpp b/src/pgm_socket.cpp index 1c214a8..7747fe0 100644 --- a/src/pgm_socket.cpp +++ b/src/pgm_socket.cpp @@ -26,10 +26,18 @@ #ifdef XS_HAVE_WINDOWS #include "windows.hpp" -#endif - -#ifdef XS_HAVE_LINUX -#include +#else +# if HAVE_SYS_TYPES +# include +# endif +# if HAVE_SYS_SELECT_H +# include +# endif +# if HAVE_POLL_H +# include +# elif HAVE_SYS_POLL_H +# include +# endif #endif #include diff --git a/src/poll.cpp b/src/poll.cpp index 9f901fc..048de97 100644 --- a/src/poll.cpp +++ b/src/poll.cpp @@ -23,12 +23,8 @@ #if defined XS_USE_ASYNC_POLL -#include -#include -#include #include -#include "poll.hpp" #include "err.hpp" #include "config.hpp" diff --git a/src/poll.hpp b/src/poll.hpp index c192a77..879f4ee 100644 --- a/src/poll.hpp +++ b/src/poll.hpp @@ -26,8 +26,22 @@ #if defined XS_USE_ASYNC_POLL -#include #include + +#if HAVE_SYS_TYPES +# include +#endif + +#if HAVE_SYS_SELECT_H +# include +#endif + +#if HAVE_POLL_H +# include +#elif HAVE_SYS_POLL_H +# include +#endif + #include #include "fd.hpp" diff --git a/src/select.cpp b/src/select.cpp index 72346a4..1e3a7c4 100644 --- a/src/select.cpp +++ b/src/select.cpp @@ -24,17 +24,9 @@ #if defined XS_USE_ASYNC_SELECT #include "platform.hpp" + #if defined XS_HAVE_WINDOWS -#include "windows.hpp" -#elif defined XS_HAVE_HPUX -#include -#include -#include -#elif defined XS_HAVE_OPENVMS -#include -#include -#else -#include +# include "windows.hpp" #endif #include diff --git a/src/select.hpp b/src/select.hpp index df188eb..23ca4d7 100644 --- a/src/select.hpp +++ b/src/select.hpp @@ -31,13 +31,24 @@ #include #include -#ifdef XS_HAVE_WINDOWS -#include "winsock2.h" -#elif defined XS_HAVE_OPENVMS -#include -#include +#if defined XS_HAVE_WINDOWS +# include "winsock2.h" #else -#include +# if HAVE_SYS_TYPES_H +# include +# endif +# if HAVE_SYS_TIME_H +# include +# endif +# if HAVE_TIME_H +# include +# endif +# if HAVE_UNISTD_H +# include +# endif +# if HAVE_SYS_SELECT_H +# include +# endif #endif #include "fd.hpp" diff --git a/src/signaler.hpp b/src/signaler.hpp index a47763f..b94858f 100644 --- a/src/signaler.hpp +++ b/src/signaler.hpp @@ -29,20 +29,37 @@ // instead of 'events' and 'revents' and defines macros to map from POSIX-y // names to AIX-specific names). #if defined XS_USE_SYNC_POLL -#include +# if HAVE_SYS_TYPES +# include +# endif +# if HAVE_SYS_SELECT_H +# include +# endif +# if HAVE_POLL_H +# include +# elif HAVE_SYS_POLL_H +# include +# endif #elif defined XS_USE_SYNC_SELECT -#if defined XS_HAVE_WINDOWS -#include "windows.hpp" -#elif defined XS_HAVE_HPUX -#include -#include -#include -#elif defined XS_HAVE_OPENVMS -#include -#include -#else -#include -#endif +# if defined XS_HAVE_WINDOWS +# include "windows.hpp" +# else +# if HAVE_SYS_TYPES_H +# include +# endif +# if HAVE_SYS_TIME_H +# include +# endif +# if HAVE_TIME_H +# include +# endif +# if HAVE_UNISTD_H +# include +# endif +# if HAVE_SYS_SELECT_H +# include +# endif +# endif #endif namespace xs diff --git a/src/upoll.cpp b/src/upoll.cpp index 089a6a5..4d61b77 100644 --- a/src/upoll.cpp +++ b/src/upoll.cpp @@ -33,13 +33,31 @@ // instead of 'events' and 'revents' and defines macros to map from POSIX-y // names to AIX-specific names). #if defined XS_USE_SYNC_POLL -#include +# if HAVE_SYS_TYPES +# include +# endif +# if HAVE_SYS_SELECT_H +# include +# endif +# if HAVE_POLL_H +# include +# elif HAVE_SYS_POLL_H +# include +# endif #endif #if defined XS_HAVE_WINDOWS -#include "windows.hpp" +# include "windows.hpp" #else -#include +# if HAVE_SYS_TIME_H +# include +# endif +# if HAVE_TIME_H +# include +# endif +# if HAVE_UNISTD_H +# include +# endif #endif int xs::upoll (xs_pollitem_t *items_, int nitems_, int timeout_) @@ -227,7 +245,7 @@ int xs::upoll (xs_pollitem_t *items_, int nitems_, int timeout_) // Ensure we do not attempt to select () on more than FD_SETSIZE // file descriptors. - xs_assert (nitems_ <= FD_SETSIZE); + xs_assert (nitems_ <= (int)FD_SETSIZE); fd_set pollset_in; FD_ZERO (&pollset_in); -- cgit v1.2.3