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


NAME
----
7
zmq_send - send a message part on a socket
8 9 10 11


SYNOPSIS
--------
12
*int zmq_send (void '*socket', void '*buf', size_t 'len', int 'flags');*
13 14 15 16


DESCRIPTION
-----------
17 18 19
The _zmq_send()_ function shall queue a message created from the buffer
referenced by the 'buf' and 'len' arguments. The 'flags' argument is
a combination of the flags defined below:
20

21
*ZMQ_DONTWAIT*::
22 23 24 25
For socket types (DEALER, PUSH) that block when there are no available peers 
(or all peers have full high-water mark), specifies that the operation should 
be performed in non-blocking mode. If the message cannot be queued on the 
'socket', the _zmq_send()_ function shall fail with 'errno' set to EAGAIN.
26

Martin Lucina's avatar
Martin Lucina committed
27 28 29 30 31
*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
32 33
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
34
the 'socket' and 0MQ has assumed responsibility for the message.
35 36


Martin Lucina's avatar
Martin Lucina committed
37 38
Multi-part messages
~~~~~~~~~~~~~~~~~~~
39 40
A 0MQ message is composed of 1 or more message parts. 0MQ ensures atomic
delivery of messages: peers shall receive either all _message parts_ of a
41 42
message or none at all. The total number of message parts is unlimited except
by available memory.
Martin Lucina's avatar
Martin Lucina committed
43

44 45
An application that sends multi-part messages must use the _ZMQ_SNDMORE_ flag
when sending each message part except the final one.
Martin Lucina's avatar
Martin Lucina committed
46 47


48 49
RETURN VALUE
------------
50 51 52
The _zmq_send()_ function shall return number of bytes in the message
if successful. Otherwise it shall return `-1` and set 'errno' to one of the
values defined below.
53 54 55 56 57


ERRORS
------
*EAGAIN*::
58
Non-blocking mode was requested and the message cannot be sent at the moment.
59
*ENOTSUP*::
Martin Lucina's avatar
Martin Lucina committed
60
The _zmq_send()_ operation is not supported by this socket type.
61 62
*EINVAL*::
The sender tried to send multipart data, which the socket type does not allow.
63
*EFSM*::
64 65
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
Martin Lucina's avatar
Martin Lucina committed
66 67
socket types that switch between several states, such as ZMQ_REP.  See the
_messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
68
*ETERM*::
Martin Lucina's avatar
Martin Lucina committed
69
The 0MQ 'context' associated with the specified 'socket' was terminated.
70 71
*ENOTSOCK*::
The provided 'socket' was invalid.
72 73 74
*EINTR*::
The operation was interrupted by delivery of a signal before the message was
sent.
75 76
*EHOSTUNREACH*::
The message cannot be routed.
77 78 79 80


EXAMPLE
-------
Martin Lucina's avatar
Martin Lucina committed
81 82 83
.Sending a multi-part message
----
/* Send a multi-part message consisting of three parts to socket */
84 85 86 87
rc = zmq_send (socket, "ABC", 3, ZMQ_SNDMORE);
assert (rc == 3);
rc = zmq_send (socket, "DEFGH", 5, ZMQ_SNDMORE);
assert (rc == 5);
Martin Lucina's avatar
Martin Lucina committed
88
/* Final part; no more parts to follow */
89 90
rc = zmq_send (socket, "JK", 2, 0);
assert (rc == 2);
Martin Lucina's avatar
Martin Lucina committed
91 92
----

93 94
SEE ALSO
--------
Uli Köhler's avatar
Uli Köhler committed
95
linkzmq:zmq_send_const[3]
96
linkzmq:zmq_recv[3]
Martin Lucina's avatar
Martin Lucina committed
97 98
linkzmq:zmq_socket[7]
linkzmq:zmq[7]
99 100


101 102
AUTHORS
-------
103 104
This page was written by the 0MQ community. To make a change please
read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.