zmq_sendmsg.txt 3.9 KB

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