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

UDP/Datagram Sockets documentation #23952

Closed
dsinecos opened this issue Oct 29, 2018 · 5 comments
Closed

UDP/Datagram Sockets documentation #23952

dsinecos opened this issue Oct 29, 2018 · 5 comments
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@dsinecos
Copy link
Contributor

Module
UDP/ Datagram Sockets documentation

Current Documentation

The description for the listening event for dgram.Socket states that 'This occurs as soon as UDP sockets are created'. Reference

Expected Documentation

To my understanding this is incorrect as the listening event is fired once the socket is bound to a Port and Address. This is also stated elsewhere in the documentation (Refer) 'Once binding is complete, a 'listening' event is emitted ...'

@bnoordhuis bnoordhuis added dgram Issues and PRs related to the dgram subsystem / UDP. doc Issues and PRs related to the documentations. labels Oct 29, 2018
@bnoordhuis
Copy link
Member

bnoordhuis commented Oct 29, 2018

I agree the wording is kind of confusing, even if it's technically correct.

"As UDP sockets are created" refers to the underlying OS socket. They're addressable the moment they're created but Node.js delays creating them until the first send() or bind(). To illustrate:

const dgram = require('dgram')
const s = dgram.createSocket('udp4')
//console.log(s.address())  // would fail with "getsockname EINVAL", no socket yet
s.on('listening', () => console.log(s.address())
s.send('', 12345, () => console.log('done'))
// Prints:
//   { address: '0.0.0.0', family: 'IPv4', port: <random port> }
//   done 

@dsinecos
Copy link
Contributor Author

Thanks @bnoordhuis :)
This cleared up my confusion.

Borrowing from your explanation I think the existing description could be modified to something like the following -

" The listening event is emitted on the first invocation of either send() or bind() for the respective socket.

While the sockets are addressable immediately after creation using dgram.createSocket NodeJS delays creating the underlying OS socket until the first send() or bind() call is made for the respective socket.

The listening event is emitted when the underlying OS socket is created (ie on the first invocation of either send() or bind()) "

@bnoordhuis
Copy link
Member

Yes, sounds good. Maybe even cut it short by a few more words. Want to open a PR?

@dsinecos
Copy link
Contributor Author

dsinecos commented Oct 29, 2018

Yup, I'll edit it and open a PR

Edit: Submitted a PR here - #23959

dsinecos added a commit to dsinecos/node that referenced this issue Nov 29, 2018
Clarify that the `'listening'` event is emitted when the
underlying OS socket is created

This occurs when either `socket.send()` or `socket.bind()`
are first invoked for the respective socket.

Fixes: nodejs#23952
@tjconcept
Copy link
Contributor

I believe this issue should be closed as #32581 landed.

@jasnell jasnell added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Jun 26, 2020
@jasnell jasnell closed this as completed Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

4 participants