zmq_msg_send.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. zmq_msg_send(3)
  2. ===============
  3. NAME
  4. ----
  5. zmq_msg_send - send a message part on a socket
  6. SYNOPSIS
  7. --------
  8. *int zmq_msg_send (zmq_msg_t '*msg', void '*socket', int 'flags');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_msg_send()_ function is identical to linkzmq:zmq_sendmsg[3], which
  12. shall be deprecated in future versions. _zmq_msg_send()_ is more consistent
  13. with other message manipulation functions.
  14. The _zmq_msg_send()_ function shall queue the message referenced by the 'msg'
  15. argument to be sent to the socket referenced by the 'socket' argument. The
  16. 'flags' argument is a combination of the flags defined below:
  17. *ZMQ_DONTWAIT*::
  18. For socket types (DEALER, PUSH) that block (either with ZMQ_IMMEDIATE option set
  19. and no peer available, or all peers having full high-water mark), specifies that
  20. the operation should be performed in non-blocking mode. If the message cannot be
  21. queued on the 'socket', the _zmq_msg_send()_ function shall fail with 'errno' set
  22. to EAGAIN.
  23. *ZMQ_SNDMORE*::
  24. Specifies that the message being sent is a multi-part message, and that further
  25. message parts are to follow. Refer to the section regarding multi-part messages
  26. below for a detailed description.
  27. The _zmq_msg_t_ structure passed to _zmq_msg_send()_ is nullified on a
  28. successful call. If you want to send the same message to multiple sockets you
  29. have to copy it (e.g. using _zmq_msg_copy()_). If the call fails, the
  30. _zmq_msg_t_ structure stays intact, and must be consumed by another call to
  31. _zmq_msg_send()_ on the same or another socket, or released using
  32. _zmq_msg_close()_ to avoid a memory leak.
  33. NOTE: A successful invocation of _zmq_msg_send()_ does not indicate that the
  34. message has been transmitted to the network, only that it has been queued on
  35. the 'socket' and 0MQ has assumed responsibility for the message. You do not need
  36. to call _zmq_msg_close()_ after a successful _zmq_msg_send()_.
  37. Multi-part messages
  38. ~~~~~~~~~~~~~~~~~~~
  39. A 0MQ message is composed of 1 or more message parts. Each message
  40. part is an independent 'zmq_msg_t' in its own right. 0MQ ensures atomic
  41. delivery of messages: peers shall receive either all _message parts_ of a
  42. message or none at all. The total number of message parts is unlimited except
  43. by available memory.
  44. An application that sends multi-part messages must use the _ZMQ_SNDMORE_ flag
  45. when sending each message part except the final one.
  46. RETURN VALUE
  47. ------------
  48. The _zmq_msg_send()_ function shall return number of bytes in the message
  49. if successful (if number of bytes is higher than 'MAX_INT', the function will
  50. return 'MAX_INT'). Otherwise it shall return `-1` and set 'errno' to one of the
  51. values defined below.
  52. ERRORS
  53. ------
  54. *EAGAIN*::
  55. Non-blocking mode was requested and the message cannot be sent at the moment.
  56. *ENOTSUP*::
  57. The _zmq_msg_send()_ operation is not supported by this socket type.
  58. *EINVAL*::
  59. The sender tried to send multipart data, which the socket type does not allow.
  60. *EFSM*::
  61. The _zmq_msg_send()_ operation cannot be performed on this socket at the moment
  62. due to the socket not being in the appropriate state. This error may occur with
  63. socket types that switch between several states, such as ZMQ_REP. See the
  64. _messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
  65. *ETERM*::
  66. The 0MQ 'context' associated with the specified 'socket' was terminated.
  67. *ENOTSOCK*::
  68. The provided 'socket' was invalid.
  69. *EINTR*::
  70. The operation was interrupted by delivery of a signal before the message was
  71. sent.
  72. *EFAULT*::
  73. Invalid message.
  74. *EHOSTUNREACH*::
  75. The message cannot be routed.
  76. EXAMPLE
  77. -------
  78. .Filling in a message and sending it to a socket
  79. ----
  80. /* Create a new message, allocating 6 bytes for message content */
  81. zmq_msg_t msg;
  82. int rc = zmq_msg_init_size (&msg, 6);
  83. assert (rc == 0);
  84. /* Fill in message content with 'AAAAAA' */
  85. memset (zmq_msg_data (&msg), 'A', 6);
  86. /* Send the message to the socket */
  87. rc = zmq_msg_send (&msg, socket, 0);
  88. assert (rc == 6);
  89. ----
  90. .Sending a multi-part message
  91. ----
  92. /* Send a multi-part message consisting of three parts to socket */
  93. rc = zmq_msg_send (&part1, socket, ZMQ_SNDMORE);
  94. rc = zmq_msg_send (&part2, socket, ZMQ_SNDMORE);
  95. /* Final part; no more parts to follow */
  96. rc = zmq_msg_send (&part3, socket, 0);
  97. ----
  98. SEE ALSO
  99. --------
  100. linkzmq:zmq_recv[3]
  101. linkzmq:zmq_send[3]
  102. linkzmq:zmq_msg_recv[3]
  103. linkzmq:zmq_socket[7]
  104. linkzmq:zmq[7]
  105. AUTHORS
  106. -------
  107. This page was written by the 0MQ community. To make a change please
  108. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.