Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: mention errors thrown by methods called on an unbound dgram.Socket #33983

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions doc/api/dgram.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ Tells the kernel to join a multicast group at the given `multicastAddress` and
one interface and will add membership to it. To add membership to every
available interface, call `addMembership` multiple times, once per interface.

When called on an unbound socket, implicitly binds to a random port, listening
on all interfaces.
mkrawczuk marked this conversation as resolved.
Show resolved Hide resolved

When sharing a UDP socket across multiple `cluster` workers, the
`socket.addMembership()` function must be called only once or an
`EADDRINUSE` error will occur:
Expand Down Expand Up @@ -143,6 +146,10 @@ is not specified, the operating system will choose one interface and will add
membership to it. To add membership to every available interface, call
`socket.addSourceSpecificMembership()` multiple times, once per interface.


mkrawczuk marked this conversation as resolved.
Show resolved Hide resolved
When called on an unbound socket, implicitly binds to a random port, listening
mkrawczuk marked this conversation as resolved.
Show resolved Hide resolved
on all interfaces.

### `socket.address()`
<!-- YAML
added: v0.1.99
Expand All @@ -154,6 +161,8 @@ Returns an object containing the address information for a socket.
For UDP sockets, this object will contain `address`, `family` and `port`
properties.

Throws `EBADF` if called on an unbound socket.

### `socket.bind([port][, address][, callback])`
<!-- YAML
added: v0.1.99
Expand Down Expand Up @@ -298,8 +307,9 @@ added: v12.0.0
-->

A synchronous function that disassociates a connected `dgram.Socket` from
its remote address. Trying to call `disconnect()` on an already disconnected
socket will result in an [`ERR_SOCKET_DGRAM_NOT_CONNECTED`][] exception.
its remote address. Trying to call `disconnect()` on an unbound or already
disconnected socket will result in an [`ERR_SOCKET_DGRAM_NOT_CONNECTED`][]
exception.

### `socket.dropMembership(multicastAddress[, multicastInterface])`
<!-- YAML
Expand Down Expand Up @@ -344,13 +354,17 @@ added: v8.7.0

* Returns: {number} the `SO_RCVBUF` socket receive buffer size in bytes.

Throws [`ERR_SOCKET_BUFFER_SIZE`][] if called on an unbound socket.
mkrawczuk marked this conversation as resolved.
Show resolved Hide resolved

### `socket.getSendBufferSize()`
<!-- YAML
added: v8.7.0
-->

* Returns: {number} the `SO_SNDBUF` socket send buffer size in bytes.

Throws [`ERR_SOCKET_BUFFER_SIZE`][] if called on an unbound socket.

### `socket.ref()`
<!-- YAML
added: v0.9.1
Expand Down Expand Up @@ -452,6 +466,8 @@ Offset and length are optional but both *must* be set if either are used.
They are supported only when the first argument is a `Buffer`, a `TypedArray`,
or a `DataView`.

Throws [`ERR_SOCKET_BAD_PORT`][] if called on an unbound socket.

Example of sending a UDP packet to a port on `localhost`;

```js
Expand Down Expand Up @@ -532,6 +548,8 @@ added: v0.6.9
Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP
packets may be sent to a local interface's broadcast address.

Throws `EBADF` if called on an unbound socket.

### `socket.setMulticastInterface(multicastInterface)`
<!-- YAML
added: v8.6.0
Expand All @@ -558,6 +576,8 @@ also use explicit scope in addresses, so only packets sent to a multicast
address without specifying an explicit scope are affected by the most recent
successful use of this call.

Throws `EBADF` if called on an unbound socket.

#### Example: IPv6 outgoing multicast interface

On most systems, where scope format uses the interface name:
Expand Down Expand Up @@ -620,6 +640,8 @@ added: v0.3.8
Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`,
multicast packets will also be received on the local interface.

Throws `EBADF` if called on an unbound socket.

### `socket.setMulticastTTL(ttl)`
<!-- YAML
added: v0.3.8
Expand All @@ -635,6 +657,8 @@ decremented to 0 by a router, it will not be forwarded.

The `ttl` argument may be between 0 and 255. The default on most systems is `1`.

Throws `EBADF` if called on an unbound socket.

### `socket.setRecvBufferSize(size)`
<!-- YAML
added: v8.7.0
Expand All @@ -645,6 +669,8 @@ added: v8.7.0
Sets the `SO_RCVBUF` socket option. Sets the maximum socket receive buffer
in bytes.

Throws [`ERR_SOCKET_BUFFER_SIZE`][] if called on an unbound socket.

### `socket.setSendBufferSize(size)`
<!-- YAML
added: v8.7.0
Expand All @@ -655,6 +681,8 @@ added: v8.7.0
Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer
in bytes.

Throws [`ERR_SOCKET_BUFFER_SIZE`][] if called on an unbound socket.

### `socket.setTTL(ttl)`
<!-- YAML
added: v0.1.101
Expand All @@ -671,6 +699,8 @@ Changing TTL values is typically done for network probes or when multicasting.
The `ttl` argument may be between between 1 and 255. The default on most systems
is 64.

Throws `EBADF` if called on an unbound socket.

### `socket.unref()`
<!-- YAML
added: v0.9.1
Expand Down Expand Up @@ -749,6 +779,8 @@ and `udp6` sockets). The bound address and port can be retrieved using
[`socket.address().address`][] and [`socket.address().port`][].

[`'close'`]: #dgram_event_close
[`ERR_SOCKET_BAD_PORT`]: errors.html#errors_err_socket_bad_port
[`ERR_SOCKET_BUFFER_SIZE`]: errors.html#errors_err_socket_buffer_size
[`ERR_SOCKET_DGRAM_IS_CONNECTED`]: errors.html#errors_err_socket_dgram_is_connected
[`ERR_SOCKET_DGRAM_NOT_CONNECTED`]: errors.html#errors_err_socket_dgram_not_connected
[`Error`]: errors.html#errors_class_error
Expand Down