summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.commkdir>2009-10-01 10:56:17 +0200
committerMartin Sustrik <sustrik@fastmq.commkdir>2009-10-01 10:56:17 +0200
commitcc631c4c6649b0d67114db13386a949426e35dbf (patch)
treefa558bc758a12d924dd81b3cd3cd27ebd7418aae /bindings
parentf2ff2c6e5c4e244dea28e1ac6ec3f886b7ebc356 (diff)
ZMQII-18: Implement I/O multiplexing (first approximation)
Diffstat (limited to 'bindings')
-rw-r--r--bindings/c/zmq.h33
-rw-r--r--bindings/cpp/zmq.hpp5
2 files changed, 38 insertions, 0 deletions
diff --git a/bindings/c/zmq.h b/bindings/c/zmq.h
index e939dcd..3eeb3f8 100644
--- a/bindings/c/zmq.h
+++ b/bindings/c/zmq.h
@@ -354,6 +354,39 @@ ZMQ_EXPORT int zmq_flush (void *s);
ZMQ_EXPORT int zmq_recv (void *s, zmq_msg_t *msg, int flags);
////////////////////////////////////////////////////////////////////////////////
+// I/O multiplexing.
+////////////////////////////////////////////////////////////////////////////////
+
+#define ZMQ_POLLIN 1
+#define ZMQ_POLLOUT 2
+
+// 'socket' is a 0MQ socket we want to poll on. If set to NULL, native file
+// descriptor (socket) 'fd' will be used instead. 'events' defines event we
+// are going to poll on - combination of ZMQ_POLLIN and ZMQ_POLLOUT. Error
+// event does not exist for portability reasons. Errors from native sockets
+// are reported as ZMQ_POLLIN. It's client's responsibilty to identify the
+// error afterwards. 'revents' field is filled in after function returns. It's
+// a combination of ZMQ_POLLIN and/or ZMQ_POLLOUT depending on the state of the
+// socket.
+typedef struct
+{
+ void *socket;
+ int fd;
+ short events;
+ short revents;
+} zmq_pollitem_t;
+
+// Polls for the items specified by 'items'. Number of items in the array is
+// determined by 'nitems' argument. Returns number of items signaled, -1
+// in the case of error.
+//
+// Errors: EFAULT - there's a 0MQ socket in the pollset belonging to
+// a different thread.
+// ENOTSUP - 0MQ context was initialised without ZMQ_POLL flag.
+// I/O multiplexing is disabled.
+ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems);
+
+////////////////////////////////////////////////////////////////////////////////
// Helper functions.
////////////////////////////////////////////////////////////////////////////////
diff --git a/bindings/cpp/zmq.hpp b/bindings/cpp/zmq.hpp
index 5c0ba7c..8a00230 100644
--- a/bindings/cpp/zmq.hpp
+++ b/bindings/cpp/zmq.hpp
@@ -200,6 +200,11 @@ namespace zmq
throw error_t ();
}
+ inline operator void* ()
+ {
+ return ptr;
+ }
+
inline void setsockopt (int option_, const void *optval_,
size_t optvallen_)
{