1ZMQ_CPP(7) 0MQ Manual ZMQ_CPP(7)
2
3
4
6 zmq_cpp - interface between 0MQ and C++ applications
7
9 #include <zmq.hpp>
10
11 c++ [flags] files -lzmq [libraries]
12
14 This manual page describes how the 0MQ C++ language binding maps to the
15 underlying 0MQ C library functions.
16
17 All 0MQ constants defined by zmq.h are also available to the C++
18 language binding.
19
20 The following classes are provided in the zmq namespace:
21
22 Context
23 The context_t class encapsulates functionality dealing with the
24 initialisation and termination of a 0MQ context.
25
26 Constructor
27 context_t::context_t(int io_threads)
28
29 Maps to the zmq_init() function, as described in zmq_init(3).
30
31 Destructor
32 context_t::~context_t(void)
33
34 Maps to the zmq_term() function, as described in zmq_term(3).
35
36 Methods
37 None.
38
39 Socket
40 The socket_t class encapsulates a 0MQ socket.
41
42 Constructor
43 socket_t::socket_t(context_t &context, int type)
44
45 Maps to the zmq_socket() function, as described in zmq_socket(3).
46
47 Destructor
48 socket_t::~socket_t(void)
49
50 Calls the zmq_close() function, as described in zmq_close(3).
51
52 Methods
53 void socket_t::getsockopt(int option_name, void *option_value, size_t
54 *option_len)
55
56 Maps to the zmq_getsockopt() function, as described in
57 zmq_getsockopt(3).
58
59 void socket_t::setsockopt(int option_name, const void *option_value, size_t
60 option_len)
61
62 Maps to the zmq_setsockopt() function, as described in
63 zmq_setsockopt(3).
64
65 void socket_t::bind(const char *endpoint)
66
67 Maps to the zmq_bind() function, as described in zmq_bind(3).
68
69 void socket_t::connect(const char *endpoint)
70
71 Maps to the zmq_connect() function, as described in zmq_connect(3).
72
73 bool socket_t::send(message_t &msg, int flags = 0)
74
75 Maps to the zmq_send() function, as described in zmq_send(3).
76 Returns true if message is successfully sent, false if it is not.
77
78 bool socket_t::recv(message_t *msg, int flags = 0)
79
80 Maps to the zmq_recv() function, as described in zmq_recv(3).
81 Returns true if message is successfully received, false if it is
82 not.
83
84 Message
85 The zmq::message_t class encapsulates the zmq_msg_t structure and
86 functions to construct, destruct and manipulate 0MQ messages.
87
88 Constructor
89 message_t::message_t(void)
90 message_t::message_t(size_t size)
91 message_t::message_t(void *data, size_t size, free_fn *ffn)
92
93 These map to the zmq_msg_init(), zmq_msg_init_size() and
94 zmq_msg_init_data() functions, described in zmq_msg_init(3),
95 zmq_msg_init_size(3) and zmq_msg_init_data(3) respectively.
96
97 Destructor
98 message_t::~message_t(void)
99
100 Calls the zmq_msg_close() function, as described in
101 zmq_msg_close(3).
102
103 Methods
104 void *message_t::data (void)
105
106 Maps to the zmq_msg_data() function, as described in
107 zmq_msg_data(3).
108
109 size_t message_t::size (void)
110
111 Maps to the zmq_msg_size() function, as described in
112 zmq_msg_size(3).
113
114 void message_t::copy (message_t *src)
115
116 Maps to the zmq_msg_copy() function, as described in
117 zmq_msg_copy(3).
118
119 void message_t::move (message_t *src)
120
121 Maps to the zmq_msg_move() function, as described in
122 zmq_msg_move(3).
123
124 message_t::rebuild(void)
125 message_t::rebuild(size_t size)
126 message_t::rebuild(void *data, size_t size, free_fn *ffn)
127
128 Equivalent to calling the zmq_msg_close() function followed by the
129 corresponding zmq_msg_init() function.
130
131 Input/output multiplexing
132 int poll (zmq_pollitem_t *items, int nitems, long timeout = -1)
133
134 The poll() function is a namespaced equivalent of the zmq_poll()
135 function, as described in zmq_poll(3).
136
137 Note
138 To obtain a 0MQ socket for use in a zmq_pollitem_t structure, you
139 should cast an instance of the socket_t class to (void *).
140
142 All errors reported by the underlying 0MQ C library functions are
143 automatically converted to exceptions by the C++ language binding. The
144 zmq::error_t class is derived from the std::exception class and uses
145 the zmq_strerror() function to convert the error code to human-readable
146 string.
147
149 zmq::context_t ctx (1);
150 zmq::socket_t s (ctx, ZMQ_PUB);
151 s.connect ("tcp://192.168.0.115:5555");
152 zmq::message_t msg (100);
153 memset (msg.data (), 0, 100);
154 s.send (msg);
155
157 zmq(7)
158
160 This 0MQ manual page was written by Martin Sustrik
161 <sustrik@250bpm.com[1]> and Martin Lucina <mato@kotelna.sk[2]>.
162
164 1. sustrik@250bpm.com
165 mailto:sustrik@250bpm.com
166
167 2. mato@kotelna.sk
168 mailto:mato@kotelna.sk
169
170
171
1720MQ 2.1.4 03/30/2011 ZMQ_CPP(7)