-
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
net: refactor Server.prototype.listen #4039
Changes from 1 commit
d5452a6
88c44c1
df8d8c8
959582c
d1c6f7b
708e1b4
150723d
5ab4028
0bffc03
db798ea
e772fa3
3fb1435
4a65449
3848eae
4bb5770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,9 @@ function normalizeArgs(args) { | |
} | ||
|
||
var cb = args[args.length - 1]; | ||
return typeof cb === 'function' ? [options, cb] : [options]; | ||
if (typeof cb !== 'function') | ||
cb = null; | ||
return [options, cb]; | ||
} | ||
exports._normalizeArgs = normalizeArgs; | ||
|
||
|
@@ -1330,21 +1332,20 @@ Server.prototype.listen = function() { | |
var args = new Array(arguments.length); | ||
for (var i = 0; i < arguments.length; i++) | ||
args[i] = arguments[i]; | ||
args = normalizeArgs(args); | ||
var [options, cb] = normalizeArgs(args); | ||
|
||
if (args[1]) { | ||
this.once('listening', args[1]); | ||
if (typeof cb === 'function') { | ||
this.once('listening', cb); | ||
} | ||
|
||
var options = args[0]; | ||
if (arguments.length === 0 || typeof arguments[0] === 'function') { | ||
if (args.length === 0 || typeof args[0] === 'function') { | ||
// Bind to a random port. | ||
options.port = 0; | ||
} | ||
|
||
// The third optional argument is the backlog size. | ||
// When the ip is omitted it can be the second argument. | ||
var backlog = toNumber(arguments[1]) || toNumber(arguments[2]); | ||
var backlog = toNumber(args[1]) || toNumber(args[2]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean like this? var backlog = toNumber(args.length > 1 && args[1]) || toNumber(args.length > 2 && args[2]); But is it really necessary / worth it to optimize this function? I don't think it's one of the hot functions in an usual node application, you call listen once during startup and not hundreds of times a second. What is your opinion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @mscdex There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still prefer it for consistency. |
||
|
||
options = options._handle || options.handle || options; | ||
|
||
|
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.
The comment for
normalizeArgs()
needs to be updated now too.