| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/opts.R |
| 3 |
\name{opt} |
| 4 |
\alias{opt} |
| 5 |
\alias{opt<-} |
| 6 |
\title{Get and Set Options for a Socket, Context, Stream, Listener or Dialer} |
| 7 |
\usage{ |
| 8 |
opt(object, name) |
| 9 |
|
| 10 |
opt(object, name) <- value |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{object}{a Socket, Context, Stream, Listener or Dialer.} |
| 14 |
|
| 15 |
\item{name}{name of option, e.g. 'recv-buffer', as a character string. See |
| 16 |
below options details.} |
| 17 |
|
| 18 |
\item{value}{value of option. Supply character type for 'string' options, |
| 19 |
integer or double for 'int', 'duration', 'size' and 'uint64', and logical |
| 20 |
for 'bool'.} |
| 21 |
} |
| 22 |
\value{ |
| 23 |
The value of the option (logical for type 'bool', integer for 'int', |
| 24 |
'duration' and 'size', character for 'string', and double for 'uint64'). |
| 25 |
} |
| 26 |
\description{ |
| 27 |
Get and set the value of options for a Socket, Context, Stream, Listener or |
| 28 |
Dialer. |
| 29 |
} |
| 30 |
\details{ |
| 31 |
Note: once a dialer or listener has started, it is not generally possible to |
| 32 |
change its configuration. Hence create the dialer or listener with |
| 33 |
\code{autostart = FALSE} if configuration needs to be set. |
| 34 |
|
| 35 |
To get or set options on a Listener or Dialer attached to a Socket or nano |
| 36 |
object, pass in the objects directly via for example \verb{$listener[[1]]} for the |
| 37 |
first Listener. |
| 38 |
|
| 39 |
Some options are only meaningful or supported in certain contexts; for |
| 40 |
example there is no single meaningful address for a socket, since sockets can |
| 41 |
have multiple dialers and endpoints associated with them. |
| 42 |
|
| 43 |
For an authoritative guide please refer to the online documentation for the |
| 44 |
NNG library at \url{https://nng.nanomsg.org/man/}. |
| 45 |
} |
| 46 |
\section{Serialization}{ |
| 47 |
|
| 48 |
|
| 49 |
Apart from the NNG options documented below, there is the following special |
| 50 |
option: |
| 51 |
|
| 52 |
\itemize{ |
| 53 |
\item 'serial' (type list) |
| 54 |
|
| 55 |
For Sockets only. This accepts a configuration created by |
| 56 |
\code{\link[=serial_config]{serial_config()}}. Setting a new configuration replaces any already set. To |
| 57 |
remove entirely, supply an empty list. Note: this option is write-only and |
| 58 |
can be set but not retrieved. |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
\section{Global Options}{ |
| 63 |
|
| 64 |
|
| 65 |
\itemize{ |
| 66 |
\item 'reconnect-time-min' (type 'ms') |
| 67 |
|
| 68 |
This is the minimum amount of time (milliseconds) to wait before attempting |
| 69 |
to establish a connection after a previous attempt has failed. This can be |
| 70 |
set on a socket, but it can also be overridden on an individual dialer. The |
| 71 |
option is irrelevant for listeners. |
| 72 |
|
| 73 |
\item 'reconnect-time-max' (type 'ms') |
| 74 |
|
| 75 |
This is the maximum amount of time (milliseconds) to wait before attempting |
| 76 |
to establish a connection after a previous attempt has failed. If this is |
| 77 |
non-zero, then the time between successive connection attempts will start |
| 78 |
at the value of 'reconnect-time-min', and grow exponentially, until it |
| 79 |
reaches this value. If this value is zero, then no exponential back-off |
| 80 |
between connection attempts is done, and each attempt will wait the time |
| 81 |
specified by 'reconnect-time-min'. This can be set on a socket, but it can |
| 82 |
also be overridden on an individual dialer. The option is irrelevant for |
| 83 |
listeners. |
| 84 |
|
| 85 |
\item 'recv-size-max' (type 'size') |
| 86 |
|
| 87 |
This is the maximum message size that the will be accepted from a remote |
| 88 |
peer. If a peer attempts to send a message larger than this, then the |
| 89 |
message will be discarded. If the value of this is zero, then no limit on |
| 90 |
message sizes is enforced. This option exists to prevent certain kinds of |
| 91 |
denial-of-service attacks, where a malicious agent can claim to want to |
| 92 |
send an extraordinarily large message, without sending any data. This |
| 93 |
option can be set for the socket, but may be overridden for on a per-dialer |
| 94 |
or per-listener basis. NOTE: Applications on hostile networks should set |
| 95 |
this to a non-zero value to prevent denial-of-service attacks. NOTE: Some |
| 96 |
transports may have further message size restrictions. |
| 97 |
|
| 98 |
\item 'recv-buffer' (type 'int') |
| 99 |
|
| 100 |
This is the depth of the socket’s receive buffer as a number of messages. |
| 101 |
Messages received by a transport may be buffered until the application has |
| 102 |
accepted them for delivery. This value must be an integer between 0 and |
| 103 |
8192, inclusive. NOTE: Not all protocols support buffering received |
| 104 |
messages. For example req can only deal with a single reply at a time. |
| 105 |
|
| 106 |
\item 'recv-timeout' (type 'ms') |
| 107 |
|
| 108 |
This is the socket receive timeout in milliseconds. When no message is |
| 109 |
available for receiving at the socket for this period of time, receive |
| 110 |
operations will fail with a return value of 5L ('timed out'). |
| 111 |
|
| 112 |
\item 'send-buffer' (type 'int') |
| 113 |
|
| 114 |
This is the depth of the socket send buffer as a number of messages. |
| 115 |
Messages sent by an application may be buffered by the socket until a |
| 116 |
transport is ready to accept them for delivery. This value must be an |
| 117 |
integer between 0 and 8192, inclusive. NOTE: Not all protocols support |
| 118 |
buffering sent messages; generally multicast protocols like pub will simply |
| 119 |
discard messages when they cannot be delivered immediately. |
| 120 |
|
| 121 |
\item 'send-timeout' (type 'ms') |
| 122 |
|
| 123 |
This is the socket send timeout in milliseconds. When a message cannot be |
| 124 |
queued for delivery by the socket for this period of time (such as if send |
| 125 |
buffers are full), the operation will fail with a return value of 5L |
| 126 |
('timed out'). |
| 127 |
|
| 128 |
\item 'recv-fd' (type 'int') |
| 129 |
|
| 130 |
This is the socket receive file descriptor. For supported protocols, this |
| 131 |
will become readable when a message is available for receiving on the |
| 132 |
socket. Attempts should not be made to read or write to the returned file |
| 133 |
descriptor, but it is suitable for use with poll(), select(), or WSAPoll() |
| 134 |
on Windows, and similar functions. |
| 135 |
|
| 136 |
\item 'send-fd' (type 'int') |
| 137 |
|
| 138 |
This is the socket send file descriptor. Attempts should not be made to |
| 139 |
read or write to the returned file descriptor, but it is suitable for use |
| 140 |
with poll(), select(), or WSAPoll() on Windows, and similar functions. |
| 141 |
|
| 142 |
\item 'socket-name' (type 'string') |
| 143 |
|
| 144 |
This is the socket name. By default this is a string corresponding to the |
| 145 |
value of the socket. The string must fit within 64-bytes, including the |
| 146 |
terminating NUL byte. The value is intended for application use, and is not |
| 147 |
used for anything in the library itself. |
| 148 |
|
| 149 |
\item 'url' (type 'string') |
| 150 |
|
| 151 |
This read-only option is used on a listener or dialer to obtain the URL |
| 152 |
with which it was configured. |
| 153 |
|
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
\section{Protocol-specific Options}{ |
| 158 |
|
| 159 |
|
| 160 |
\itemize{ |
| 161 |
\item 'req:resend-time' (type 'ms') |
| 162 |
|
| 163 |
(Request protocol) When a new request is started, a timer of this duration |
| 164 |
is also started. If no reply is received before this timer expires, then |
| 165 |
the request will be resent. (Requests are also automatically resent if the |
| 166 |
peer to whom the original request was sent disconnects, or if a peer |
| 167 |
becomes available while the requester is waiting for an available peer.) |
| 168 |
|
| 169 |
\item 'sub:subscribe' (type 'string') |
| 170 |
|
| 171 |
(Subscribe protocol) This option registers a topic that the subscriber is |
| 172 |
interested in. Each incoming message is checked against the list of |
| 173 |
subscribed topics. If the body begins with the entire set of bytes in the |
| 174 |
topic, then the message is accepted. If no topic matches, then the message |
| 175 |
is discarded. To receive all messages, set the topic to NULL. |
| 176 |
|
| 177 |
\item 'sub:unsubscribe' (type 'string') |
| 178 |
|
| 179 |
(Subscribe protocol) This option removes a topic from the subscription |
| 180 |
list. Note that if the topic was not previously subscribed to with |
| 181 |
'sub:subscribe' then an 'entry not found' error will result. |
| 182 |
|
| 183 |
\item 'sub:prefnew' (type 'bool') |
| 184 |
|
| 185 |
(Subscribe protocol) This option specifies the behavior of the subscriber |
| 186 |
when the queue is full. When TRUE (the default), the subscriber will make |
| 187 |
room in the queue by removing the oldest message. When FALSE, the |
| 188 |
subscriber will reject messages if the message queue does not have room. |
| 189 |
|
| 190 |
\item 'surveyor:survey-time' (type 'ms') |
| 191 |
|
| 192 |
(Surveyor protocol) Duration of surveys. When a new survey is started, a |
| 193 |
timer of this duration is also started. Any responses arriving after this |
| 194 |
time will be discarded. Attempts to receive after the timer expires with no |
| 195 |
other surveys started will result in an 'incorrect state' error. Attempts |
| 196 |
to receive when this timer expires will result in a 'timed out' error. |
| 197 |
|
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
\section{Transport-specific Options}{ |
| 202 |
|
| 203 |
|
| 204 |
\itemize{ |
| 205 |
\item 'ipc:permissions' (type 'int') |
| 206 |
|
| 207 |
(IPC transport) This option may be applied to a listener to configure the |
| 208 |
permissions that are used on the UNIX domain socket created by that |
| 209 |
listener. This property is only supported on POSIX systems. The value is of |
| 210 |
type int, representing the normal permission bits on a file, such as 0600 |
| 211 |
(typically meaning read-write to the owner, and no permissions for anyone |
| 212 |
else.) The default is system-specific, most often 0644. |
| 213 |
|
| 214 |
\item 'tcp-nodelay' (type 'bool') |
| 215 |
|
| 216 |
(TCP transport) This option is used to disable (or enable) the use of |
| 217 |
Nagle's algorithm for TCP connections. When TRUE (the default), messages |
| 218 |
are sent immediately by the underlying TCP stream without waiting to gather |
| 219 |
more data. When FALSE, Nagle’s algorithm is enabled, and the TCP stream may |
| 220 |
wait briefly in an attempt to coalesce messages. Nagle’s algorithm is |
| 221 |
useful on low-bandwidth connections to reduce overhead, but it comes at a |
| 222 |
cost to latency. When used on a dialer or a listener, the value affects how |
| 223 |
newly created connections will be configured. |
| 224 |
|
| 225 |
\item 'tcp-keepalive' (type 'bool') |
| 226 |
|
| 227 |
(TCP transport) This option is used to enable the sending of keep-alive |
| 228 |
messages on the underlying TCP stream. This option is FALSE by default. |
| 229 |
When enabled, if no messages are seen for a period of time, then a zero |
| 230 |
length TCP message is sent with the ACK flag set in an attempt to tickle |
| 231 |
some traffic from the peer. If none is still seen (after some |
| 232 |
platform-specific number of retries and timeouts), then the remote peer is |
| 233 |
presumed dead, and the connection is closed. When used on a dialer or a |
| 234 |
listener, the value affects how newly created connections will be |
| 235 |
configured. This option has two purposes. First, it can be used to detect |
| 236 |
dead peers on an otherwise quiescent network. Second, it can be used to |
| 237 |
keep connection table entries in NAT and other middleware from expiring due |
| 238 |
to lack of activity. |
| 239 |
|
| 240 |
\item 'tcp-bound-port' (type 'int') |
| 241 |
|
| 242 |
(TCP transport) Local TCP port number. This is used on a listener, and is |
| 243 |
intended to be used after starting the listener in combination with a |
| 244 |
wildcard (0) local port. This determines the actual ephemeral port that was |
| 245 |
selected and bound. The value is provided as an integer, but only the low |
| 246 |
order 16 bits will be set, and is in native byte order for convenience. |
| 247 |
|
| 248 |
\item 'ws:request-headers' (type 'string') |
| 249 |
|
| 250 |
(WebSocket transport) Concatenation of multiple lines terminated by CRLF |
| 251 |
sequences, that can be used to add further headers to the HTTP request sent |
| 252 |
when connecting. This option can be set on dialers, and must be done before |
| 253 |
the transport is started. |
| 254 |
|
| 255 |
\item 'ws:response-headers' (type 'string') |
| 256 |
|
| 257 |
(WebSocket transport) Concatenation of multiple lines terminated by CRLF |
| 258 |
sequences, that can be used to add further headers to the HTTP response |
| 259 |
sent when connecting. This option can be set on listeners, and must be done |
| 260 |
before the transport is started. |
| 261 |
|
| 262 |
\item 'ws:request-uri' (type 'string') |
| 263 |
|
| 264 |
(WebSocket transport) For obtaining the URI sent by the client. This can be |
| 265 |
useful when a handler supports an entire directory tree. |
| 266 |
|
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
\examples{ |
| 271 |
s <- socket("pair") |
| 272 |
opt(s, "send-buffer") |
| 273 |
close(s) |
| 274 |
|
| 275 |
s <- socket("req") |
| 276 |
ctx <- context(s) |
| 277 |
opt(ctx, "send-timeout") |
| 278 |
close(ctx) |
| 279 |
close(s) |
| 280 |
|
| 281 |
s <- socket("pair", dial = "inproc://nanonext", autostart = FALSE) |
| 282 |
opt(s$dialer[[1]], "reconnect-time-min") |
| 283 |
close(s) |
| 284 |
|
| 285 |
s <- socket("pair", listen = "inproc://nanonext", autostart = FALSE) |
| 286 |
opt(s$listener[[1]], "recv-size-max") |
| 287 |
close(s) |
| 288 |
|
| 289 |
s <- socket("pair") |
| 290 |
opt(s, "recv-timeout") <- 2000 |
| 291 |
close(s) |
| 292 |
|
| 293 |
s <- socket("req") |
| 294 |
ctx <- context(s) |
| 295 |
opt(ctx, "send-timeout") <- 2000 |
| 296 |
close(ctx) |
| 297 |
close(s) |
| 298 |
|
| 299 |
s <- socket("pair", dial = "inproc://nanonext", autostart = FALSE) |
| 300 |
opt(s$dialer[[1]], "reconnect-time-min") <- 2000 |
| 301 |
start(s$dialer[[1]]) |
| 302 |
close(s) |
| 303 |
|
| 304 |
s <- socket("pair", listen = "inproc://nanonext", autostart = FALSE) |
| 305 |
opt(s$listener[[1]], "recv-size-max") <- 1024 |
| 306 |
start(s$listener[[1]]) |
| 307 |
close(s) |
| 308 |
|
| 309 |
} |