Skip to content

Commit 0114b57

Browse files
committed
Bugfixes and ZeroMQ3 compatibility by Peter Fokkinga.
1 parent b1e06ab commit 0114b57

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

universal-sub-pubsub.c

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
/* This software is the client component of the ND-OV system
2-
* each multipart message it receives from the ND-OV system
3-
* consisting of an envelope and its data, is received and
4-
* rebroadcasted to all connected clients of the serviceprovider.
1+
/* This software is the client component of the ND-OV system.
2+
* Each multipart message it receives from the ND-OV system
3+
* consisting of an envelope and its data is rebroadcasted
4+
* to all connected clients of the serviceprovider.
55
*
6-
* Requirements: zeromq2
6+
* Requirements: zeromq2 or zeromq3.2
77
* gcc -lzmq -o universal-sub-pubsub universal-sub-pubsub.c
88
*
99
* Changes:
1010
* - Initial version <[email protected]>
11+
* - zeromq 3.2 compatibility added,
12+
* pubsub binding bugfix <[email protected]>
1113
*/
1214

1315
#include <stdio.h>
@@ -38,9 +40,14 @@ int main (int argc, char *argv[]) {
3840

3941
/* Apply a high water mark at the PubSub */
4042
uint64_t hwm = 255;
43+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
44+
zmq_setsockopt(pubsub, ZMQ_SNDHWM, &hwm, sizeof(hwm));
45+
zmq_setsockopt(pubsub, ZMQ_RCVHWM, &hwm, sizeof(hwm));
46+
#else
4147
zmq_setsockopt(pubsub, ZMQ_HWM, &hwm, sizeof(hwm));
48+
#endif
4249

43-
zmq_bind (pubsub, argv[2]);
50+
zmq_bind (pubsub, argv[argc - 1]);
4451
zmq_connect (subscriber, argv[1]);
4552

4653
/* Apply the subscriptions */
@@ -54,14 +61,26 @@ int main (int argc, char *argv[]) {
5461
zmq_msg_t part;
5562
int rc = zmq_msg_init (&part);
5663
assert (rc == 0);
64+
5765
/* Block until a message is available to be received from the socket */
66+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
67+
rc = zmq_recvmsg (subscriber, &part, 0);
68+
#else
5869
rc = zmq_recv (subscriber, &part, 0);
70+
#endif
5971
assert (rc == 0);
72+
6073
/* Determine if more message parts are to follow */
6174
rc = zmq_getsockopt (subscriber, ZMQ_RCVMORE, &more, &more_size);
6275
assert (rc == 0);
76+
6377
/* Send the message, when more is set, apply the flag, otherwise don't */
78+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
79+
zmq_sendmsg (pubsub, &part, (more ? ZMQ_SNDMORE : 0));
80+
#else
6481
zmq_send (pubsub, &part, (more ? ZMQ_SNDMORE : 0));
82+
#endif
83+
6584
zmq_msg_close (&part);
6685
} while (more);
6786
}

0 commit comments

Comments
 (0)