Skip to content

Instantly share code, notes, and snippets.

@sustrik
Created October 2, 2011 14:23
Show Gist options
  • Select an option

  • Save sustrik/1257494 to your computer and use it in GitHub Desktop.

Select an option

Save sustrik/1257494 to your computer and use it in GitHub Desktop.
#include <zmq.hpp>
#include <stdio.h>
#include <stdint.h>
int main ()
{
zmq::context_t context (1);
zmq::socket_t s (context, ZMQ_DEALER);
uint64_t hwm = 1;
s.setsockopt (ZMQ_HWM, &hwm, sizeof (uint64_t));
s.bind ("tcp://*:11132");
zmq::pollitem_t items [1];
items [0].socket = s;
items [0].fd = 0;
items [0].events = ZMQ_POLLIN | ZMQ_POLLOUT;
items [0].revents = 0;
while (true)
{
int rc = zmq::poll (&items [0], 1, -1);
assert (rc > 0);
// ACK coming in
if (items [0].revents & ZMQ_POLLIN) {
zmq::message_t msg;
s.recv (&msg);
static int got_ack = 0;
got_ack++;
printf ("Got ACK: %d\n", got_ack);
}
// Sending messages out
if (items [0].revents & ZMQ_POLLOUT) {
while (true)
{
zmq::message_t msg (10);
if (!s.send (msg, ZMQ_NOBLOCK))
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment