zmq_recv.txt 2.77 KB
Newer Older
1 2 3 4 5 6
zmq_recv(3)
===========


NAME
----
7
zmq_recv - receive a message part from a socket
8 9 10 11


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


DESCRIPTION
-----------
17 18 19 20 21
The _zmq_recv()_ function shall receive a message from the socket referenced
by the 'socket' argument and store it in the buffer referenced by the 'buf'
argument. Any bytes exceeding the length specified by the 'len' argument shall
be truncated. If there are no messages available on the specified 'socket'
the _zmq_recv()_ function shall block until the request can be satisfied.
22 23
The 'flags' argument is a combination of the flags defined below: The 'buf'
argument may be null if len is zero.
24

25
*ZMQ_DONTWAIT*::
Martin Lucina's avatar
Martin Lucina committed
26
Specifies that the operation should be performed in non-blocking mode. If there
27 28
are no messages available on the specified 'socket', the _zmq_recv()_
function shall fail with 'errno' set to EAGAIN.
29

30

Martin Lucina's avatar
Martin Lucina committed
31 32
Multi-part messages
~~~~~~~~~~~~~~~~~~~
33 34
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
35 36
message or none at all. The total number of message parts is unlimited except
by available memory.
Martin Lucina's avatar
Martin Lucina committed
37

38
An application that processes multi-part messages must use the _ZMQ_RCVMORE_
39
linkzmq:zmq_getsockopt[3] option after calling _zmq_recv()_ to determine if
40
there are further parts to receive.
Martin Lucina's avatar
Martin Lucina committed
41

42 43
RETURN VALUE
------------
44 45 46 47
The _zmq_recv()_ function shall return number of bytes in the message
if successful. Note that the value can exceed the value of the 'len' parameter
in case the message was truncated. If not successful the function shall return
`-1` and set 'errno' to one of the values defined below.
48 49 50 51 52


ERRORS
------
*EAGAIN*::
Martin Lucina's avatar
Martin Lucina committed
53
Non-blocking mode was requested and no messages are available at the moment.
54
*ENOTSUP*::
Martin Lucina's avatar
Martin Lucina committed
55
The _zmq_recv()_ operation is not supported by this socket type.
56
*EFSM*::
57 58
The _zmq_recv()_ 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
59 60
socket types that switch between several states, such as ZMQ_REP.  See the
_messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
61
*ETERM*::
Martin Lucina's avatar
Martin Lucina committed
62
The 0MQ 'context' associated with the specified 'socket' was terminated.
63 64
*ENOTSOCK*::
The provided 'socket' was invalid.
65 66 67
*EINTR*::
The operation was interrupted by delivery of a signal before a message was
available.
68 69 70 71


EXAMPLE
-------
Martin Lucina's avatar
Martin Lucina committed
72
.Receiving a message from a socket
73
----
74 75 76
char buf [256];
nbytes = zmq_recv (socket, buf, 256, 0);
assert (nbytes != -1);
Martin Lucina's avatar
Martin Lucina committed
77 78
----

79 80 81 82

SEE ALSO
--------
linkzmq:zmq_send[3]
Martin Lucina's avatar
Martin Lucina committed
83
linkzmq:zmq_getsockopt[3]
Martin Lucina's avatar
Martin Lucina committed
84 85
linkzmq:zmq_socket[7]
linkzmq:zmq[7]
86 87


88 89
AUTHORS
-------
90 91
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>.