-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
lib: reduce process.binding() calls #1367
Changes from 2 commits
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 |
---|---|---|
|
@@ -7,8 +7,10 @@ const util = require('util'); | |
const assert = require('assert'); | ||
const cares = process.binding('cares_wrap'); | ||
const uv = process.binding('uv'); | ||
const Pipe = process.binding('pipe_wrap').Pipe; | ||
|
||
const TTY = process.binding('tty_wrap'); | ||
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. The naming suggests it's the TTY constructor but it's really the tty_wrap object (which has the constructor as a property.) |
||
const TCP = process.binding('tcp_wrap').TCP; | ||
const Pipe = process.binding('pipe_wrap').Pipe; | ||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; | ||
const PipeConnectWrap = process.binding('pipe_wrap').PipeConnectWrap; | ||
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap; | ||
|
@@ -21,23 +23,10 @@ const exceptionWithHostPort = util._exceptionWithHostPort; | |
|
||
function noop() {} | ||
|
||
// constructor for lazy loading | ||
function createPipe() { | ||
return new Pipe(); | ||
} | ||
|
||
// constructor for lazy loading | ||
function createTCP() { | ||
var TCP = process.binding('tcp_wrap').TCP; | ||
return new TCP(); | ||
} | ||
|
||
|
||
function createHandle(fd) { | ||
var tty = process.binding('tty_wrap'); | ||
var type = tty.guessHandleType(fd); | ||
if (type === 'PIPE') return createPipe(); | ||
if (type === 'TCP') return createTCP(); | ||
var type = TTY.guessHandleType(fd); | ||
if (type === 'PIPE') return new Pipe(); | ||
if (type === 'TCP') return new TCP(); | ||
throw new TypeError('Unsupported fd type: ' + type); | ||
} | ||
|
||
|
@@ -135,6 +124,7 @@ function Socket(options) { | |
} else if (options.fd !== undefined) { | ||
this._handle = createHandle(options.fd); | ||
this._handle.open(options.fd); | ||
|
||
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. Can you undo the whitespace change? |
||
if ((options.fd == 1 || options.fd == 2) && | ||
(this._handle instanceof Pipe) && | ||
process.platform === 'win32') { | ||
|
@@ -873,7 +863,7 @@ Socket.prototype.connect = function(options, cb) { | |
debug('pipe', pipe, options.path); | ||
|
||
if (!this._handle) { | ||
this._handle = pipe ? createPipe() : createTCP(); | ||
this._handle = pipe ? new Pipe() : new TCP(); | ||
initSocketHandle(this); | ||
} | ||
|
||
|
@@ -1095,15 +1085,15 @@ var createServerHandle = exports._createServerHandle = | |
handle.writable = true; | ||
assert(!address && !port); | ||
} else if (port === -1 && addressType === -1) { | ||
handle = createPipe(); | ||
handle = new Pipe(); | ||
if (process.platform === 'win32') { | ||
var instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); | ||
if (!isNaN(instances)) { | ||
handle.setPendingInstances(instances); | ||
} | ||
} | ||
} else { | ||
handle = createTCP(); | ||
handle = new TCP(); | ||
isTCP = true; | ||
} | ||
|
||
|
@@ -1255,8 +1245,6 @@ Server.prototype.listen = function() { | |
// When the ip is omitted it can be the second argument. | ||
var backlog = toNumber(arguments[1]) || toNumber(arguments[2]); | ||
|
||
const TCP = process.binding('tcp_wrap').TCP; | ||
|
||
if (arguments.length === 0 || typeof arguments[0] === 'function') { | ||
// Bind to a random port. | ||
listen(self, null, 0, null, backlog); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
const net = require('net'); | ||
const url = require('url'); | ||
const util = require('util'); | ||
const binding = process.binding('crypto'); | ||
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.
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 think the different naming is possibly to differentiate it from the result of 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. |
||
|
||
// Allow {CLIENT_RENEG_LIMIT} client-initiated session renegotiations | ||
// every {CLIENT_RENEG_WINDOW} seconds. An error event is emitted if more | ||
|
@@ -35,7 +36,7 @@ exports.DEFAULT_CIPHERS = [ | |
exports.DEFAULT_ECDH_CURVE = 'prime256v1'; | ||
|
||
exports.getCiphers = function() { | ||
const names = process.binding('crypto').getSSLCiphers(); | ||
const names = binding.getSSLCiphers(); | ||
// Drop all-caps names in favor of their lowercase aliases, | ||
var ctx = {}; | ||
names.forEach(function(name) { | ||
|
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.
Fits on a single line now.