Skip to content

Commit

Permalink
tls: do not confuse TLSSocket and Socket
Browse files Browse the repository at this point in the history
Don't use "socket" to describe two different objects in the same
function.

PR-URL: #25153
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
sam-github authored and BridgeAR committed Jan 9, 2019
1 parent e1d4f43 commit 453bd18
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ exports.connect = function connect(...args) {

const context = options.secureContext || tls.createSecureContext(options);

var socket = new TLSSocket(options.socket, {
var tlssock = new TLSSocket(options.socket, {
pipe: !!options.path,
secureContext: context,
isServer: false,
Expand All @@ -1235,12 +1235,14 @@ exports.connect = function connect(...args) {
requestOCSP: options.requestOCSP
});

socket[kConnectOptions] = options;
tlssock[kConnectOptions] = options;

if (cb)
socket.once('secureConnect', cb);
tlssock.once('secureConnect', cb);

if (!options.socket) {
// If user provided the socket, its their responsibility to manage its
// connectivity. If we created one internally, we connect it.
const connectOpt = {
path: options.path,
port: options.port,
Expand All @@ -1249,22 +1251,22 @@ exports.connect = function connect(...args) {
localAddress: options.localAddress,
lookup: options.lookup
};
socket.connect(connectOpt, socket._start);
tlssock.connect(connectOpt, tlssock._start);
}

socket._releaseControl();
tlssock._releaseControl();

if (options.session)
socket.setSession(options.session);
tlssock.setSession(options.session);

if (options.servername)
socket.setServername(options.servername);
tlssock.setServername(options.servername);

if (options.socket)
socket._start();
tlssock._start();

socket.on('secure', onConnectSecure);
socket.once('end', onConnectEnd);
tlssock.on('secure', onConnectSecure);
tlssock.once('end', onConnectEnd);

return socket;
return tlssock;
};

0 comments on commit 453bd18

Please sign in to comment.