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.
5
5
*
6
- * Requirements: zeromq2
6
+ * Requirements: zeromq2 or zeromq3.2
7
7
* gcc -lzmq -o universal-sub-pubsub universal-sub-pubsub.c
8
8
*
9
9
* Changes:
10
10
* - Initial version <[email protected] >
11
+ * - zeromq 3.2 compatibility added,
12
+ * pubsub binding bugfix <[email protected] >
11
13
*/
12
14
13
15
#include <stdio.h>
@@ -38,9 +40,14 @@ int main (int argc, char *argv[]) {
38
40
39
41
/* Apply a high water mark at the PubSub */
40
42
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
41
47
zmq_setsockopt (pubsub , ZMQ_HWM , & hwm , sizeof (hwm ));
48
+ #endif
42
49
43
- zmq_bind (pubsub , argv [2 ]);
50
+ zmq_bind (pubsub , argv [argc - 1 ]);
44
51
zmq_connect (subscriber , argv [1 ]);
45
52
46
53
/* Apply the subscriptions */
@@ -54,14 +61,26 @@ int main (int argc, char *argv[]) {
54
61
zmq_msg_t part ;
55
62
int rc = zmq_msg_init (& part );
56
63
assert (rc == 0 );
64
+
57
65
/* 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
58
69
rc = zmq_recv (subscriber , & part , 0 );
70
+ #endif
59
71
assert (rc == 0 );
72
+
60
73
/* Determine if more message parts are to follow */
61
74
rc = zmq_getsockopt (subscriber , ZMQ_RCVMORE , & more , & more_size );
62
75
assert (rc == 0 );
76
+
63
77
/* 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
64
81
zmq_send (pubsub , & part , (more ? ZMQ_SNDMORE : 0 ));
82
+ #endif
83
+
65
84
zmq_msg_close (& part );
66
85
} while (more );
67
86
}
0 commit comments