Skip to content

fixed TLSSocket documentation error from Issue #3963. #14062

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

Closed
wants to merge 13 commits 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
22 changes: 22 additions & 0 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,28 @@ The `callback` function, if specified, will be added as a listener for the

`tls.connect()` returns a [`tls.TLSSocket`][] object.

To upgrade an existing instance of `net.Socket` to a
Copy link
Contributor

Choose a reason for hiding this comment

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

this is documented above, does it really need an example? was the existing description of the socket: option somehow deficient?

`tls.TLSSocket`, pass it to `tls.connect()` as
the socket option:

```js
const { Socket } = require('net');
const tls = require('tls');
const socket = new Socket();
const secureSock = tls.connect({ socket }, () => {
console.log('The TLS socket has been connected.');
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point, neither the underlying Socket or tls.TLSSocket are connected, so the log message is misleading (see description of the socket option)

Copy link
Member

@tniessen tniessen Jul 5, 2017

Choose a reason for hiding this comment

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

This must have slipped through, earlier commits had the actual connect code in them, so the message was justified at that point.

});
```

If no socket is provided, this function will create a new TLS socket:

```js
const tls = require('tls');
const secureSock = tls.connect({ port: 443, host: 'example.org' }, () => {
console.log('The TLS socket has been connected.');
});
```

The following implements a simple "echo server" example:

```js
Expand Down