-
Notifications
You must be signed in to change notification settings - Fork 30k
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: improve docs for net.connect, net.createConnection, net.Socket #11700
Conversation
8768384
to
3271f84
Compare
doc/api/net.md
Outdated
user and used as a client (with [`connect()`][]) or they can be created by Node.js | ||
and passed to the user through the `'connection'` event of a server. | ||
This class is an abstraction of a TCP socket, a UNIX domain socket, or | ||
a Windows named pipe. A `net.Socket` is also a [duplex stream][], so it |
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.
consider: a abstraction of a TCP or local streaming socket (local uses named pipes on Windows, and UNIX domain sockets otherwise)
... this long list of underlying technologies seemed random to you at first, I think it will confuse others, and it would be good to emphasize the OS mechanism being abstracted is "local streaming IPC", it just happens to have different names on UNIX and Windows (the Windows O/S devs weren't about to call a core IPC mechanism "unix" I guess ;-).
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 have considered using the term IPC but remembered people are using net
abstractions over Windows named pipes for RPC as well? (I think I've seem issues about access permissions before, couldn't find the link).
So maybe: a abstraction of a TCP or streaming socket (uses named pipes on Windows, and UNIX domain sockets otherwise)
(loses the local part)?
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.
Er, wait, I think IPC still works because technically the name IPC doesn't imply it's local, it can be remote. s/streaming socket/streaming IPC/
?
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've never seen anything that suggests that windows named pipes can be used between machines. And IPC doesn't have an exact definition, its like the word "process" itself, but it does usually imply same-host. Anyhow, I'm ok with any reasonable phrase, that we define and then use instead of writing out "named pipes on Windows and UNIX domain sockets on non-Windows" over and over.... @piscisaureus can named pipes be used between hosts?
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.
FWIW, the MSDN says:
Named pipes can be used to provide communication between processes on the same computer or between processes on different computers across a network. If the server service is running, all named pipes are accessible remotely. If you intend to use a named pipe locally only, deny access to NT AUTHORITY\NETWORK or switch to local RPC.
I am not sure if Node.js actually supports this, but looks like the remote access is configured outside the application?
(er, nevermind, just saw your comment below this :D)
doc/api/net.md
Outdated
a Windows named pipe. A `net.Socket` is also a [duplex stream][], so it | ||
can be both readable and writable, and it is also a [`EventEmitter`][]. | ||
|
||
A `net.Socket` can be created by the user and used as an abstraction |
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.
"used as an abstraction of the client" is a bit convoluted in my opinion, consider: "used directly to connect to a server". Almost all programming objects are in some sense "abstractions" (a url.URL is an abstraction of a "URL", a js-String is an abstraction of a "sequence of characters", etc., but its not how we usually describe them).
doc/api/net.md
Outdated
of the client. For example, it is returned by [`net.createConnection()`][], | ||
so the user can use it to interact with the server. | ||
|
||
It can also be be created by Node.js and passed to the user as an abstraction |
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.
consider: "passed to the user when a connection is received"
doc/api/net.md
Outdated
`net.Socket` instances are [`EventEmitter`][] with the following events: | ||
* `options` {Object} Available options are: | ||
* `fd`: {number | null} Defaults to `null`. If specified, wrap around an | ||
existing socket with the given file descriptor. |
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.
otherwise ...
? If unspecified, the fd/socket will be created should be stated.
doc/api/net.md
Outdated
existing socket with the given file descriptor. | ||
* `allowHalfOpen` {boolean} Default to `false`. Indicates whether | ||
half-opened TCP connections are allowed. See [`net.createServer()`][] | ||
and [`'end'`][] event 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.
and the end event for details
<--- need a "the"
doc/api/net.md
Outdated
- `hints`: [`dns.lookup()` hints][]. Defaults to `0`. | ||
* `port` {number} Required. Port the socket should connect to. | ||
* `host` {string} Host the socket should connect to. Defaults to `'localhost'`. | ||
* `localAddress` {string} Optional. Local address the socket should send |
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.
"should connect from" (you don't really "send" connections)
doc/api/net.md
Outdated
* `host` {string} Host the socket should connect to. Defaults to `'localhost'`. | ||
* `localAddress` {string} Optional. Local address the socket should send | ||
connections from. | ||
* `localPort` {number} Optional. Local port the socket should send connections |
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.
ditto
doc/api/net.md
Outdated
|
||
`net.Socket` instances are [`EventEmitter`][] with the following events: | ||
* `options` {Object} Available options are: | ||
* `fd`: {number | null} Defaults to `null`. If specified, wrap around an |
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.
general comment: there is a fairly random mix of style wrt. where the default is mentioned. sometines the default is first thing mentioned (here), sometimes it is the last thing (net.connect). I think it makes more sense to describe what an option does before describing its default.
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.
+1 to describe the meaning before describing default. Also some docs use "Defaults to", some use "Default to". Not sure if we need to use present tense in the docs if a sentence starts this way? (This is a bit inconsistent in almost every API docs I've ever seen, not just Node.js..)
(random idea: it would be great if we have some structural way to describe the default, and let the doc tools generate something with different styles).
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.
"Default to X" is ungrammatical, IMO. "Defaults to X" and "Default is X" both sound OK to me. Tooling would be good, too! Lots of work, though.
doc/api/net.md
Outdated
|
||
Normally this method is not needed, as `net.createConnection` opens the | ||
socket. Use this only if you are implementing a custom Socket. | ||
* `path` {string} Required. Path the client should connect 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.
I think "Required." is unnecessary, its clearly not optional in the syntax above. There would be an awful lot of "Required." in our docs if we put that as the first word sentence for every mandatory positional parameter, which we don't.
doc/api/net.md
Outdated
|
||
## net.createConnection(options[, connectListener]) | ||
This function is asynchronous. When the connection is established, a |
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 function is asynchronous.
I think this is misleading. The connection object is returned synchronously, but the establishment of the connection is asynchronous. Better would be something like:
Creates a socket object and initiates a connection. When the connection is established....
3271f84
to
33cae98
Compare
@sam-github Thanks for the review! Addressed most comments, apart from #11700 (comment). Added a section about IPC support and how to specify the paths (mostly moved from |
@sam-github Removed the man pages references...PTAL, 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.
I like the way you have brought the IPC section out to a seperate section, looks great.
doc/api/net.md
Outdated
### Identifying paths for IPC connections | ||
|
||
[`net.connect()`][], [`net.createConnection()`][], [`server.listen()`][] and | ||
[`socket.connect()`][] takes a `path` parameter to identify IPC endpoints. |
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.
"take"
doc/api/net.md
Outdated
[`net.connect()`][], [`net.createConnection()`][], [`server.listen()`][] and | ||
[`socket.connect()`][] takes a `path` parameter to identify IPC endpoints. | ||
|
||
On UNIX, the local domain is usually known as the UNIX domain. The path is a |
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.
usually -> also
doc/api/net.md
Outdated
*Note*: Unix named pipes (FIFOs) are not supported. | ||
|
||
On Windows, the local domain is implemented using a named pipe. The path *must* | ||
refer to an entry in `\\?\pipe\` or `\\.\pipe\`. Any characters are permitted, |
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 thought if you listen on a path like 'path'
it becomes \\?\pipe\path
, not true?
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.
There will be an EACCESS if the path is not prepended with that..see nodejs/node-v0.x-archive#2797 (comment)
doc/api/net.md
Outdated
socket (NOTE: Works only when `fd` is passed). | ||
About `allowHalfOpen`, refer to [`net.createServer()`][] and [`'end'`][] event. | ||
* `options` {Object} Available options are: | ||
* `fd`: {number | null} If specified, wrap around an existing socket with |
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.
{number}
is sufficient, we don't call out undefined/null as independent types for unspecified options in our docs, not anywhere I can recall seeing. You don't do on the 3 other options that default to null
just below, for example.
doc/api/net.md
Outdated
|
||
It can also be be created by Node.js and passed to the user when a connection | ||
is received. For example, it is passed to the listeners of a | ||
[`'connection'`][] event fired on a [`net.Server`][], so the user can use |
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.
"fired" -> "emitted"
doc/api/net.md
Outdated
[half-closed]: https://tools.ietf.org/html/rfc1122#section-4.2.2.13 | ||
[IPC]: #net_ipc_support |
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 order, use default/ASCII/"C" locale sorting
doc/api/net.md
Outdated
|
||
```js | ||
const net = require('net'); | ||
``` | ||
|
||
## IPC Support | ||
|
||
The `net` module supports IPC with named pipes on Windows, and domain 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.
"UNIX domain sockets", they are never called "domain sockets"! http://man7.org/linux/man-pages/man7/unix.7.html
doc/api/net.md
Outdated
on file creation. It will be visible in the filesystem, and will *persist until | ||
unlinked*. | ||
|
||
*Note*: Unix named pipes (FIFOs) are not supported. |
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 makes it sound like its a missing feature, when actually its an entirely diffferent IPC pattern that doesn't map to duplex streams, or to client/server communication patterns. Also, I expect that they are supported by node... using the fs
API. If you are going to mention them here, I think you should mention something like "FIFOs on Unix are sometimes called "named pipes", but despite the similarity in name to Windows named pipes, they function completely differently, and aren't supported or relevant to the net
API.". I think this is getting off track, though. The only people who would read this section and think "wait, what about UNIX named pipes?" are people who already know that there are UNIX named pipes... and those people already know that a FIFO is not representable as a bi-directional stream (IMO). I'm not wondering about unix pipes, socketpairs, or message queues when I read the net docs, either.
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.
Yes it does look stranger if pulled out to here, where the context of net
being about bidirectional streams is clearer. This can be removed.
or maybe I should have waited before approving, but when the nits you thumbed up above are addressed, this LGTM |
* Nest the overloaded signatures * Add references to system call manuals * Improve links
* Nest the overloaded signatures * Improve links
499a773
to
834b9ea
Compare
Addressed comments and rebased. |
* Add type annotations to the options * Improve the descriptions of net.Socket class
2909de5
to
090607c
Compare
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
|
||
### socket.connecting | ||
<!-- YAML | ||
added: v6.1.0 | ||
--> | ||
|
||
If `true` - [`socket.connect(options[, connectListener])`][`socket.connect(options, connectListener)`] was called and | ||
If `true` - [`socket.connect(options[, connectListener])`][`socket.connect(options)`] was called and |
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 wrap at 80 chars :-)
@jasnell Fixed 80-character wrap, thanks. (Aside: the wording of Going to land this tomorrow. |
8c948d8
to
ce0c668
Compare
Landed in df97727, thanks! |
* Improve description of socket.connect, net.connect, net.createConnection * Nest the overloaded signatures * Alias net.connect to net.createConnection * Add type annotations to the options * Make a separate section to explain IPC support and how to specify the path parameter. * General improvements to wording and explanation PR-URL: #11700 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
@joyeecheung this is not landing clearly in |
* Improve description of socket.connect, net.connect, net.createConnection * Nest the overloaded signatures * Alias net.connect to net.createConnection * Add type annotations to the options * Make a separate section to explain IPC support and how to specify the path parameter. * General improvements to wording and explanation PR-URL: nodejs#11700 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Should this be backported to |
This is a follow up of #11636.
===
)Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
doc, net