zmq_send.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. zmq_send(3)
  2. ===========
  3. NAME
  4. ----
  5. zmq_send - send a message part on a socket
  6. SYNOPSIS
  7. --------
  8. *int zmq_send (void '*socket', const void '*buf', size_t 'len', int 'flags');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_send()_ function shall queue a message created from the buffer
  12. referenced by the 'buf' and 'len' arguments. The 'flags' argument is
  13. 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_send()_ 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. NOTE: A successful invocation of _zmq_send()_ does not indicate that the
  25. message has been transmitted to the network, only that it has been queued on
  26. the 'socket' and 0MQ has assumed responsibility for the message.
  27. Multi-part messages
  28. ~~~~~~~~~~~~~~~~~~~
  29. A 0MQ message is composed of 1 or more message parts. 0MQ ensures atomic
  30. delivery of messages: peers shall receive either all _message parts_ of a
  31. message or none at all. The total number of message parts is unlimited except
  32. by available memory.
  33. An application that sends multi-part messages must use the _ZMQ_SNDMORE_ flag
  34. when sending each message part except the final one.
  35. RETURN VALUE
  36. ------------
  37. The _zmq_send()_ function shall return number of bytes in the message
  38. if successful. Otherwise it shall return `-1` and set 'errno' to one of the
  39. values defined below.
  40. ERRORS
  41. ------
  42. *EAGAIN*::
  43. Non-blocking mode was requested and the message cannot be sent at the moment.
  44. *ENOTSUP*::
  45. The _zmq_send()_ operation is not supported by this socket type.
  46. *EINVAL*::
  47. The sender tried to send multipart data, which the socket type does not allow.
  48. *EFSM*::
  49. The _zmq_send()_ 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 the message was
  59. sent.
  60. *EHOSTUNREACH*::
  61. The message cannot be routed.
  62. EXAMPLE
  63. -------
  64. .Sending a multi-part message
  65. ----
  66. /* Send a multi-part message consisting of three parts to socket */
  67. rc = zmq_send (socket, "ABC", 3, ZMQ_SNDMORE);
  68. assert (rc == 3);
  69. rc = zmq_send (socket, "DEFGH", 5, ZMQ_SNDMORE);
  70. assert (rc == 5);
  71. /* Final part; no more parts to follow */
  72. rc = zmq_send (socket, "JK", 2, 0);
  73. assert (rc == 2);
  74. ----
  75. SEE ALSO
  76. --------
  77. linkzmq:zmq_send_const[3]
  78. linkzmq:zmq_recv[3]
  79. linkzmq:zmq_socket[7]
  80. linkzmq:zmq[7]
  81. AUTHORS
  82. -------
  83. This page was written by the 0MQ community. To make a change please
  84. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.