Skip to content

Instantly share code, notes, and snippets.

@hintjens hintjens/issue.c
Last active Jan 1, 2017

Embed
What would you like to do?
Workaround for issue LIBZMQ-270
#include <zmq.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
int main (void)
{
void *ctx = zmq_ctx_new ();
assert (ctx);
void *pub = zmq_socket (ctx, ZMQ_PUB);
assert (pub);
int rc;
void *sub = zmq_socket (ctx, ZMQ_SUB);
rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0);
assert (rc == 0);
rc = zmq_bind (sub, "tcp://127.0.0.1:5555");
assert (rc >= 0);
rc = zmq_connect (pub, "tcp://127.0.0.1:5555");
assert (rc >= 0);
zmq_pollitem_t pollitems [] = { { sub, 0, ZMQ_POLLIN, 0 } };
zmq_poll (pollitems, 1, 1);
rc = zmq_send (pub, "TEST", 5, 0);
assert (rc == 5);
char buffer [5];
puts ("Waiting for message");
rc = zmq_recv (sub, buffer, 5, 0);
assert (rc == 5);
assert (strcmp (buffer, "TEST") == 0);
puts (" OK");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.