stream: move process.binding('stream_wrap') to internalBinding
PR-URL: https://github.com/nodejs/node/pull/22345 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
7108893ec8
commit
884b23daf7
@ -12,14 +12,15 @@ const bench = common.createBenchmark(main, {
|
|||||||
len: [102400, 1024 * 1024 * 16],
|
len: [102400, 1024 * 1024 * 16],
|
||||||
type: ['utf', 'asc', 'buf'],
|
type: ['utf', 'asc', 'buf'],
|
||||||
dur: [5]
|
dur: [5]
|
||||||
});
|
}, { flags: [ '--expose-internals', '--no-warnings' ] });
|
||||||
|
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
|
||||||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
|
||||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
|
||||||
const PORT = common.PORT;
|
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||||
|
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
const PORT = common.PORT;
|
||||||
|
|
||||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||||
if (err)
|
if (err)
|
||||||
@ -58,71 +59,70 @@ function main({ dur, len, type }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
client(type, len);
|
client(type, len);
|
||||||
}
|
|
||||||
|
|
||||||
|
function fail(err, syscall) {
|
||||||
function fail(err, syscall) {
|
throw util._errnoException(err, syscall);
|
||||||
throw util._errnoException(err, syscall);
|
|
||||||
}
|
|
||||||
|
|
||||||
function client(type, len) {
|
|
||||||
var chunk;
|
|
||||||
switch (type) {
|
|
||||||
case 'buf':
|
|
||||||
chunk = Buffer.alloc(len, 'x');
|
|
||||||
break;
|
|
||||||
case 'utf':
|
|
||||||
chunk = 'ü'.repeat(len / 2);
|
|
||||||
break;
|
|
||||||
case 'asc':
|
|
||||||
chunk = 'x'.repeat(len);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(`invalid type: ${type}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
function client(type, len) {
|
||||||
const connectReq = new TCPConnectWrap();
|
var chunk;
|
||||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
switch (type) {
|
||||||
|
case 'buf':
|
||||||
|
chunk = Buffer.alloc(len, 'x');
|
||||||
|
break;
|
||||||
|
case 'utf':
|
||||||
|
chunk = 'ü'.repeat(len / 2);
|
||||||
|
break;
|
||||||
|
case 'asc':
|
||||||
|
chunk = 'x'.repeat(len);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`invalid type: ${type}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (err)
|
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||||
fail(err, 'connect');
|
const connectReq = new TCPConnectWrap();
|
||||||
|
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||||
|
|
||||||
clientHandle.readStart();
|
|
||||||
|
|
||||||
connectReq.oncomplete = function(err) {
|
|
||||||
if (err)
|
if (err)
|
||||||
fail(err, 'connect');
|
fail(err, 'connect');
|
||||||
|
|
||||||
while (clientHandle.writeQueueSize === 0)
|
clientHandle.readStart();
|
||||||
write();
|
|
||||||
};
|
|
||||||
|
|
||||||
function write() {
|
connectReq.oncomplete = function(err) {
|
||||||
const writeReq = new WriteWrap();
|
if (err)
|
||||||
writeReq.oncomplete = afterWrite;
|
fail(err, 'connect');
|
||||||
var err;
|
|
||||||
switch (type) {
|
while (clientHandle.writeQueueSize === 0)
|
||||||
case 'buf':
|
write();
|
||||||
err = clientHandle.writeBuffer(writeReq, chunk);
|
};
|
||||||
break;
|
|
||||||
case 'utf':
|
function write() {
|
||||||
err = clientHandle.writeUtf8String(writeReq, chunk);
|
const writeReq = new WriteWrap();
|
||||||
break;
|
writeReq.oncomplete = afterWrite;
|
||||||
case 'asc':
|
var err;
|
||||||
err = clientHandle.writeAsciiString(writeReq, chunk);
|
switch (type) {
|
||||||
break;
|
case 'buf':
|
||||||
|
err = clientHandle.writeBuffer(writeReq, chunk);
|
||||||
|
break;
|
||||||
|
case 'utf':
|
||||||
|
err = clientHandle.writeUtf8String(writeReq, chunk);
|
||||||
|
break;
|
||||||
|
case 'asc':
|
||||||
|
err = clientHandle.writeAsciiString(writeReq, chunk);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
fail(err, 'write');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
function afterWrite(err, handle) {
|
||||||
fail(err, 'write');
|
if (err)
|
||||||
}
|
fail(err, 'write');
|
||||||
|
|
||||||
function afterWrite(err, handle) {
|
while (clientHandle.writeQueueSize === 0)
|
||||||
if (err)
|
write();
|
||||||
fail(err, 'write');
|
}
|
||||||
|
|
||||||
while (clientHandle.writeQueueSize === 0)
|
|
||||||
write();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,18 +12,21 @@ const bench = common.createBenchmark(main, {
|
|||||||
len: [102400, 1024 * 1024 * 16],
|
len: [102400, 1024 * 1024 * 16],
|
||||||
type: ['utf', 'asc', 'buf'],
|
type: ['utf', 'asc', 'buf'],
|
||||||
dur: [5]
|
dur: [5]
|
||||||
|
}, {
|
||||||
|
flags: [ '--expose-internals', '--no-warnings' ]
|
||||||
});
|
});
|
||||||
|
|
||||||
function fail(err, syscall) {
|
|
||||||
throw util._errnoException(err, syscall);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
|
||||||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
|
||||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
|
||||||
const PORT = common.PORT;
|
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||||
|
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
const PORT = common.PORT;
|
||||||
|
|
||||||
|
function fail(err, syscall) {
|
||||||
|
throw util._errnoException(err, syscall);
|
||||||
|
}
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||||
|
@ -12,14 +12,17 @@ const bench = common.createBenchmark(main, {
|
|||||||
len: [102400, 1024 * 1024 * 16],
|
len: [102400, 1024 * 1024 * 16],
|
||||||
type: ['utf', 'asc', 'buf'],
|
type: ['utf', 'asc', 'buf'],
|
||||||
dur: [5]
|
dur: [5]
|
||||||
|
}, {
|
||||||
|
flags: [ '--expose-internals', '--no-warnings' ]
|
||||||
});
|
});
|
||||||
|
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
|
||||||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
|
||||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
|
||||||
const PORT = common.PORT;
|
|
||||||
|
|
||||||
function main({ dur, len, type }) {
|
function main({ dur, len, type }) {
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||||
|
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
||||||
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
const PORT = common.PORT;
|
||||||
|
|
||||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||||
if (err)
|
if (err)
|
||||||
@ -89,42 +92,42 @@ function main({ dur, len, type }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
client(dur);
|
client(dur);
|
||||||
}
|
|
||||||
|
|
||||||
function fail(err, syscall) {
|
function fail(err, syscall) {
|
||||||
throw util._errnoException(err, syscall);
|
throw util._errnoException(err, syscall);
|
||||||
}
|
}
|
||||||
|
|
||||||
function client(dur) {
|
function client(dur) {
|
||||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||||
const connectReq = new TCPConnectWrap();
|
const connectReq = new TCPConnectWrap();
|
||||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
fail(err, 'connect');
|
fail(err, 'connect');
|
||||||
|
|
||||||
connectReq.oncomplete = function() {
|
connectReq.oncomplete = function() {
|
||||||
var bytes = 0;
|
var bytes = 0;
|
||||||
clientHandle.onread = function(nread, buffer) {
|
clientHandle.onread = function(nread, buffer) {
|
||||||
// we're not expecting to ever get an EOF from the client.
|
// we're not expecting to ever get an EOF from the client.
|
||||||
// just lots of data forever.
|
// just lots of data forever.
|
||||||
if (nread < 0)
|
if (nread < 0)
|
||||||
fail(nread, 'read');
|
fail(nread, 'read');
|
||||||
|
|
||||||
// don't slice the buffer. the point of this is to isolate, not
|
// don't slice the buffer. the point of this is to isolate, not
|
||||||
// simulate real traffic.
|
// simulate real traffic.
|
||||||
bytes += buffer.length;
|
bytes += buffer.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
clientHandle.readStart();
|
||||||
|
|
||||||
|
// the meat of the benchmark is right here:
|
||||||
|
bench.start();
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
// report in Gb/sec
|
||||||
|
bench.end((bytes * 8) / (1024 * 1024 * 1024));
|
||||||
|
process.exit(0);
|
||||||
|
}, dur * 1000);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
clientHandle.readStart();
|
|
||||||
|
|
||||||
// the meat of the benchmark is right here:
|
|
||||||
bench.start();
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
// report in Gb/sec
|
|
||||||
bench.end((bytes * 8) / (1024 * 1024 * 1024));
|
|
||||||
process.exit(0);
|
|
||||||
}, dur * 1000);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,12 @@
|
|||||||
// that are whitelisted for access via process.binding()... this is used
|
// that are whitelisted for access via process.binding()... this is used
|
||||||
// to provide a transition path for modules that are being moved over to
|
// to provide a transition path for modules that are being moved over to
|
||||||
// internalBinding.
|
// internalBinding.
|
||||||
const internalBindingWhitelist = new SafeSet(['uv', 'http_parser', 'v8']);
|
const internalBindingWhitelist =
|
||||||
|
new SafeSet([
|
||||||
|
'uv',
|
||||||
|
'http_parser',
|
||||||
|
'v8',
|
||||||
|
'stream_wrap']);
|
||||||
process.binding = function binding(name) {
|
process.binding = function binding(name) {
|
||||||
return internalBindingWhitelist.has(name) ?
|
return internalBindingWhitelist.has(name) ?
|
||||||
internalBinding(name) :
|
internalBinding(name) :
|
||||||
|
@ -24,7 +24,7 @@ const assert = require('assert');
|
|||||||
const { internalBinding } = require('internal/bootstrap/loaders');
|
const { internalBinding } = require('internal/bootstrap/loaders');
|
||||||
|
|
||||||
const { Process } = process.binding('process_wrap');
|
const { Process } = process.binding('process_wrap');
|
||||||
const { WriteWrap } = process.binding('stream_wrap');
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
|
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
|
||||||
const { TTY } = process.binding('tty_wrap');
|
const { TTY } = process.binding('tty_wrap');
|
||||||
const { TCP } = process.binding('tcp_wrap');
|
const { TCP } = process.binding('tcp_wrap');
|
||||||
|
@ -115,7 +115,7 @@ const { isArrayBufferView } = require('internal/util/types');
|
|||||||
|
|
||||||
const { FileHandle } = process.binding('fs');
|
const { FileHandle } = process.binding('fs');
|
||||||
const binding = internalBinding('http2');
|
const binding = internalBinding('http2');
|
||||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||||
const { UV_EOF } = internalBinding('uv');
|
const { UV_EOF } = internalBinding('uv');
|
||||||
|
|
||||||
const { StreamPipe } = internalBinding('stream_pipe');
|
const { StreamPipe } = internalBinding('stream_pipe');
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
const { WriteWrap } = process.binding('stream_wrap');
|
const { internalBinding } = require('internal/bootstrap/loaders');
|
||||||
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
const errnoException = errors.errnoException;
|
const errnoException = errors.errnoException;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ const {
|
|||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const TTYWrap = process.binding('tty_wrap');
|
const TTYWrap = process.binding('tty_wrap');
|
||||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||||
const {
|
const {
|
||||||
TCP,
|
TCP,
|
||||||
TCPConnectWrap,
|
TCPConnectWrap,
|
||||||
|
@ -374,5 +374,5 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) {
|
|||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(stream_wrap,
|
NODE_MODULE_CONTEXT_AWARE_INTERNAL(stream_wrap,
|
||||||
node::LibuvStreamWrap::Initialize)
|
node::LibuvStreamWrap::Initialize)
|
||||||
|
@ -9,3 +9,4 @@ const assert = require('assert');
|
|||||||
assert(process.binding('uv'));
|
assert(process.binding('uv'));
|
||||||
assert(process.binding('http_parser'));
|
assert(process.binding('http_parser'));
|
||||||
assert(process.binding('v8'));
|
assert(process.binding('v8'));
|
||||||
|
assert(process.binding('stream_wrap'));
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const StreamWrap = require('_stream_wrap');
|
const StreamWrap = require('_stream_wrap');
|
||||||
const Duplex = require('stream').Duplex;
|
const { Duplex } = require('stream');
|
||||||
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
function testShutdown(callback) {
|
function testShutdown(callback) {
|
||||||
const stream = new Duplex({
|
const stream = new Duplex({
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
||||||
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
function makeConnection() {
|
function makeConnection() {
|
||||||
const client = new TCP(TCPConstants.SOCKET);
|
const client = new TCP(TCPConstants.SOCKET);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
const server = new TCP(TCPConstants.SOCKET);
|
const server = new TCP(TCPConstants.SOCKET);
|
||||||
|
|
||||||
|
@ -19,15 +19,17 @@
|
|||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
if (!common.hasCrypto)
|
if (!common.hasCrypto)
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
|
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const tls = require('tls');
|
const tls = require('tls');
|
||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
const server = tls.createServer({
|
const server = tls.createServer({
|
||||||
key: fixtures.readKey('agent1-key.pem'),
|
key: fixtures.readKey('agent1-key.pem'),
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
// Flags: --expose-internals --no-warnings
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
require('../common');
|
||||||
|
|
||||||
const TTY = process.binding('tty_wrap').TTY;
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
const { TTY } = process.binding('tty_wrap');
|
||||||
|
const { WriteWrap } = internalBinding('stream_wrap');
|
||||||
|
|
||||||
const handle = new TTY(1);
|
const handle = new TTY(1);
|
||||||
const req = new WriteWrap();
|
const req = new WriteWrap();
|
||||||
|
@ -201,12 +201,12 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const binding = process.binding('stream_wrap');
|
const binding = internalBinding('stream_wrap');
|
||||||
testUninitialized(new binding.WriteWrap(), 'WriteWrap');
|
testUninitialized(new binding.WriteWrap(), 'WriteWrap');
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const stream_wrap = process.binding('stream_wrap');
|
const stream_wrap = internalBinding('stream_wrap');
|
||||||
const tcp_wrap = process.binding('tcp_wrap');
|
const tcp_wrap = process.binding('tcp_wrap');
|
||||||
const server = net.createServer(common.mustCall((socket) => {
|
const server = net.createServer(common.mustCall((socket) => {
|
||||||
server.close();
|
server.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user