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: various improvements to net.md #11636

Closed
wants to merge 7 commits into from

Conversation

joyeecheung
Copy link
Member

  • Improve general description of the module, specifically,
    explain that it provides TCP or local communications
    (domain sockets on UNIX, named pipes on Windows) functionalities.
  • Improve explanation of allowHalfOpen
  • Nest the overloaded server.listen() API in a list, explain
    the common arguments and notes in the same place.

Some minor improvements:

  • Add description to the net.Server constructor
  • Add type annotations to server.listen()
  • Add contexts to method links

TODO: do the same thing tonet.Socket if this one is good to go.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

net, doc

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. net Issues and PRs related to the net subsystem. labels Mar 1, 2017
doc/api/net.md Outdated
this module with `require('net');`.
The `net` module provides an asynchronous network API for creating
servers ([`net.Server`][]) and clients ([`net.Socket`][]) that implement TCP
or local communications (domain sockets on UNIX, named pipes on Windows).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it also underlies UDP? or does that reimplement sockets?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UDP is different code, no support for it in net

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:S just got enlightened by @addaleax , the stuff in this module is stream-based, UDP(dgram) is not.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit.

doc/api/net.md Outdated
* [`server.listen(handle[, backlog][, callback])`][`server.listen(handle, backlog, callback)`]
* [`server.listen(options[, callback])`][`server.listen(options, callback)`]
* [`server.listen(path[, backlog][, callback])`][`server.listen(path, backlog, callback)`] for local servers
* [`server.listen([port][, host][, backlog][, callback])`][`server.listen(port, host, backlog, callback)`] for TCP servers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please line wrap at 80 chars

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just skimmed over it but looks pretty good in general (and helpful!) :)

doc/api/net.md Outdated

Note:

* All [`net.Socket`][] are set to `SO_REUSEADDR`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention that this flag is explained in socket(7)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trried http://man7.org/linux/man-pages/man7/socket.7.html but couldn't find an ID in that page(and it's a really long page)...maybe just add it because it's better than nothing? :3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung Yeah, it’s better than nothing. I would even be okay with telling people to Ctrl+F it. 😄

doc/api/net.md Outdated
Start a TCP server listening for connections on the given `port` and `host`.

If `port` is omitted or is 0, the operating system will assign a random
port, which can be retrieved by using `server.address().port`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe use arbitrary unused port instead of random port? There doesn’t need to be any true randomness in the port choice

@joyeecheung
Copy link
Member Author

@jasnell @addaleax comments addressed, PTAL

@joyeecheung joyeecheung force-pushed the improve-net-doc branch 2 times, most recently from 348944d to 186a790 Compare March 1, 2017 17:16
doc/api/net.md Outdated

Begin accepting connections on the specified `port` and `hostname`. If the
`hostname` is omitted, the server will accept connections on the
If `port` is omitted or is 0, the operating system will assign an arbitrary unused port, which can be retrieved by using `server.address().port`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap to 80 columns

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are almost sorted in the markdown links at the bottom of page, but otherwise, LGTM

doc/api/net.md Outdated
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback
[`dns.lookup()` hints]: dns.html#dns_supported_getaddrinfo_flags
[`end()`]: #net_socket_end_data_encoding
[`socket.end()`]: #net_socket_end_data_encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is out of sort order now

doc/api/net.md Outdated
[`server.listen(handle)`]: #net_server_listen_handle_backlog_callback
[`server.listen(options)`]: #net_server_listen_options_callback
[`server.listen(port, host)`]: #net_server_listen_port_host_backlog_callback
[`server.listen(path)`]: #net_server_listen_path_backlog_callback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of sort order

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM!

doc/api/net.md Outdated
functions for creating both servers and clients (called streams). You can include
this module with `require('net');`.
The `net` module provides an asynchronous network API for creating stream-based
servers ([`net.Server`][]) and clients ([`net.Socket`][]) that implement TCP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm… both ends of a connection are net.Sockets, so maybe servers (…) and connections (…) is a bit better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the examples for net.Socket call the returned value client though...? I guess saying it provides clients would help people looking for one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument for the 'connection' listener is a net.Socket, that’s where the non-client sockets come from.

I guess saying it provides clients would help people looking for one.

Not disagreeing! It’s definitely good to state that net provides servers and clients… I’m just trying to say that I would prefer to avoid any confusion of associating net.Socket with client.

If you think this is a non-issue, feel free to ignore this :)

Copy link
Member Author

@joyeecheung joyeecheung Mar 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps

..and clients ([`net.Socket`][] calling [`connect()`][])

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung In that case we could just refer to createConnection 😄

But, yeah, this is getting really bike-shed-y and I trust your judgement on this :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just put net.createServer and net.createConnection then (the classes are not usually newed anyway :D)

On a side note, what is the preferred way to create a client? net.createConnection and net.connect are just aliases now..(net.createConnection does look better when you put it alongside net.createServer though)

doc/api/net.md Outdated

Note:

* All [`net.Socket`][] are set to `SO_REUSEADDR`(See [socket(7)][] for details).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing space before the opening parenthesis

doc/api/net.md Outdated
@@ -392,11 +407,12 @@ added: v0.1.90

Emitted when the other end of the socket sends a FIN packet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sends a FIN packet, thus ending the readable side of the socket.?

doc/api/net.md Outdated
By default (`allowHalfOpen` is `false`) the socket will send a FIN packet
back and destroy its file descriptor once it has written out its pending
write queue. However, if `allowHalfOpen` is set to `true`, the socket will
not automatically [`end()`][`socket.end()`] its side, allowing the user to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: its writable side

* Improve general description of the module, specifically,
  explain that it provides TCP or local communications
  (domain sockets on UNIX, named pipes on Windows) functionalities.
* Improve explanation of `allowHalfOpen`
* Nest the overloaded `server.listen()` API in a list, explain
  the common arguments and notes in the same place.

Some minor improvements:

* Add description to the `net.Server` constructor
* Add type annotations to `server.listen()`
* Add contexts to method links
@joyeecheung
Copy link
Member Author

Addressed comments and rebased since #11167 is merged.

@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

osx build failure is unrelated, tried another one and it build scucessfully.. https://ci.nodejs.org/job/node-test-commit-osx/8200/

Landed in 3b05153, thanks!

@joyeecheung joyeecheung closed this Mar 4, 2017
joyeecheung added a commit that referenced this pull request Mar 4, 2017
* Improve general description of the module, specifically,
  explain that it provides TCP or local communications
  (domain sockets on UNIX, named pipes on Windows) functionalities.
* Improve explanation of `allowHalfOpen`
* Nest the overloaded `server.listen()` API in a list, explain
  the common arguments and notes in the same place.

Some minor improvements:

* Add description to the `net.Server` constructor
* Add type annotations to `server.listen()`
* Add contexts to method links

PR-URL: #11636
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@evanlucas
Copy link
Contributor

This is not landing cleanly on v7.x-staging. Mind submitting a backport PR?

@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants