Skip to content

Commit 76bc4c7

Browse files
committed
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 eaa9e0e commit 76bc4c7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

doc/api/dgram.markdown

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +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, string, or an array of either. Message to be
190+
* `msg` Buffer object, string, or an array of either. Message to be
191191
sent.
192-
* `offset` Integer. Offset in the buffer where the message starts.
193-
* `length` Integer. Number of bytes in the message.
192+
* `offset` Integer. Optional. Offset in the buffer where the message starts.
193+
* `length` Integer. Optional. Number of bytes in the message.
194194
* `port` Integer. Destination port.
195195
* `address` String. Destination hostname or IP address.
196196
* `callback` Function. Called when the message has been sent. Optional.
197197

198198
Broadcasts a datagram on the socket. The destination `port` and `address` must
199199
be specified.
200200

201-
The `buf` argument is a [`Buffer`] object containing the message. The `offset`
202-
and `length` specify the offset within the `Buffer` where the message begins
203-
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
204207
contain multi-byte characters, `offset` and `length` will be calculated with
205208
respect to [byte length][] and not the character position.
209+
If `msg` is an array, `offset` and `length` must not be specified.
206210

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

0 commit comments

Comments
 (0)