zmq_msg_init_data.txt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. zmq_msg_init_data(3)
  2. ====================
  3. NAME
  4. ----
  5. zmq_msg_init_data - initialise 0MQ message from a supplied buffer
  6. SYNOPSIS
  7. --------
  8. *typedef void (zmq_free_fn) (void '*data', void '*hint');*
  9. *int zmq_msg_init_data (zmq_msg_t '*msg', void '*data', size_t 'size', zmq_free_fn '*ffn', void '*hint');*
  10. DESCRIPTION
  11. -----------
  12. The _zmq_msg_init_data()_ function shall initialise the message object
  13. referenced by 'msg' to represent the content referenced by the buffer located
  14. at address 'data', 'size' bytes long. No copy of 'data' shall be performed and
  15. 0MQ shall take ownership of the supplied buffer.
  16. If provided, the deallocation function 'ffn' shall be called once the data
  17. buffer is no longer required by 0MQ, with the 'data' and 'hint' arguments
  18. supplied to _zmq_msg_init_data()_.
  19. CAUTION: Never access 'zmq_msg_t' members directly, instead always use the
  20. _zmq_msg_ family of functions.
  21. CAUTION: The deallocation function 'ffn' needs to be thread-safe, since it
  22. will be called from an arbitrary thread.
  23. CAUTION: If the deallocation function is not provided, the allocated memory
  24. will not be freed, and this may cause a memory leak.
  25. CAUTION: The functions _zmq_msg_init()_, _zmq_msg_init_data()_,
  26. _zmq_msg_init_size()_ and _zmq_msg_init_buffer()_ are mutually exclusive.
  27. Never initialise the same 'zmq_msg_t' twice.
  28. RETURN VALUE
  29. ------------
  30. The _zmq_msg_init_data()_ function shall return zero if successful. Otherwise
  31. it shall return `-1` and set 'errno' to one of the values defined below.
  32. ERRORS
  33. ------
  34. *ENOMEM*::
  35. Insufficient storage space is available.
  36. EXAMPLE
  37. -------
  38. .Initialising a message from a supplied buffer
  39. ----
  40. void my_free (void *data, void *hint)
  41. {
  42. free (data);
  43. }
  44. /* ... */
  45. void *data = malloc (6);
  46. assert (data);
  47. memcpy (data, "ABCDEF", 6);
  48. zmq_msg_t msg;
  49. rc = zmq_msg_init_data (&msg, data, 6, my_free, NULL);
  50. assert (rc == 0);
  51. ----
  52. SEE ALSO
  53. --------
  54. linkzmq:zmq_msg_init_size[3]
  55. linkzmq:zmq_msg_init_buffer[3]
  56. linkzmq:zmq_msg_init[3]
  57. linkzmq:zmq_msg_close[3]
  58. linkzmq:zmq_msg_data[3]
  59. linkzmq:zmq_msg_size[3]
  60. linkzmq:zmq[7]
  61. AUTHORS
  62. -------
  63. This page was written by the 0MQ community. To make a change please
  64. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.