Skip to content

Commit 9f7aa6f

Browse files
mcollinarvagg
authored andcommitted
doc: clarify dgram socket.send() multi-buffer support
Fixes: #5124 See: #4374 PR-URL: #5130 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a96ae2c commit 9f7aa6f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

doc/api/dgram.markdown

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,28 @@ never have reason to call this.
185185
If `multicastInterface` is not specified, the operating system will attempt to
186186
drop membership on all valid interfaces.
187187

188-
### socket.send(buf, offset, length, port, address[, callback])
188+
### socket.send(msg, [offset, length,] port, address[, callback])
189189

190-
* `buf` Buffer object or string. Message to be sent
191-
* `offset` Integer. Offset in the buffer where the message starts.
192-
* `length` Integer. Number of bytes in the message.
190+
* `msg` Buffer object, string, or an array of either. Message to be
191+
sent.
192+
* `offset` Integer. Optional. Offset in the buffer where the message starts.
193+
* `length` Integer. Optional. Number of bytes in the message.
193194
* `port` Integer. Destination port.
194195
* `address` String. Destination hostname or IP address.
195196
* `callback` Function. Called when the message has been sent. Optional.
196197

197198
Broadcasts a datagram on the socket. The destination `port` and `address` must
198199
be specified.
199200

200-
The `buf` argument is a [`Buffer`] object containing the message. The `offset`
201-
and `length` specify the offset within the `Buffer` where the message begins
202-
and the number of bytes in the message, respectively. With messages that
201+
The `msg` argument containins the message to be sent.
202+
Depending on its type, different behavior can apply. If `msg` is a `Buffer`,
203+
the `offset` and `length` specify the offset within the `Buffer` where the
204+
message begins and the number of bytes in the message, respectively.
205+
If `msg` is a `String`, then it is automatically converted to a `Buffer`
206+
with `'utf8'` enecoding. With messages that
203207
contain multi-byte characters, `offset` and `length` will be calculated with
204208
respect to [byte length][] and not the character position.
209+
If `msg` is an array, `offset` and `length` must not be specified.
205210

206211
The `address` argument is a string. If the value of `address` is a host name,
207212
DNS will be used to resolve the address of the host. If the `address` is not

0 commit comments

Comments
 (0)