zmq_cpp.txt 4.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
zmq_cpp(7)
==========


NAME
----
zmq_cpp - interface between 0MQ and C++ applications


SYNOPSIS
--------
12
*#include <zmq.hpp>*
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
*c$$++$$* ['flags'] 'files' *-lzmq* ['libraries']


DESCRIPTION
-----------
This manual page describes how the 0MQ C++ language binding maps to the
underlying 0MQ C library functions. 

All 0MQ constants defined by _zmq.h_ are also available to the C++ language
binding.

The following classes are provided in the 'zmq' namespace:


Context
~~~~~~~
The 'context_t' class encapsulates functionality dealing with the
initialisation and termination of a 0MQ _context_.


Constructor
^^^^^^^^^^^
[verse]
37
*context_t::context_t(int 'io_threads')*
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

Maps to the _zmq_init()_ function, as described in linkzmq:zmq_init[3].

Destructor
^^^^^^^^^^
[verse]
*context_t::~context_t(void)*

Maps to the _zmq_term()_ function, as described in linkzmq:zmq_term[3].


Methods
^^^^^^^
None.


Socket
~~~~~~
The 'socket_t' class encapsulates a 0MQ socket.


Constructor
^^^^^^^^^^^
[verse]
*socket_t::socket_t(context_t '&context', int 'type')*

Maps to the _zmq_socket()_ function, as described in linkzmq:zmq_socket[3].


Destructor
^^^^^^^^^^
[verse]
*socket_t::~socket_t(void)*

Calls the _zmq_close()_ function, as described in linkzmq:zmq_close[3].


Methods
^^^^^^^
77 78 79 80 81 82 83
[verse]
*void socket_t::getsockopt(int 'option_name', void '*option_value', size_t
'*option_len')*

Maps to the _zmq_getsockopt()_ function, as described in
linkzmq:zmq_getsockopt[3].

84 85 86 87 88
[verse]
*void socket_t::setsockopt(int 'option_name', const void '*option_value', size_t
'option_len')*

Maps to the _zmq_setsockopt()_ function, as described in
89 90
linkzmq:zmq_setsockopt[3].

91
[verse]
92
*void socket_t::bind(const char '*endpoint')*
93

94
Maps to the _zmq_bind()_ function, as described in linkzmq:zmq_bind[3].
95

96
[verse]
97
*void socket_t::connect(const char '*endpoint')*
98

99
Maps to the _zmq_connect()_ function, as described in linkzmq:zmq_connect[3].
100

101 102
[verse]
*bool socket_t::send(message_t '&msg', int 'flags' = 0)*
103

104
Maps to the _zmq_send()_ function, as described in linkzmq:zmq_send[3].
105
Returns true if message is successfully sent, false if it is not.
106

107 108 109 110
[verse]
*bool socket_t::recv(message_t '*msg', int 'flags' = 0)*

Maps to the _zmq_recv()_ function, as described in linkzmq:zmq_recv[3].
111
Returns true if message is successfully received, false if it is not.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128


Message
~~~~~~~
The 'zmq::message_t' class encapsulates the 'zmq_msg_t' structure and
functions to construct, destruct and manipulate 0MQ messages.


Constructor
^^^^^^^^^^^
[verse]
*message_t::message_t(void)*
*message_t::message_t(size_t 'size')*
*message_t::message_t(void '*data', size_t 'size', free_fn '*ffn')*

These map to the _zmq_msg_init()_, _zmq_msg_init_size()_ and
_zmq_msg_init_data()_ functions, described in linkzmq:zmq_msg_init[3],
129
linkzmq:zmq_msg_init_size[3] and linkzmq:zmq_msg_init_data[3] respectively.
130 131 132 133 134 135 136 137


Destructor
^^^^^^^^^^
[verse]
*message_t::~message_t(void)*

Calls the _zmq_msg_close()_ function, as described in linkzmq:zmq_msg_close[3].
138 139


140 141 142 143
Methods
^^^^^^^
[verse]
*void *message_t::data (void)*
144

145
Maps to the _zmq_msg_data()_ function, as described in linkzmq:zmq_msg_data[3].
146

147 148
[verse]
*size_t message_t::size (void)*
149

150
Maps to the _zmq_msg_size()_ function, as described in linkzmq:zmq_msg_size[3].
151

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
[verse]
*void message_t::copy (message_t '*src')*

Maps to the _zmq_msg_copy()_ function, as described in linkzmq:zmq_msg_copy[3].

[verse]
*void message_t::move (message_t '*src')*

Maps to the _zmq_msg_move()_ function, as described in linkzmq:zmq_msg_move[3].

[verse]
*message_t::rebuild(void)*
*message_t::rebuild(size_t 'size')*
*message_t::rebuild(void '*data', size_t 'size', free_fn '*ffn')*

Equivalent to calling the _zmq_msg_close()_ function followed by the
corresponding _zmq_msg_init()_ function.


Input/output multiplexing
~~~~~~~~~~~~~~~~~~~~~~~~~
173 174 175 176

[verse]
*int poll (zmq_pollitem_t *items, int nitems, long timeout = -1)*

177 178 179
The _poll()_ function is a namespaced equivalent of the _zmq_poll()_ function,
as described in linkzmq:zmq_poll[3].

180 181 182
NOTE: To obtain a 0MQ _socket_ for use in a _zmq_pollitem_t_ structure, you
should cast an instance of the _socket_t_ class to `(void *)`.

183 184 185 186 187 188 189

ERROR HANDLING
--------------
All errors reported by the underlying 0MQ C library functions are automatically
converted to exceptions by the C++ language binding.  The 'zmq::error_t' class
is derived from the 'std::exception' class and uses the _zmq_strerror()_
function to convert the error code to human-readable string.
190 191 192 193 194


EXAMPLE
-------
----
195
zmq::context_t ctx (1);
196 197 198 199 200 201 202 203 204 205 206 207 208
zmq::socket_t s (ctx, ZMQ_PUB);
s.connect ("tcp://192.168.0.115:5555");
zmq::message_t msg (100);
memset (msg.data (), 0, 100);
s.send (msg);
----


SEE ALSO
--------
linkzmq:zmq[7]


209 210 211 212
AUTHORS
-------
The 0MQ documentation was written by Martin Sustrik <sustrik@250bpm.com> and
Martin Lucina <mato@kotelna.sk>.