Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

issue 270 showing SUB POLLIN error

  • Loading branch information...
commit 196c1c0f37eb97586bca7100d75f960dc4497208 1 parent a172a19
Chuck Remes authored
Showing with 99 additions and 0 deletions.
  1. +9 −0 270/3-0/README
  2. +45 −0 270/3-0/issue.c
  3. +45 −0 270/3-0/issue_works.c
View
9 270/3-0/README
@@ -0,0 +1,9 @@
+A SUB socket should have its socket EVENTS set to
+POLLIN when it has a message in queue. This works
+when the SUB socket *connects* and the PUB socket
+binds, but it FAILS when the SUB socket *binds* and
+the PUB socket connects.
+
+issue.c shows the failure.
+
+issue_works.c shows how it works with the connect/bind swapped
View
45 270/3-0/issue.c
@@ -0,0 +1,45 @@
+//
+// A SUB socket should always have ZMQ_POLLIN set
+// when it has a message in queue and ready to read.
+// FAILS when the SUB socket binds the socket.
+//
+// gcc -lzmq issue.c
+// chmod +x a.out
+// ./a.out
+//
+#include <zmq.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+
+
+int main (void)
+{
+ int rc;
+ void *context = zmq_init (1);
+ void *sender = zmq_socket (context, ZMQ_PUB);
+ void *receiver = zmq_socket (context, ZMQ_SUB);
+ assert (0 == zmq_setsockopt (receiver, ZMQ_SUBSCRIBE, "", 0));
+ assert (0 == zmq_bind (receiver, "tcp://127.0.0.1:7557"));
+ assert (0 == zmq_connect (sender, "tcp://127.0.0.1:7557"));
+ sleep (1);
+
+ zmq_msg_t m1, m2;
+ assert (0 == zmq_msg_init_data (&m1, "Hello world", 11, NULL, NULL));
+ assert (11 == zmq_sendmsg(sender, &m1, 0));
+ sleep (1);
+
+ unsigned int events;
+ size_t size = sizeof (events);
+ assert (0 == zmq_getsockopt(receiver, ZMQ_EVENTS, &events, &size));
+
+ // the test!
+ fprintf (stderr, "events [%d], pollin [%d]\n", events, ZMQ_POLLIN);
+ assert (events == ZMQ_POLLIN);
+
+ zmq_close (sender);
+ zmq_close (receiver);
+ zmq_term (context);
+ return (0);
+}
View
45 270/3-0/issue_works.c
@@ -0,0 +1,45 @@
+//
+// A SUB socket should always have ZMQ_POLLIN set
+// when it has a message in queue and ready to read.
+// SUCCEEDS only when the SUB socket connects (not binds).
+//
+// gcc -lzmq issue_works.c
+// chmod +x a.out
+// ./a.out
+//
+#include <zmq.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+
+
+int main (void)
+{
+ int rc;
+ void *context = zmq_init (1);
+ void *sender = zmq_socket (context, ZMQ_PUB);
+ void *receiver = zmq_socket (context, ZMQ_SUB);
+ assert (0 == zmq_setsockopt (receiver, ZMQ_SUBSCRIBE, "", 0));
+ assert (0 == zmq_connect (receiver, "tcp://127.0.0.1:7557"));
+ assert (0 == zmq_bind (sender, "tcp://127.0.0.1:7557"));
+ sleep (1);
+
+ zmq_msg_t m1, m2;
+ assert (0 == zmq_msg_init_data (&m1, "Hello world", 11, NULL, NULL));
+ assert (11 == zmq_sendmsg(sender, &m1, 0));
+ sleep (1);
+
+ unsigned int events;
+ size_t size = sizeof (events);
+ assert (0 == zmq_getsockopt(receiver, ZMQ_EVENTS, &events, &size));
+
+ // the test!
+ fprintf (stderr, "events [%d], pollin [%d]\n", events, ZMQ_POLLIN);
+ assert (events == ZMQ_POLLIN);
+
+ zmq_close (sender);
+ zmq_close (receiver);
+ zmq_term (context);
+ return (0);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.