zmq_msg_recv.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. zmq_msg_recv(3)
  2. ===============
  3. NAME
  4. ----
  5. zmq_msg_recv - receive a message part from a socket
  6. SYNOPSIS
  7. --------
  8. *int zmq_msg_recv (zmq_msg_t '*msg', void '*socket', int 'flags');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_msg_recv()_ function is identical to linkzmq:zmq_recvmsg[3], which
  12. shall be deprecated in future versions. _zmq_msg_recv()_ is more consistent
  13. with other message manipulation functions.
  14. The _zmq_msg_recv()_ function shall receive a message part from the socket
  15. referenced by the 'socket' argument and store it in the message referenced by
  16. the 'msg' argument. Any content previously stored in 'msg' shall be properly
  17. deallocated. If there are no message parts available on the specified 'socket'
  18. the _zmq_msg_recv()_ function shall block until the request can be satisfied.
  19. The 'flags' argument is a combination of the flags defined below:
  20. *ZMQ_DONTWAIT*::
  21. Specifies that the operation should be performed in non-blocking mode. If there
  22. are no messages available on the specified 'socket', the _zmq_msg_recv()_
  23. function shall fail with 'errno' set to EAGAIN.
  24. Multi-part messages
  25. ~~~~~~~~~~~~~~~~~~~
  26. A 0MQ message is composed of 1 or more message parts. Each message
  27. part is an independent 'zmq_msg_t' in its own right. 0MQ ensures atomic
  28. delivery of messages: peers shall receive either all _message parts_ of a
  29. message or none at all. The total number of message parts is unlimited except
  30. by available memory.
  31. An application that processes multi-part messages must use the _ZMQ_RCVMORE_
  32. linkzmq:zmq_getsockopt[3] option after calling _zmq_msg_recv()_ to determine if
  33. there are further parts to receive.
  34. RETURN VALUE
  35. ------------
  36. The _zmq_msg_recv()_ function shall return number of bytes in the message
  37. if successful. Otherwise it shall return `-1` and set 'errno' to one of the
  38. values defined below.
  39. ERRORS
  40. ------
  41. *EAGAIN*::
  42. Either the timeout set via the socket-option ZMQ_RCVTIMEO (see linkzmq:zmq_setsockopt[3])
  43. has been reached (flag ZMQ_DONTWAIT not set) without being able to read a message
  44. from the socket or there are no messages available at the moment (flag ZMQ_DONTWAIT set)
  45. and the operation would block.
  46. *ENOTSUP*::
  47. The _zmq_msg_recv()_ operation is not supported by this socket type.
  48. *EFSM*::
  49. The _zmq_msg_recv()_ operation cannot be performed on this socket at the moment
  50. due to the socket not being in the appropriate state. This error may occur with
  51. socket types that switch between several states, such as ZMQ_REP. See the
  52. _messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
  53. *ETERM*::
  54. The 0MQ 'context' associated with the specified 'socket' was terminated.
  55. *ENOTSOCK*::
  56. The provided 'socket' was invalid.
  57. *EINTR*::
  58. The operation was interrupted by delivery of a signal before a message was
  59. available.
  60. *EFAULT*::
  61. The message passed to the function was invalid.
  62. EXAMPLE
  63. -------
  64. .Receiving a message from a socket
  65. ----
  66. /* Create an empty 0MQ message */
  67. zmq_msg_t msg;
  68. int rc = zmq_msg_init (&msg);
  69. assert (rc == 0);
  70. /* Block until a message is available to be received from socket */
  71. rc = zmq_msg_recv (&msg, socket, 0);
  72. assert (rc != -1);
  73. /* Release message */
  74. zmq_msg_close (&msg);
  75. ----
  76. .Receiving a multi-part message
  77. ----
  78. int more;
  79. size_t more_size = sizeof (more);
  80. do {
  81. /* Create an empty 0MQ message to hold the message part */
  82. zmq_msg_t part;
  83. int rc = zmq_msg_init (&part);
  84. assert (rc == 0);
  85. /* Block until a message is available to be received from socket */
  86. rc = zmq_msg_recv (&part, socket, 0);
  87. assert (rc != -1);
  88. /* Determine if more message parts are to follow */
  89. rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
  90. assert (rc == 0);
  91. zmq_msg_close (&part);
  92. } while (more);
  93. ----
  94. SEE ALSO
  95. --------
  96. linkzmq:zmq_recv[3]
  97. linkzmq:zmq_send[3]
  98. linkzmq:zmq_msg_send[3]
  99. linkzmq:zmq_getsockopt[3]
  100. linkzmq:zmq_setsockopt[3]
  101. linkzmq:zmq_socket[7]
  102. linkzmq:zmq[7]
  103. AUTHORS
  104. -------
  105. This page was written by the 0MQ community. To make a change please
  106. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.