aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/core/platform.h24
-rw-r--r--src/platform/posix/posix_impl.h1
-rw-r--r--src/platform/windows/win_impl.h2
-rw-r--r--src/platform/windows/win_net.c2
-rw-r--r--tests/tcp.c1
7 files changed, 31 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af8d03f1..190e75fc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -97,6 +97,7 @@ option (NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package (Threads REQUIRED)
add_definitions (-DPLATFORM_POSIX)
+ add_definitions (-DNNG_USE_EVENTFD)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
find_package (Threads REQUIRED)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2df849ae..82d7205d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -71,6 +71,7 @@ set (NNG_SOURCES
platform/posix/posix_debug.c
platform/posix/posix_ipc.c
platform/posix/posix_net.c
+ platform/posix/posix_pipe.c
platform/posix/posix_rand.c
platform/posix/posix_thread.c
@@ -79,6 +80,7 @@ set (NNG_SOURCES
platform/windows/win_debug.c
platform/windows/win_ipc.c
platform/windows/win_net.c
+ platform/windows/win_pipe.c
platform/windows/win_rand.c
platform/windows/win_thread.c
diff --git a/src/core/platform.h b/src/core/platform.h
index 7afd33ef..14b3aaed 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -256,6 +256,30 @@ extern int nni_plat_ipc_recv(nni_plat_ipcsock *, nni_iov *, int);
// to seed up to 256 bytes of data.
extern void nni_plat_seed_prng(void *, size_t);
+// nni_plat_pipe creates a pair of linked file descriptors that are
+// suitable for notification via SENDFD/RECVFD. These are platform
+// specific and exposed to applications for integration into event loops.
+// The first pipe is written to by nng to notify, and the second pipe is
+// generally read from to clear the event. The implementation is not
+// obliged to provide two pipes -- for example eventfd can be used with
+// just a single file descriptor. In such a case the implementation may
+// just provide the same value twice.
+extern int nni_plat_pipe_open(int *, int *);
+
+// nni_plat_pipe_push pushses a notification to the pipe. Usually this
+// will just be a non-blocking attempt to write a single byte. It may
+// however use any other underlying system call that is appropriate.
+extern void nni_plat_pipe_push(int);
+
+// nni_plat_pipe_pull pulls a notification from the pipe. Usually this
+// will just be a non-blocking read. (The pull should attempt to read
+// all data on the pipe.)
+extern void nni_plat_pipe_pull(int);
+
+// nni_plat_pipe_close closes both pipes that were provided by the open
+// routine.
+extern void nni_plat_pipe_close(int, int);
+
// Actual platforms we support. This is included up front so that we can
// get the specific types that are supplied by the platform.
#if defined(PLATFORM_POSIX)
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 3faebfd4..56cc5937 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -22,6 +22,7 @@
#define PLATFORM_POSIX_CLOCK
#define PLATFORM_POSIX_IPC
#define PLATFORM_POSIX_NET
+#define PLATFORM_POSIX_PIPE
#define PLATFORM_POSIX_RANDOM
#define PLATFORM_POSIX_THREAD
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h
index e63553a5..7bb71707 100644
--- a/src/platform/windows/win_impl.h
+++ b/src/platform/windows/win_impl.h
@@ -69,6 +69,8 @@ struct nni_plat_cv {
CRITICAL_SECTION * cs;
};
+extern int nni_winsock_error(int);
+
#endif // PLATFORM_WINDOWS
#endif // PLATFORM_WIN_IMPL_H
diff --git a/src/platform/windows/win_net.c b/src/platform/windows/win_net.c
index cd5862ff..678ccfb9 100644
--- a/src/platform/windows/win_net.c
+++ b/src/platform/windows/win_net.c
@@ -84,7 +84,7 @@ nni_plat_wsa_errnos[] = {
};
-static int
+int
nni_winsock_error(int werr)
{
int i;
diff --git a/tests/tcp.c b/tests/tcp.c
index 73039e64..f77ec3a0 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -40,6 +40,5 @@ TestMain("TCP Transport", {
})
So(nng_listen(s1, "tcp://*:5771", NULL, NNG_FLAG_SYNCH) == 0);
So(nng_dial(s2, "tcp://127.0.0.1:5771", NULL, NNG_FLAG_SYNCH) == 0);
- fflush(stdout);
})
})