nn_recvmsg.adoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. nn_recvmsg(3)
  2. =============
  3. NAME
  4. ----
  5. nn_recvmsg - fine-grained alternative to nn_recv
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *NN_EXPORT int nn_recvmsg (int 's', struct nn_msghdr '*msghdr', int 'flags');*
  10. DESCRIPTION
  11. -----------
  12. Receives a message from socket 's' into buffers specified by 'msghdr' parameter
  13. along with any additional control data. 'msghdr' parameter should be nullified
  14. before being 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 gather array of buffers to fill in. 'msg_iovlen' specifies
  21. the size of the array.
  22. 'msg_control' points to the buffer to hold control information associated with
  23. the received message. 'msg_controllen' specifies the length of the buffer.
  24. If the control information should not be retrieved, set 'msg_control' parameter
  25. to NULL. For detailed discussion of how to parse the control information check
  26. <<nn_cmsg#,nn_cmsg(3)>> man page.
  27. Structure 'nn_iovec' defines one element in the gather array (a buffer to be
  28. filled in by message data) and contains following members:
  29. void *iov_base;
  30. size_t iov_len;
  31. Alternatively, _nanomsg_ library can allocate the buffer for you. To do so,
  32. let the 'iov_base' point to void* variable to receive the buffer and set
  33. 'iov_len' to _NN_MSG_. After successful completion user is responsible
  34. for deallocating the message using <<nn_freemsg#,nn_freemsg(3)>> function. Gather
  35. array in _nn_msghdr_ structure can contain only one element in this case.
  36. The 'flags' argument is a combination of the flags defined below:
  37. *NN_DONTWAIT*::
  38. Specifies that the operation should be performed in non-blocking mode. If the
  39. message cannot be received straight away, the function will fail with 'errno'
  40. set to EAGAIN.
  41. RETURN VALUE
  42. ------------
  43. If the function succeeds number of bytes in the message is returned. Otherwise,
  44. -1 is returned and 'errno' is set to to one of the values defined
  45. below.
  46. ERRORS
  47. ------
  48. *EBADF*::
  49. The provided socket is invalid.
  50. *ENOTSUP*::
  51. The operation is not supported by this socket type.
  52. *EFSM*::
  53. The operation cannot be performed on this socket at the moment because socket is
  54. not in the appropriate state. This error may occur with socket types that
  55. switch between several states.
  56. *EAGAIN*::
  57. Non-blocking mode was requested and there's no message to receive at the moment.
  58. *EINTR*::
  59. The operation was interrupted by delivery of a signal before the message was
  60. received.
  61. *ETIMEDOUT*::
  62. Individual socket types may define their own specific timeouts. If such timeout
  63. is hit this error will be returned.
  64. *ETERM*::
  65. The library is terminating.
  66. EXAMPLE
  67. -------
  68. ----
  69. struct nn_msghdr hdr;
  70. struct nn_iovec iov [2];
  71. char buf0 [4];
  72. char buf1 [2];
  73. iov [0].iov_base = buf0;
  74. iov [0].iov_len = sizeof (buf0);
  75. iov [1].iov_base = buf1;
  76. iov [1].iov_len = sizeof (buf1);
  77. memset (&hdr, 0, sizeof (hdr));
  78. hdr.msg_iov = iov;
  79. hdr.msg_iovlen = 2;
  80. nn_recvmsg (s, &hdr, 0);
  81. ----
  82. SEE ALSO
  83. --------
  84. <<nn_recv#,nn_recv(3)>>
  85. <<nn_sendmsg#,nn_sendmsg(3)>>
  86. <<nn_allocmsg#,nn_allocmsg(3)>>
  87. <<nn_freemsg#,nn_freemsg(3)>>
  88. <<nn_cmsg#,nn_cmsg(3)>>
  89. <<nanomsg#,nanomsg(7)>>
  90. AUTHORS
  91. -------
  92. link:mailto:sustrik@250bpm.com[Martin Sustrik]