Skip to content

Instantly share code, notes, and snippets.

@sustrik
Created March 20, 2011 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sustrik/878554 to your computer and use it in GitHub Desktop.
Save sustrik/878554 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <zmq.hpp>
int main ()
{
zmq::context_t ctx (1);
zmq::socket_t b (ctx, ZMQ_PUSH);
b.bind ("tcp://lo:5555");
zmq::socket_t c1 (ctx, ZMQ_PULL);
c1.connect ("tcp://localhost:5555");
zmq::message_t msg1;
b.send (msg1, ZMQ_SNDMORE);
c1.close ();
sleep (1);
zmq::socket_t c2 (ctx, ZMQ_PULL);
c2.connect ("tcp://localhost:5555");
zmq::message_t msg2;
b.send (msg2);
int64_t more;
size_t more_size = sizeof (more);
printf ("before recv\n");
zmq::message_t msg3;
c2.recv (&msg3);
c2.getsockopt (ZMQ_RCVMORE, &more, &more_size);
assert (more != 0);
printf ("first part recvd\n");
c2.recv (&msg3);
c2.getsockopt (ZMQ_RCVMORE, &more, &more_size);
assert (more == 0);
printf ("second part recvd\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment