summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builds/msvc/libxs/libxs.vcxproj3
-rw-r--r--builds/msvc/libxs/libxs.vcxproj.filters5
-rw-r--r--src/Makefile.am1
-rw-r--r--src/devpoll.cpp3
-rw-r--r--src/devpoll.hpp4
-rw-r--r--src/epoll.cpp2
-rw-r--r--src/epoll.hpp4
-rw-r--r--src/io_thread.cpp11
-rw-r--r--src/kqueue.cpp3
-rw-r--r--src/kqueue.hpp5
-rw-r--r--src/poll.cpp2
-rw-r--r--src/poll.hpp4
-rw-r--r--src/polling.hpp68
-rw-r--r--src/select.cpp2
-rw-r--r--src/select.hpp4
-rw-r--r--src/signaler.cpp32
-rw-r--r--src/upoll.cpp32
17 files changed, 110 insertions, 75 deletions
diff --git a/builds/msvc/libxs/libxs.vcxproj b/builds/msvc/libxs/libxs.vcxproj
index d4f40ca..229d7ec 100644
--- a/builds/msvc/libxs/libxs.vcxproj
+++ b/builds/msvc/libxs/libxs.vcxproj
@@ -206,6 +206,7 @@
<ClInclude Include="..\..\..\src\pgm_socket.hpp" />
<ClInclude Include="..\..\..\src\pipe.hpp" />
<ClInclude Include="..\..\..\src\poll.hpp" />
+ <ClInclude Include="..\..\..\src\polling.hpp" />
<ClInclude Include="..\..\..\src\precompiled.hpp" />
<ClInclude Include="..\..\..\src\prefix_filter.hpp" />
<ClInclude Include="..\..\..\src\pub.hpp" />
@@ -244,4 +245,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/builds/msvc/libxs/libxs.vcxproj.filters b/builds/msvc/libxs/libxs.vcxproj.filters
index 1fefb60..a1b80e3 100644
--- a/builds/msvc/libxs/libxs.vcxproj.filters
+++ b/builds/msvc/libxs/libxs.vcxproj.filters
@@ -301,6 +301,9 @@
<ClInclude Include="..\..\..\src\poll.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\src\polling.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\..\..\src\precompiled.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@@ -413,4 +416,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/Makefile.am b/src/Makefile.am
index 3025e13..03b6381 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,6 +55,7 @@ libxs_la_SOURCES = \
pipe.hpp \
platform.hpp \
poll.hpp \
+ polling.hpp \
pair.hpp \
prefix_filter.hpp \
pub.hpp \
diff --git a/src/devpoll.cpp b/src/devpoll.cpp
index 76943f0..2fbd1c1 100644
--- a/src/devpoll.cpp
+++ b/src/devpoll.cpp
@@ -21,7 +21,7 @@
#include "devpoll.hpp"
-#if defined XS_HAVE_DEVPOLL
+#if defined XS_USE_ASYNC_DEVPOLL
#include <sys/devpoll.h>
#include <sys/time.h>
@@ -33,6 +33,7 @@
#include <limits.h>
#include <algorithm>
+#include "platform.hpp"
#include "devpoll.hpp"
#include "err.hpp"
#include "config.hpp"
diff --git a/src/devpoll.hpp b/src/devpoll.hpp
index 3e35a99..975b442 100644
--- a/src/devpoll.hpp
+++ b/src/devpoll.hpp
@@ -22,9 +22,9 @@
#ifndef __XS_DEVPOLL_HPP_INCLUDED__
#define __XS_DEVPOLL_HPP_INCLUDED__
-#include "platform.hpp"
+#include "polling.hpp"
-#if defined XS_HAVE_DEVPOLL
+#if defined XS_USE_ASYNC_DEVPOLL
#include <vector>
diff --git a/src/epoll.cpp b/src/epoll.cpp
index 8ba2f17..ecdee1a 100644
--- a/src/epoll.cpp
+++ b/src/epoll.cpp
@@ -21,7 +21,7 @@
#include "epoll.hpp"
-#if defined XS_HAVE_EPOLL
+#if defined XS_USE_ASYNC_EPOLL
#include <sys/epoll.h>
#include <stdlib.h>
diff --git a/src/epoll.hpp b/src/epoll.hpp
index 595168e..6d2f8be 100644
--- a/src/epoll.hpp
+++ b/src/epoll.hpp
@@ -22,9 +22,9 @@
#ifndef __XS_EPOLL_HPP_INCLUDED__
#define __XS_EPOLL_HPP_INCLUDED__
-#include "platform.hpp"
+#include "polling.hpp"
-#if defined XS_HAVE_EPOLL
+#if defined XS_USE_ASYNC_EPOLL
#include <vector>
#include <sys/epoll.h>
diff --git a/src/io_thread.cpp b/src/io_thread.cpp
index df5a623..c363592 100644
--- a/src/io_thread.cpp
+++ b/src/io_thread.cpp
@@ -21,6 +21,7 @@
#include "io_thread.hpp"
#include "err.hpp"
+#include "polling.hpp"
#include "select.hpp"
#include "poll.hpp"
#include "epoll.hpp"
@@ -30,15 +31,15 @@
xs::io_thread_t *xs::io_thread_t::create (xs::ctx_t *ctx_, uint32_t tid_)
{
io_thread_t *result;
-#if defined XS_HAVE_SELECT
+#if defined XS_USE_ASYNC_SELECT
result = new (std::nothrow) select_t (ctx_, tid_);
-#elif defined XS_HAVE_POLL
+#elif defined XS_USE_ASYNC_POLL
result = new (std::nothrow) poll_t (ctx_, tid_);
-#elif defined XS_HAVE_EPOLL
+#elif defined XS_USE_ASYNC_EPOLL
result = new (std::nothrow) epoll_t (ctx_, tid_);
-#elif defined XS_HAVE_DEVPOLL
+#elif defined XS_USE_ASYNC_DEVPOLL
result = new (std::nothrow) devpoll_t (ctx_, tid_);
-#elif defined XS_HAVE_KQUEUE
+#elif defined XS_USE_ASYNC_KQUEUE
result = new (std::nothrow) kqueue_t (ctx_, tid_);
#endif
alloc_assert (result);
diff --git a/src/kqueue.cpp b/src/kqueue.cpp
index c3ef5b5..06e22d3 100644
--- a/src/kqueue.cpp
+++ b/src/kqueue.cpp
@@ -21,7 +21,7 @@
#include "kqueue.hpp"
-#if defined XS_HAVE_KQUEUE
+#if defined XS_USE_ASYNC_KQUEUE
#include <sys/time.h>
#include <sys/types.h>
@@ -31,6 +31,7 @@
#include <algorithm>
#include <new>
+#include "platform.hpp"
#include "kqueue.hpp"
#include "err.hpp"
#include "config.hpp"
diff --git a/src/kqueue.hpp b/src/kqueue.hpp
index 3aaa10b..862458b 100644
--- a/src/kqueue.hpp
+++ b/src/kqueue.hpp
@@ -22,8 +22,9 @@
#ifndef __XS_KQUEUE_HPP_INCLUDED__
#define __XS_KQUEUE_HPP_INCLUDED__
-#include "platform.hpp"
-#if defined XS_HAVE_KQUEUE
+#include "polling.hpp"
+
+#if defined XS_USE_ASYNC_KQUEUE
#include <vector>
diff --git a/src/poll.cpp b/src/poll.cpp
index c0f070e..9f901fc 100644
--- a/src/poll.cpp
+++ b/src/poll.cpp
@@ -21,7 +21,7 @@
#include "poll.hpp"
-#if defined XS_HAVE_POLL
+#if defined XS_USE_ASYNC_POLL
#include <sys/types.h>
#include <sys/time.h>
diff --git a/src/poll.hpp b/src/poll.hpp
index 2df1796..c192a77 100644
--- a/src/poll.hpp
+++ b/src/poll.hpp
@@ -22,9 +22,9 @@
#ifndef __XS_POLL_HPP_INCLUDED__
#define __XS_POLL_HPP_INCLUDED__
-#include "platform.hpp"
+#include "polling.hpp"
-#if defined XS_HAVE_POLL
+#if defined XS_USE_ASYNC_POLL
#include <poll.h>
#include <stddef.h>
diff --git a/src/polling.hpp b/src/polling.hpp
new file mode 100644
index 0000000..b8f0540
--- /dev/null
+++ b/src/polling.hpp
@@ -0,0 +1,68 @@
+/*
+ Copyright (c) 2012 250bpm s.r.o.
+ Copyright (c) 2012 Other contributors as noted in the AUTHORS file
+
+ This file is part of Crossroads I/O project.
+
+ Crossroads I/O is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Crossroads 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __XS_CORE_HPP_INCLUDED__
+#define __XS_CORE_HPP_INCLUDED__
+
+#include "platform.hpp"
+
+// This header file contains code that decides what polling mechanisms
+// should be used in individual cases. It also includes appropriate headers.
+//
+// ASYNC polling mechanism to drive event loops in the I/O threads.
+// SYNC polling mechanism is used in xs_poll() and for blocking API functions.
+
+#if defined XS_FORCE_SELECT
+#define XS_USE_ASYNC_SELECT
+#elif defined XS_FORCE_POLL
+#define XS_USE_ASYNC_POLL
+#elif defined XS_FORCE_EPOLL
+#define XS_USE_ASYNC_EPOLL
+#elif defined XS_FORCE_DEVPOLL
+#define XS_USE_ASYNC_DEVPOLL
+#elif defined XS_FORCE_KQUEUE
+#define XS_USE_ASYNC_KQUEUE
+#elif defined XS_HAVE_EPOLL
+#define XS_USE_ASYNC_EPOLL
+#elif defined XS_HAVE_DEVPOLL
+#define XS_USE_ASYNC_DEVPOLL
+#elif defined XS_HAVE_KQUEUE
+#define XS_USE_ASYNC_KQUEUE
+#elif defined XS_HAVE_POLL
+#define XS_USE_ASYNC_POLL
+#elif defined XS_HAVE_SELECT
+#define XS_USE_ASYNC_SELECT
+#else
+#error No polling mechanism available!
+#endif
+
+#if defined XS_FORCE_SELECT
+#define XS_USE_SYNC_SELECT
+#elif defined XS_FORCE_POLL
+#define XS_USE_SYNC_POLL
+#elif defined XS_HAVE_POLL
+#define XS_USE_SYNC_POLL
+#elif defined XS_HAVE_SELECT
+#define XS_USE_SYNC_SELECT
+#else
+#error No polling mechanism available!
+#endif
+
+#endif
diff --git a/src/select.cpp b/src/select.cpp
index eeac5a9..72346a4 100644
--- a/src/select.cpp
+++ b/src/select.cpp
@@ -21,7 +21,7 @@
#include "select.hpp"
-#if defined XS_HAVE_SELECT
+#if defined XS_USE_ASYNC_SELECT
#include "platform.hpp"
#if defined XS_HAVE_WINDOWS
diff --git a/src/select.hpp b/src/select.hpp
index ea2831d..df188eb 100644
--- a/src/select.hpp
+++ b/src/select.hpp
@@ -22,9 +22,9 @@
#ifndef __XS_SELECT_HPP_INCLUDED__
#define __XS_SELECT_HPP_INCLUDED__
-#include "platform.hpp"
+#include "polling.hpp"
-#if defined XS_HAVE_SELECT
+#if defined XS_USE_ASYNC_SELECT
#include "platform.hpp"
diff --git a/src/signaler.cpp b/src/signaler.cpp
index 8832c6b..1f754f6 100644
--- a/src/signaler.cpp
+++ b/src/signaler.cpp
@@ -19,29 +19,15 @@
*/
#include "platform.hpp"
-
-#if defined XS_HAVE_SELECT
-#define XS_SIGNALER_WAIT_BASED_ON_SELECT
-#elif defined XS_HAVE_POLL
-#define XS_SIGNALER_WAIT_BASED_ON_POLL
-#elif defined XS_HAVE_LINUX || defined XS_HAVE_FREEBSD ||\
- defined XS_HAVE_OPENBSD || defined XS_HAVE_SOLARIS ||\
- defined XS_HAVE_OSX || defined XS_HAVE_QNXNTO ||\
- defined XS_HAVE_HPUX || defined XS_HAVE_AIX ||\
- defined XS_HAVE_NETBSD
-#define XS_SIGNALER_WAIT_BASED_ON_POLL
-#elif defined XS_HAVE_WINDOWS || defined XS_HAVE_OPENVMS ||\
- defined XS_HAVE_CYGWIN
-#define XS_SIGNALER_WAIT_BASED_ON_SELECT
-#endif
+#include "polling.hpp"
// On AIX, poll.h has to be included before xs.h to get consistent
// definition of pollfd structure (AIX uses 'reqevents' and 'retnevents'
// instead of 'events' and 'revents' and defines macros to map from POSIX-y
// names to AIX-specific names).
-#if defined XS_SIGNALER_WAIT_BASED_ON_POLL
+#if defined XS_USE_SYNC_POLL
#include <poll.h>
-#elif defined XS_SIGNALER_WAIT_BASED_ON_SELECT
+#elif defined XS_USE_SYNC_SELECT
#if defined XS_HAVE_WINDOWS
#include "windows.hpp"
#elif defined XS_HAVE_HPUX
@@ -357,7 +343,7 @@ void xs::signaler_send (xs::signaler_t *self_)
int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
{
-#ifdef XS_SIGNALER_WAIT_BASED_ON_POLL
+#ifdef XS_USE_SYNC_POLL
struct pollfd pfd;
pfd.fd = self_->r;
@@ -375,7 +361,7 @@ int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
xs_assert (pfd.revents & POLLIN);
return 0;
-#elif defined XS_SIGNALER_WAIT_BASED_ON_SELECT
+#elif defined XS_USE_SYNC_SELECT
fd_set fds;
FD_ZERO (&fds);
@@ -406,6 +392,7 @@ int xs::signaler_wait (xs::signaler_t *self_, int timeout_)
#else
#error
+ return -1;
#endif
}
@@ -441,10 +428,3 @@ void xs::signaler_recv (xs::signaler_t *self_)
#endif
}
-#if defined XS_SIGNALER_WAIT_BASED_ON_SELECT
-#undef XS_SIGNALER_WAIT_BASED_ON_SELECT
-#endif
-#if defined XS_SIGNALER_WAIT_BASED_ON_POLL
-#undef XS_SIGNALER_WAIT_BASED_ON_POLL
-#endif
-
diff --git a/src/upoll.cpp b/src/upoll.cpp
index d99deec..089a6a5 100644
--- a/src/upoll.cpp
+++ b/src/upoll.cpp
@@ -26,27 +26,13 @@
#include "clock.hpp"
#include "likely.hpp"
#include "platform.hpp"
-
-#if defined XS_HAVE_SELECT
-#define XS_POLL_BASED_ON_SELECT
-#elif defined XS_HAVE_POLL
-#define XS_POLL_BASED_ON_POLL
-#elif defined XS_HAVE_LINUX || defined XS_HAVE_FREEBSD ||\
- defined XS_HAVE_OPENBSD || defined XS_HAVE_SOLARIS ||\
- defined XS_HAVE_OSX || defined XS_HAVE_QNXNTO ||\
- defined XS_HAVE_HPUX || defined XS_HAVE_AIX ||\
- defined XS_HAVE_NETBSD
-#define XS_POLL_BASED_ON_POLL
-#elif defined XS_HAVE_WINDOWS || defined XS_HAVE_OPENVMS ||\
- defined XS_HAVE_CYGWIN
-#define XS_POLL_BASED_ON_SELECT
-#endif
+#include "polling.hpp"
// On AIX platform, poll.h has to be included first to get consistent
// definition of pollfd structure (AIX uses 'reqevents' and 'retnevents'
// instead of 'events' and 'revents' and defines macros to map from POSIX-y
// names to AIX-specific names).
-#if defined XS_POLL_BASED_ON_POLL
+#if defined XS_USE_SYNC_POLL
#include <poll.h>
#endif
@@ -58,7 +44,7 @@
int xs::upoll (xs_pollitem_t *items_, int nitems_, int timeout_)
{
-#if defined XS_POLL_BASED_ON_POLL
+#if defined XS_USE_SYNC_POLL
if (unlikely (nitems_ < 0)) {
errno = EINVAL;
return -1;
@@ -213,7 +199,7 @@ int xs::upoll (xs_pollitem_t *items_, int nitems_, int timeout_)
free (pollfds);
return nevents;
-#elif defined XS_POLL_BASED_ON_SELECT
+#elif defined XS_USE_SYNC_SELECT
if (unlikely (nitems_ < 0)) {
errno = EINVAL;
@@ -403,15 +389,7 @@ int xs::upoll (xs_pollitem_t *items_, int nitems_, int timeout_)
return nevents;
#else
- // Exotic platforms that support neither poll() nor select().
- errno = ENOTSUP;
- return -1;
+#error
#endif
}
-#if defined XS_POLL_BASED_ON_SELECT
-#undef XS_POLL_BASED_ON_SELECT
-#endif
-#if defined XS_POLL_BASED_ON_POLL
-#undef XS_POLL_BASED_ON_POLL
-#endif