summaryrefslogtreecommitdiff
path: root/test/parallel/test-tcp-wrap-listen.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-10-21 08:34:00 +0200
committerAnna Henningsen <anna@addaleax.net>2018-10-24 09:57:42 +0200
commit1365f657b51d31044cca54c3152d3940a4bd9dc3 (patch)
tree4772c2b484555de0a0368b35ebf889ff23d154c2 /test/parallel/test-tcp-wrap-listen.js
parentbb79e768e5ab150f2075780734005783d53eb3ca (diff)
downloadandroid-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.tar.gz
android-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.tar.bz2
android-node-v8-1365f657b51d31044cca54c3152d3940a4bd9dc3.zip
src: improve StreamBase read throughput
Improve performance by providing JS with the raw ingridients for the read data, i.e. an `ArrayBuffer` + offset + length fields, instead of creating `Buffer` instances in C++ land. PR-URL: https://github.com/nodejs/node/pull/23797 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-tcp-wrap-listen.js')
-rw-r--r--test/parallel/test-tcp-wrap-listen.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/test/parallel/test-tcp-wrap-listen.js b/test/parallel/test-tcp-wrap-listen.js
index 9ecdf60f8c..72981b683c 100644
--- a/test/parallel/test-tcp-wrap-listen.js
+++ b/test/parallel/test-tcp-wrap-listen.js
@@ -5,7 +5,12 @@ const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
-const { WriteWrap } = internalBinding('stream_wrap');
+const {
+ WriteWrap,
+ kReadBytesOrError,
+ kArrayBufferOffset,
+ streamBaseState
+} = internalBinding('stream_wrap');
const server = new TCP(TCPConstants.SOCKET);
@@ -30,8 +35,11 @@ server.onconnection = (err, client) => {
client.readStart();
client.pendingWrites = [];
- client.onread = common.mustCall((err, buffer) => {
- if (buffer) {
+ client.onread = common.mustCall((arrayBuffer) => {
+ if (arrayBuffer) {
+ const offset = streamBaseState[kArrayBufferOffset];
+ const nread = streamBaseState[kReadBytesOrError];
+ const buffer = Buffer.from(arrayBuffer, offset, nread);
assert.ok(buffer.length > 0);
assert.strictEqual(client.writeQueueSize, 0);