-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Conversation
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). |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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`. |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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
348944d
to
186a790
Compare
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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap to 80 columns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of sort order
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.Socket
s, so maybe servers (…) and connections (…)
is a bit better?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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()`][])
?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 new
ed 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). |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
434b6ac
to
fb61a63
Compare
Addressed comments and rebased since #11167 is merged. |
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/6699/ |
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! |
* 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 <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This is not landing cleanly on v7.x-staging. Mind submitting a backport PR? |
Should this be backported to |
explain that it provides TCP or local communications
(domain sockets on UNIX, named pipes on Windows) functionalities.
allowHalfOpen
server.listen()
API in a list, explainthe common arguments and notes in the same place.
Some minor improvements:
net.Server
constructorserver.listen()
TODO: do the same thing to
net.Socket
if this one is good to go.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
net, doc