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],
|
||||
type: ['utf', 'asc', 'buf'],
|
||||
dur: [5]
|
||||
});
|
||||
|
||||
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;
|
||||
}, { flags: [ '--expose-internals', '--no-warnings' ] });
|
||||
|
||||
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);
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (err)
|
||||
@ -58,71 +59,70 @@ function main({ dur, len, type }) {
|
||||
};
|
||||
|
||||
client(type, len);
|
||||
}
|
||||
|
||||
|
||||
function fail(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}`);
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
|
||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||
const connectReq = new TCPConnectWrap();
|
||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
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}`);
|
||||
}
|
||||
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||
const connectReq = new TCPConnectWrap();
|
||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
|
||||
clientHandle.readStart();
|
||||
|
||||
connectReq.oncomplete = function(err) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
};
|
||||
clientHandle.readStart();
|
||||
|
||||
function write() {
|
||||
const writeReq = new WriteWrap();
|
||||
writeReq.oncomplete = afterWrite;
|
||||
var err;
|
||||
switch (type) {
|
||||
case 'buf':
|
||||
err = clientHandle.writeBuffer(writeReq, chunk);
|
||||
break;
|
||||
case 'utf':
|
||||
err = clientHandle.writeUtf8String(writeReq, chunk);
|
||||
break;
|
||||
case 'asc':
|
||||
err = clientHandle.writeAsciiString(writeReq, chunk);
|
||||
break;
|
||||
connectReq.oncomplete = function(err) {
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
};
|
||||
|
||||
function write() {
|
||||
const writeReq = new WriteWrap();
|
||||
writeReq.oncomplete = afterWrite;
|
||||
var err;
|
||||
switch (type) {
|
||||
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)
|
||||
fail(err, 'write');
|
||||
}
|
||||
function afterWrite(err, handle) {
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
function afterWrite(err, handle) {
|
||||
if (err)
|
||||
fail(err, 'write');
|
||||
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
while (clientHandle.writeQueueSize === 0)
|
||||
write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,18 +12,21 @@ const bench = common.createBenchmark(main, {
|
||||
len: [102400, 1024 * 1024 * 16],
|
||||
type: ['utf', 'asc', 'buf'],
|
||||
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 }) {
|
||||
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
|
||||
const serverHandle = new TCP(TCPConstants.SERVER);
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
|
@ -12,14 +12,17 @@ const bench = common.createBenchmark(main, {
|
||||
len: [102400, 1024 * 1024 * 16],
|
||||
type: ['utf', 'asc', 'buf'],
|
||||
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 }) {
|
||||
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);
|
||||
var err = serverHandle.bind('127.0.0.1', PORT);
|
||||
if (err)
|
||||
@ -89,42 +92,42 @@ function main({ dur, len, type }) {
|
||||
};
|
||||
|
||||
client(dur);
|
||||
}
|
||||
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
function fail(err, syscall) {
|
||||
throw util._errnoException(err, syscall);
|
||||
}
|
||||
|
||||
function client(dur) {
|
||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||
const connectReq = new TCPConnectWrap();
|
||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
function client(dur) {
|
||||
const clientHandle = new TCP(TCPConstants.SOCKET);
|
||||
const connectReq = new TCPConnectWrap();
|
||||
const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
|
||||
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
if (err)
|
||||
fail(err, 'connect');
|
||||
|
||||
connectReq.oncomplete = function() {
|
||||
var bytes = 0;
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
// we're not expecting to ever get an EOF from the client.
|
||||
// just lots of data forever.
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
connectReq.oncomplete = function() {
|
||||
var bytes = 0;
|
||||
clientHandle.onread = function(nread, buffer) {
|
||||
// we're not expecting to ever get an EOF from the client.
|
||||
// just lots of data forever.
|
||||
if (nread < 0)
|
||||
fail(nread, 'read');
|
||||
|
||||
// don't slice the buffer. the point of this is to isolate, not
|
||||
// simulate real traffic.
|
||||
bytes += buffer.length;
|
||||
// don't slice the buffer. the point of this is to isolate, not
|
||||
// simulate real traffic.
|
||||
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
|
||||
// to provide a transition path for modules that are being moved over to
|
||||
// internalBinding.
|
||||
const internalBindingWhitelist = new SafeSet(['uv', 'http_parser', 'v8']);
|
||||
const internalBindingWhitelist =
|
||||
new SafeSet([
|
||||
'uv',
|
||||
'http_parser',
|
||||
'v8',
|
||||
'stream_wrap']);
|
||||
process.binding = function binding(name) {
|
||||
return internalBindingWhitelist.has(name) ?
|
||||
internalBinding(name) :
|
||||
|
@ -24,7 +24,7 @@ const assert = require('assert');
|
||||
const { internalBinding } = require('internal/bootstrap/loaders');
|
||||
|
||||
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 { TTY } = process.binding('tty_wrap');
|
||||
const { TCP } = process.binding('tcp_wrap');
|
||||
|
@ -115,7 +115,7 @@ const { isArrayBufferView } = require('internal/util/types');
|
||||
|
||||
const { FileHandle } = process.binding('fs');
|
||||
const binding = internalBinding('http2');
|
||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
||||
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
const { UV_EOF } = internalBinding('uv');
|
||||
|
||||
const { StreamPipe } = internalBinding('stream_pipe');
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
const { Buffer } = require('buffer');
|
||||
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;
|
||||
|
||||
|
@ -43,7 +43,7 @@ const {
|
||||
|
||||
const { Buffer } = require('buffer');
|
||||
const TTYWrap = process.binding('tty_wrap');
|
||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
||||
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
const {
|
||||
TCP,
|
||||
TCPConnectWrap,
|
||||
|
@ -374,5 +374,5 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) {
|
||||
|
||||
} // namespace node
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(stream_wrap,
|
||||
node::LibuvStreamWrap::Initialize)
|
||||
NODE_MODULE_CONTEXT_AWARE_INTERNAL(stream_wrap,
|
||||
node::LibuvStreamWrap::Initialize)
|
||||
|
@ -9,3 +9,4 @@ const assert = require('assert');
|
||||
assert(process.binding('uv'));
|
||||
assert(process.binding('http_parser'));
|
||||
assert(process.binding('v8'));
|
||||
assert(process.binding('stream_wrap'));
|
||||
|
@ -1,10 +1,12 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const StreamWrap = require('_stream_wrap');
|
||||
const Duplex = require('stream').Duplex;
|
||||
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
|
||||
const { Duplex } = require('stream');
|
||||
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
|
||||
function testShutdown(callback) {
|
||||
const stream = new Duplex({
|
||||
|
@ -1,9 +1,11 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
|
||||
const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
||||
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
|
||||
const { TCPConnectWrap } = process.binding('tcp_wrap');
|
||||
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
|
||||
function makeConnection() {
|
||||
const client = new TCP(TCPConstants.SOCKET);
|
||||
|
@ -1,9 +1,11 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
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);
|
||||
|
||||
|
@ -19,15 +19,17 @@
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const tls = require('tls');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const { ShutdownWrap } = process.binding('stream_wrap');
|
||||
const { ShutdownWrap } = internalBinding('stream_wrap');
|
||||
|
||||
const server = tls.createServer({
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
|
@ -1,8 +1,10 @@
|
||||
// Flags: --expose-internals --no-warnings
|
||||
'use strict';
|
||||
require('../common');
|
||||
|
||||
const TTY = process.binding('tty_wrap').TTY;
|
||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const { TTY } = process.binding('tty_wrap');
|
||||
const { WriteWrap } = internalBinding('stream_wrap');
|
||||
|
||||
const handle = new TTY(1);
|
||||
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');
|
||||
}
|
||||
|
||||
{
|
||||
const stream_wrap = process.binding('stream_wrap');
|
||||
const stream_wrap = internalBinding('stream_wrap');
|
||||
const tcp_wrap = process.binding('tcp_wrap');
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
server.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user