nn_getsockopt.adoc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. nn_getsockopt(3)
  2. ================
  3. NAME
  4. ----
  5. nn_getsockopt - retrieve a socket option
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *int nn_getsockopt (int 's', int 'level', int 'option', void '*optval', size_t '*optvallen');*
  10. DESCRIPTION
  11. -----------
  12. Retrieves the value for the 'option'. The 'level' argument specifies
  13. the protocol level at which the option resides. For generic socket-level options
  14. use _NN_SOL_SOCKET_ level. For socket-type-specific options use socket type
  15. for 'level' argument (e.g. _NN_SUB_). For transport-specific options use ID of
  16. the transport as the 'level' argument (e.g. _NN_TCP_).
  17. The value is stored in the buffer pointed to by 'optval' argument. Size of the
  18. buffer is specified by the 'optvallen' argument. If the size of the option is
  19. greater than size of the buffer, the value will be silently truncated.
  20. Otherwise, the 'optvallen' will be modified to indicate the actual length of
  21. the option.
  22. _<nanomsg/nn.h>_ header defines generic socket-level options
  23. (_NN_SOL_SOCKET_ level). The options are as follows:
  24. *NN_DOMAIN*::
  25. Returns the domain constant as it was passed to _nn_socket()_.
  26. *NN_PROTOCOL*::
  27. Returns the protocol constant as it was passed to _nn_socket()_.
  28. *NN_LINGER*::
  29. Specifies how long the socket should try to send pending outbound messages
  30. after _nn_close()_ have been called, in milliseconds. Negative value means
  31. infinite linger. The type of the option is int. Default value
  32. is 1000 (1 second).
  33. *NN_SNDBUF*::
  34. Size of the send buffer, in bytes. To prevent blocking for messages larger
  35. than the buffer, exactly one message may be buffered in addition to the data
  36. in the send buffer. The type of this option is int. Default value is 128kB.
  37. *NN_RCVBUF*::
  38. Size of the receive buffer, in bytes. To prevent blocking for messages
  39. larger than the buffer, exactly one message may be buffered in addition
  40. to the data in the receive buffer. The type of this option is int. Default
  41. value is 128kB.
  42. *NN_RCVMAXSIZE*::
  43. Maximum message size that can be received, in bytes. Negative value means
  44. that the received size is limited only by available addressable memory. The
  45. type of this option is int. Default is 1024kB.
  46. *NN_SNDTIMEO*::
  47. The timeout for send operation on the socket, in milliseconds. If message
  48. cannot be sent within the specified timeout, ETIMEDOUT error is returned.
  49. Negative value means infinite timeout. The type of the option is int.
  50. Default value is -1.
  51. *NN_RCVTIMEO*::
  52. The timeout for recv operation on the socket, in milliseconds. If message
  53. cannot be received within the specified timeout, ETIMEDOUT error is returned.
  54. Negative value means infinite timeout. The type of the option is int.
  55. Default value is -1.
  56. *NN_RECONNECT_IVL*::
  57. For connection-based transports such as TCP, this option specifies how
  58. long to wait, in milliseconds, when connection is broken before trying
  59. to re-establish it. Note that actual reconnect interval may be randomised
  60. to some extent to prevent severe reconnection storms. The type of the option
  61. is int. Default value is 100 (0.1 second).
  62. *NN_RECONNECT_IVL_MAX*::
  63. This option is to be used only in addition to _NN_RECONNECT_IVL_ option.
  64. It specifies maximum reconnection interval. On each reconnect attempt,
  65. the previous interval is doubled until _NN_RECONNECT_IVL_MAX_ is reached.
  66. Value of zero means that no exponential backoff is performed and reconnect
  67. interval is based only on _NN_RECONNECT_IVL_. If _NN_RECONNECT_IVL_MAX_ is
  68. less than _NN_RECONNECT_IVL_, it is ignored. The type of the option is int.
  69. Default value is 0.
  70. *NN_SNDPRIO*::
  71. Retrieves outbound priority currently set on the socket. This
  72. option has no effect on socket types that send messages to all the peers.
  73. However, if the socket type sends each message to a single peer
  74. (or a limited set of peers), peers with high priority take precedence
  75. over peers with low priority. The type of the option is int. Highest
  76. priority is 1, lowest priority is 16. Default value is 8.
  77. *NN_RCVPRIO*::
  78. Sets inbound priority for endpoints subsequently added to the socket. This
  79. option has no effect on socket types that are not able to receive messages.
  80. When receiving a message, messages from peer with higher priority are
  81. received before messages from peer with lower priority. The type of the
  82. option is int. Highest priority is 1, lowest priority is 16. Default value
  83. is 8.
  84. *NN_IPV4ONLY*::
  85. If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6
  86. addresses are used. The type of the option is int. Default value is 1.
  87. *NN_SNDFD*::
  88. Retrieves a file descriptor that is readable when a message can be sent
  89. to the socket. The descriptor should be used only for polling and never
  90. read from or written to. The type of the option is same as the type of
  91. file descriptor on the platform. That is, int on POSIX-complaint platforms
  92. and SOCKET on Windows. The descriptor becomes invalid and should not be
  93. used any more once the socket is closed. This socket option is not available
  94. for unidirectional recv-only socket types.
  95. *NN_RCVFD*::
  96. Retrieves a file descriptor that is readable when a message can be received
  97. from the socket. The descriptor should be used only for polling and never
  98. read from or written to. The type of the option is same as the type of
  99. file descriptor on the platform. That is, int on POSIX-complaint platforms
  100. and SOCKET on Windows. The descriptor becomes invalid and should not be
  101. used any more once the socket is closed. This socket option is not available
  102. for unidirectional send-only socket types.
  103. *NN_SOCKET_NAME*::
  104. Socket name for error reporting and statistics. The type of the option
  105. is string. Default value is "N" where N is socket integer.
  106. *This option is experimental, see <<nn_env#,nn_env(7)>> for details*
  107. *NN_MAXTTL*::
  108. Retrieves the maximum number of "hops" a message can go through before
  109. it is dropped. Each time the message is received (for example via
  110. the <<nn_device#,nn_device(3)>> function) counts as a single hop.
  111. This provides a form of protection against inadvertent loops.
  112. RETURN VALUE
  113. ------------
  114. If the function succeeds zero is returned. Otherwise, -1 is
  115. returned and 'errno' is set to to one of the values defined below.
  116. ERRORS
  117. ------
  118. *EBADF*::
  119. The provided socket is invalid.
  120. *ENOPROTOOPT*::
  121. The option is unknown at the level indicated.
  122. *ETERM*::
  123. The library is terminating.
  124. EXAMPLE
  125. -------
  126. ----
  127. int linger;
  128. size_t sz = sizeof (linger);
  129. nn_getsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, &sz);
  130. ----
  131. SEE ALSO
  132. --------
  133. <<nn_socket#,nn_socket(3)>>
  134. <<nn_setsockopt#,nn_setsockopt(3)>>
  135. <<nanomsg#,nanomsg(7)>>
  136. AUTHORS
  137. -------
  138. link:mailto:sustrik@250bpm.com[Martin Sustrik]
  139. link:mailto:garrett@damore.org[Garrett D'Amore]