-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chuck Remes
committed
Oct 17, 2011
1 parent
a172a19
commit 196c1c0
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
} |