Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tls: do not confuse TLSSocket and Socket
Don't use "socket" to describe two different objects in the same
function.
  • Loading branch information
sam-github committed Dec 27, 2018
commit 2e526ce8d971a4069bf43c339738a84f5962305b
24 changes: 13 additions & 11 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,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 @@ -1238,12 +1238,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 @@ -1252,13 +1254,13 @@ 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) {
if (!ipServernameWarned && net.isIP(options.servername)) {
Expand All @@ -1270,14 +1272,14 @@ exports.connect = function connect(...args) {
);
ipServernameWarned = true;
}
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;
};