summaryrefslogtreecommitdiff
path: root/doc/zmq_cpp.txt
blob: b963afabefe8f363225b4d122d91efc4da84ec63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
zmq_cpp(7)
==========


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


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

*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]
*context_t::context_t(int 'io_threads')*

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
^^^^^^^
[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].

[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
linkzmq:zmq_setsockopt[3].

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

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

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

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

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

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

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

Maps to the _zmq_recv()_ function, as described in linkzmq:zmq_recv[3].
Returns true if message is successfully received, false if it is not.


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],
linkzmq:zmq_msg_init_size[3] and linkzmq:zmq_msg_init_data[3] respectively.


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

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


Methods
^^^^^^^
[verse]
*void *message_t::data (void)*

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

[verse]
*size_t message_t::size (void)*

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

[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
~~~~~~~~~~~~~~~~~~~~~~~~~

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

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

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 *)`.


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.


EXAMPLE
-------
----
zmq::context_t ctx (1);
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]


AUTHORS
-------
This manual page was written by the 0MQ community.