zmq_send.txt 3.2 KB
Newer Older
1 2 3 4 5 6
zmq_send(3)
===========


NAME
----
Martin Lucina's avatar
Martin Lucina committed
7
zmq_send - send a message on a socket
8 9 10 11


SYNOPSIS
--------
Martin Lucina's avatar
Martin Lucina committed
12
*int zmq_send (void '*socket', zmq_msg_t '*msg', int 'flags');*
13 14 15 16


DESCRIPTION
-----------
Martin Lucina's avatar
Martin Lucina committed
17 18 19
The _zmq_send()_ function shall queue the message referenced by the 'msg'
argument to be sent to the socket referenced by the 'socket' argument.  The
'flags' argument is a combination of the flags defined below:
20 21

*ZMQ_NOBLOCK*::
Martin Lucina's avatar
Martin Lucina committed
22
Specifies that the operation should be performed in non-blocking mode. If the
23 24
message cannot be queued on the 'socket', the _zmq_send()_ function shall fail
with 'errno' set to EAGAIN.
25

Martin Lucina's avatar
Martin Lucina committed
26 27 28 29 30
*ZMQ_SNDMORE*::
Specifies that the message being sent is a multi-part message, and that further
message parts are to follow. Refer to the section regarding multi-part messages
below for a detailed description.

Martin Lucina's avatar
Martin Lucina committed
31 32
NOTE: A successful invocation of _zmq_send()_ does not indicate that the
message has been transmitted to the network, only that it has been queued on
33
the 'socket' and 0MQ has assumed responsibility for the message.
34 35


Martin Lucina's avatar
Martin Lucina committed
36 37
Multi-part messages
~~~~~~~~~~~~~~~~~~~
Martin Lucina's avatar
Martin Lucina committed
38 39 40 41 42 43
A 0MQ message is composed of 1 or more message parts; each message part is an
independent 'zmq_msg_t' in its own right. 0MQ ensures atomic delivery of
messages; peers shall receive either all _message parts_ of a message or none
at all.

The total number of message parts is unlimited.
Martin Lucina's avatar
Martin Lucina committed
44 45 46 47 48 49

An application wishing to send a multi-part message does so by specifying the
'ZMQ_SNDMORE' flag to _zmq_send()_. The presence of this flag indicates to 0MQ
that the message being sent is a multi-part message and that more message parts
are to follow. When the application wishes to send the final message part it
does so by calling _zmq_send()_ without the 'ZMQ_SNDMORE' flag; this indicates
Martin Lucina's avatar
Martin Lucina committed
50
that no more message parts are to follow.
Martin Lucina's avatar
Martin Lucina committed
51 52


53 54
RETURN VALUE
------------
Martin Lucina's avatar
Martin Lucina committed
55
The _zmq_send()_ function shall return zero if successful. Otherwise it shall
Martin Lucina's avatar
Martin Lucina committed
56
return `-1` and set 'errno' to one of the values defined below.
57 58 59 60 61


ERRORS
------
*EAGAIN*::
62
Non-blocking mode was requested and the message cannot be sent at the moment.
63
*ENOTSUP*::
Martin Lucina's avatar
Martin Lucina committed
64
The _zmq_send()_ operation is not supported by this socket type.
65
*EFSM*::
Martin Lucina's avatar
Martin Lucina committed
66 67 68 69
The _zmq_send()_ operation cannot be performed on this socket at the moment due
to the socket not being in the appropriate state.  This error may occur with
socket types that switch between several states, such as ZMQ_REP.  See the
_messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
70
*ETERM*::
Martin Lucina's avatar
Martin Lucina committed
71
The 0MQ 'context' associated with the specified 'socket' was terminated.
72 73 74 75


EXAMPLE
-------
Martin Lucina's avatar
Martin Lucina committed
76
.Filling in a message and sending it to a socket
77
----
Martin Lucina's avatar
Martin Lucina committed
78
/* Create a new message, allocating 6 bytes for message content */
79 80 81
zmq_msg_t msg;
int rc = zmq_msg_init_size (&msg, 6);
assert (rc == 0);
Martin Lucina's avatar
Martin Lucina committed
82
/* Fill in message content with 'AAAAAA' */
83
memset (zmq_msg_data (&msg), 'A', 6);
Martin Lucina's avatar
Martin Lucina committed
84 85
/* Send the message to the socket */
rc = zmq_send (socket, &msg, 0);
86 87 88
assert (rc == 0);
----

Martin Lucina's avatar
Martin Lucina committed
89 90 91 92 93 94 95 96 97
.Sending a multi-part message
----
/* Send a multi-part message consisting of three parts to socket */
rc = zmq_send (socket, &part1, ZMQ_SNDMORE);
rc = zmq_send (socket, &part2, ZMQ_SNDMORE);
/* Final part; no more parts to follow */
rc = zmq_send (socket, &part3, 0);
----

98 99 100 101

SEE ALSO
--------
linkzmq:zmq_recv[3]
Martin Lucina's avatar
Martin Lucina committed
102 103
linkzmq:zmq_socket[7]
linkzmq:zmq[7]
104 105