Created
October 2, 2011 14:23
-
-
Save sustrik/1257494 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #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