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: Add notes how addMembership should be managed #16240

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
20 changes: 20 additions & 0 deletions doc/api/dgram.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ 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.

UDP works as a bit special with cluster. When `dgram` creates a socket in the
master process, each worker gets a copy as in `dup(2)``, except the actual
mechanism is `sendmsg(2)`` with a SCM_RIGHTS vector. Therefor, `.addMembership`
needs to be managed to be called only once.

```js
const cluster = require('cluster');
const dgram = require('dgram');

if (cluster.isMaster) {
cluster.fork(); // ok
cluster.fork(); // EADDRINUSE
} else {
const s = dgram.createSocket('udp4');
s.bind(1234, () => {
s.addMembership('224.0.0.114');
});
}
```

### socket.address()
<!-- YAML
added: v0.1.99
Expand Down