summaryrefslogtreecommitdiff
path: root/benchmark/net/tcp-raw-c2s.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-08-15 17:14:22 -0700
committerJames M Snell <jasnell@gmail.com>2018-08-19 12:46:10 -0700
commit884b23daf723db60ebe939e6dde492fa5f9230eb (patch)
treefeb159647324b4fd00024d72ea464cd4cbe161ab /benchmark/net/tcp-raw-c2s.js
parent7108893ec8fb3b3ee8538c82640fa61ac7014e38 (diff)
downloadandroid-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.tar.gz
android-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.tar.bz2
android-node-v8-884b23daf723db60ebe939e6dde492fa5f9230eb.zip
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>
Diffstat (limited to 'benchmark/net/tcp-raw-c2s.js')
-rw-r--r--benchmark/net/tcp-raw-c2s.js114
1 files changed, 57 insertions, 57 deletions
diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js
index 4b6dd9c3f2..d6666011d5 100644
--- a/benchmark/net/tcp-raw-c2s.js
+++ b/benchmark/net/tcp-raw-c2s.js
@@ -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);
-
- if (err)
- fail(err, 'connect');
-
- clientHandle.readStart();
-
- 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;
+ function client(type, len) {
+ var chunk;
switch (type) {
case 'buf':
- err = clientHandle.writeBuffer(writeReq, chunk);
+ chunk = Buffer.alloc(len, 'x');
break;
case 'utf':
- err = clientHandle.writeUtf8String(writeReq, chunk);
+ chunk = 'ü'.repeat(len / 2);
break;
case 'asc':
- err = clientHandle.writeAsciiString(writeReq, chunk);
+ chunk = 'x'.repeat(len);
break;
+ default:
+ throw new Error(`invalid type: ${type}`);
}
- if (err)
- fail(err, 'write');
- }
+ const clientHandle = new TCP(TCPConstants.SOCKET);
+ const connectReq = new TCPConnectWrap();
+ const err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
- function afterWrite(err, handle) {
if (err)
- fail(err, 'write');
+ fail(err, 'connect');
+
+ clientHandle.readStart();
+
+ connectReq.oncomplete = function(err) {
+ if (err)
+ fail(err, 'connect');
- while (clientHandle.writeQueueSize === 0)
- write();
+ 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');
+ }
+
+ function afterWrite(err, handle) {
+ if (err)
+ fail(err, 'write');
+
+ while (clientHandle.writeQueueSize === 0)
+ write();
+ }
}
}