zmq_recvmsg.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. zmq_recvmsg(3)
  2. ==============
  3. NAME
  4. ----
  5. zmq_recvmsg - receive a message part from a socket
  6. SYNOPSIS
  7. --------
  8. *int zmq_recvmsg (void '*socket', zmq_msg_t '*msg', int 'flags');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_recvmsg()_ function shall receive a message part from the socket
  12. referenced by the 'socket' argument and store it in the message referenced by
  13. the 'msg' argument. Any content previously stored in 'msg' shall be properly
  14. deallocated. If there are no message parts available on the specified 'socket'
  15. the _zmq_recvmsg()_ function shall block until the request can be satisfied.
  16. The 'flags' argument is a combination of the flags defined below:
  17. *ZMQ_DONTWAIT*::
  18. Specifies that the operation should be performed in non-blocking mode. If there
  19. are no messages available on the specified 'socket', the _zmq_recvmsg()_
  20. function shall fail with 'errno' set to EAGAIN.
  21. NOTE: this API method is deprecated in favor of zmq_msg_recv(3).
  22. Multi-part messages
  23. ~~~~~~~~~~~~~~~~~~~
  24. A 0MQ message is composed of 1 or more message parts. Each message
  25. part is an independent 'zmq_msg_t' in its own right. 0MQ ensures atomic
  26. delivery of messages: peers shall receive either all _message parts_ of a
  27. message or none at all. The total number of message parts is unlimited except
  28. by available memory.
  29. An application that processes multi-part messages must use the _ZMQ_RCVMORE_
  30. linkzmq:zmq_getsockopt[3] option after calling _zmq_recvmsg()_ to determine if
  31. there are further parts to receive.
  32. RETURN VALUE
  33. ------------
  34. The _zmq_recvmsg()_ function shall return number of bytes in the message
  35. if successful. Otherwise it shall return `-1` and set 'errno' to one of the
  36. 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_recvmsg()_ operation is not supported by this socket type.
  46. *EFSM*::
  47. The _zmq_recvmsg()_ 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. *EFAULT*::
  59. The message passed to the function was invalid.
  60. EXAMPLE
  61. -------
  62. .Receiving a message from a socket
  63. ----
  64. /* Create an empty 0MQ message */
  65. zmq_msg_t msg;
  66. int rc = zmq_msg_init (&msg);
  67. assert (rc == 0);
  68. /* Block until a message is available to be received from socket */
  69. rc = zmq_recvmsg (socket, &msg, 0);
  70. assert (rc != -1);
  71. /* Release message */
  72. zmq_msg_close (&msg);
  73. ----
  74. .Receiving a multi-part message
  75. ----
  76. int more;
  77. size_t more_size = sizeof (more);
  78. do {
  79. /* Create an empty 0MQ message to hold the message part */
  80. zmq_msg_t part;
  81. int rc = zmq_msg_init (&part);
  82. assert (rc == 0);
  83. /* Block until a message is available to be received from socket */
  84. rc = zmq_recvmsg (socket, &part, 0);
  85. assert (rc != -1);
  86. /* Determine if more message parts are to follow */
  87. rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
  88. assert (rc == 0);
  89. zmq_msg_close (&part);
  90. } while (more);
  91. ----
  92. SEE ALSO
  93. --------
  94. linkzmq:zmq_recv[3]
  95. linkzmq:zmq_send[3]
  96. linkzmq:zmq_getsockopt[3]
  97. linkzmq:zmq_setsockopt[3]
  98. linkzmq:zmq_socket[7]
  99. linkzmq:zmq[7]
  100. AUTHORS
  101. -------
  102. This page was written by the 0MQ community. To make a change please
  103. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.