Skip to content

Commit

Permalink
net: don't normalize twice in Socket#connect()
Browse files Browse the repository at this point in the history
Split up Socket#connect() so that we don't call normalizeArgs() twice
when invoking net.connect() or net.createConnection().

PR-URL: #12342
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
bnoordhuis authored and evanlucas committed May 2, 2017
1 parent 0e40e6d commit 94385c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function connect() {
socket.setTimeout(options.timeout);
}

return Socket.prototype.connect.call(socket, options, cb);
return realConnect.call(socket, options, cb);
}


Expand Down Expand Up @@ -899,7 +899,11 @@ Socket.prototype.connect = function() {
const normalized = normalizeArgs(args);
const options = normalized[0];
const cb = normalized[1];
return realConnect.call(this, options, cb);
};


function realConnect(options, cb) {
if (this.write !== Socket.prototype.write)
this.write = Socket.prototype.write;

Expand Down Expand Up @@ -940,7 +944,7 @@ Socket.prototype.connect = function() {
lookupAndConnect(this, options);
}
return this;
};
}


function lookupAndConnect(self, options) {
Expand Down

0 comments on commit 94385c6

Please sign in to comment.