zmq_recv.txt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. zmq_recv(3)
  2. ===========
  3. NAME
  4. ----
  5. zmq_recv - receive a message part from a socket
  6. SYNOPSIS
  7. --------
  8. *int zmq_recv (void '*socket', void '*buf', size_t 'len', int 'flags');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_recv()_ function shall receive a message from the socket referenced
  12. by the 'socket' argument and store it in the buffer referenced by the 'buf'
  13. argument. Any bytes exceeding the length specified by the 'len' argument shall
  14. be truncated. If there are no messages available on the specified 'socket'
  15. the _zmq_recv()_ function shall block until the request can be satisfied.
  16. The 'flags' argument is a combination of the flags defined below: The 'buf'
  17. argument may be null if len is zero.
  18. *ZMQ_DONTWAIT*::
  19. Specifies that the operation should be performed in non-blocking mode. If there
  20. are no messages available on the specified 'socket', the _zmq_recv()_
  21. function shall fail with 'errno' set to EAGAIN.
  22. Multi-part messages
  23. ~~~~~~~~~~~~~~~~~~~
  24. A 0MQ message is composed of 1 or more message parts. 0MQ ensures atomic
  25. delivery of messages: peers shall receive either all _message parts_ of a
  26. message or none at all. The total number of message parts is unlimited except
  27. by available memory.
  28. An application that processes multi-part messages must use the _ZMQ_RCVMORE_
  29. linkzmq:zmq_getsockopt[3] option after calling _zmq_recv()_ to determine if
  30. there are further parts to receive.
  31. RETURN VALUE
  32. ------------
  33. The _zmq_recv()_ function shall return number of bytes in the message
  34. if successful. Note that the value can exceed the value of the 'len' parameter
  35. in case the message was truncated. If not successful the function shall return
  36. `-1` and set 'errno' to one of the values defined below.
  37. ERRORS
  38. ------
  39. *EAGAIN*::
  40. Either the timeout set via the socket-option ZMQ_RCVTIMEO (see linkzmq:zmq_setsockopt[3])
  41. has been reached (flag ZMQ_DONTWAIT not set) without being able to read a message
  42. from the socket or there are no messages available at the moment (flag ZMQ_DONTWAIT set)
  43. and the operation would block.
  44. *ENOTSUP*::
  45. The _zmq_recv()_ operation is not supported by this socket type.
  46. *EFSM*::
  47. The _zmq_recv()_ operation cannot be performed on this socket at the moment
  48. due to the socket not being in the appropriate state. This error may occur with
  49. socket types that switch between several states, such as ZMQ_REP. See the
  50. _messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
  51. *ETERM*::
  52. The 0MQ 'context' associated with the specified 'socket' was terminated.
  53. *ENOTSOCK*::
  54. The provided 'socket' was invalid.
  55. *EINTR*::
  56. The operation was interrupted by delivery of a signal before a message was
  57. available.
  58. EXAMPLE
  59. -------
  60. .Receiving a message from a socket
  61. ----
  62. char buf [256];
  63. nbytes = zmq_recv (socket, buf, 256, 0);
  64. assert (nbytes != -1);
  65. ----
  66. SEE ALSO
  67. --------
  68. linkzmq:zmq_send[3]
  69. linkzmq:zmq_getsockopt[3]
  70. linkzmq:zmq_setsockopt[3]
  71. linkzmq:zmq_socket[7]
  72. linkzmq:zmq[7]
  73. AUTHORS
  74. -------
  75. This page was written by the 0MQ community. To make a change please
  76. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.