nn_sendmsg.adoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. nn_sendmsg(3)
  2. =============
  3. NAME
  4. ----
  5. nn_sendmsg - fine-grained alternative to nn_send
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *int nn_sendmsg (int 's', const struct nn_msghdr '*msghdr', int 'flags');*
  10. DESCRIPTION
  11. -----------
  12. Sends data specified by 'msghdr' parameter to socket 's' along with any
  13. additional control data. 'msghdr' structure should be nullified before being
  14. used.
  15. Structure 'nn_msghdr' contains at least following members:
  16. struct nn_iovec *msg_iov;
  17. int msg_iovlen;
  18. void *msg_control;
  19. size_t msg_controllen;
  20. 'msg_iov' points to a scatter array of buffers to send. 'msg_iovlen' specifies
  21. the size of the array.
  22. 'msg_control' points to the buffer containing control information to be
  23. associated with the message being sent. 'msg_controllen' specifies the length
  24. of the buffer. If there's no control information to send, 'msg_control' should
  25. be set to NULL. For detailed discussion of how to set control data check
  26. <<nn_cmsg#,nn_cmsg(3)>> man page.
  27. Structure 'nn_iovec' defines one element in the scatter array (i.e. a buffer
  28. to send to the socket) and contains following members:
  29. void *iov_base;
  30. size_t iov_len;
  31. Alternatively, to send a buffer allocated by <<nn_allocmsg#,nn_allocmsg(3)>> function
  32. set 'iov_base' to point to the pointer to the buffer and 'iov_len' to _NN_MSG_
  33. constant. In this case a successful call to _nn_sendmsg_ will deallocate the
  34. buffer. Trying to deallocate it afterwards will result in undefined behaviour.
  35. Also, scatter array in _nn_msghdr_ structure can contain only one element
  36. in this case.
  37. To which of the peers will the message be sent to is determined by
  38. the particular socket type.
  39. The 'flags' argument is a combination of the flags defined below:
  40. *NN_DONTWAIT*::
  41. Specifies that the operation should be performed in non-blocking mode. If the
  42. message cannot be sent straight away, the function will fail with 'errno' set
  43. to EAGAIN.
  44. RETURN VALUE
  45. ------------
  46. If the function succeeds number of bytes in the message is returned. Otherwise,
  47. -1 is returned and 'errno' is set to to one of the values defined below.
  48. ERRORS
  49. ------
  50. *EINVAL*::
  51. Either 'msghdr' is NULL, there are multiple scatter buffers but length is
  52. set to 'NN_MSG' for one of them, or the sum of 'iov_len' values for the
  53. scatter buffers overflows 'size_t'. These are early checks and no
  54. pre-allocated message is freed in this case.
  55. *EMSGSIZE*::
  56. msghdr->msg_iovlen is negative. This is an early check and no pre-allocated
  57. message is freed in this case.
  58. *EFAULT*::
  59. The supplied pointer for the pre-allocated message buffer or the scatter
  60. buffer is NULL, or the length for the scatter buffer is 0.
  61. *EBADF*::
  62. The provided socket is invalid.
  63. *ENOTSUP*::
  64. The operation is not supported by this socket type.
  65. *EFSM*::
  66. The operation cannot be performed on this socket at the moment because socket is
  67. not in the appropriate state. This error may occur with socket types that
  68. switch between several states.
  69. *EAGAIN*::
  70. Non-blocking mode was requested and the message cannot be sent at the moment.
  71. *EINTR*::
  72. The operation was interrupted by delivery of a signal before the message was
  73. sent.
  74. *ETIMEDOUT*::
  75. Individual socket types may define their own specific timeouts. If such timeout
  76. is hit this error will be returned.
  77. *ETERM*::
  78. The library is terminating.
  79. EXAMPLE
  80. -------
  81. Usage of multiple scatter buffers:
  82. ----
  83. struct nn_msghdr hdr;
  84. struct nn_iovec iov [2];
  85. iov [0].iov_base = "Hello";
  86. iov [0].iov_len = 5;
  87. iov [1].iov_base = "World";
  88. iov [1].iov_len = 5;
  89. memset (&hdr, 0, sizeof (hdr));
  90. hdr.msg_iov = iov;
  91. hdr.msg_iovlen = 2;
  92. nn_sendmsg (s, &hdr, 0);
  93. ----
  94. Usage of a single message:
  95. ----
  96. void *msg;
  97. struct nn_msghdr hdr;
  98. struct nn_iovec iov;
  99. msg = nn_allocmsg(12, 0);
  100. strcpy(msg, "Hello World");
  101. iov.iov_base = &msg;
  102. iov.iov_len = NN_MSG;
  103. memset (&hdr, 0, sizeof (hdr));
  104. hdr.msg_iov = &iov;
  105. hdr.msg_iovlen = 1;
  106. nn_sendmsg (s, &hdr, 0);
  107. ----
  108. SEE ALSO
  109. --------
  110. <<nn_send#,nn_send(3)>>
  111. <<nn_recvmsg#,nn_recvmsg(3)>>
  112. <<nn_allocmsg#,nn_allocmsg(3)>>
  113. <<nn_freemsg#,nn_freemsg(3)>>
  114. <<nn_cmsg#,nn_cmsg(3)>>
  115. <<nanomsg#,nanomsg(7)>>
  116. AUTHORS
  117. -------
  118. link:mailto:sustrik@250bpm.com[Martin Sustrik]