Skip to content

Commit 18069e4

Browse files
committed
fixup! src: improve StreamBase read throughput
1 parent 6023661 commit 18069e4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

benchmark/net/tcp-raw-c2s.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ function main({ dur, len, type }) {
4646
process.exit(0);
4747
}, dur * 1000);
4848

49-
clientHandle.onread = function(nread, buffer) {
49+
clientHandle.onread = function(buffer) {
5050
// we're not expecting to ever get an EOF from the client.
5151
// just lots of data forever.
52-
if (nread < 0)
53-
fail(nread, 'read');
52+
if (!buffer)
53+
fail('read');
5454

5555
// don't slice the buffer. the point of this is to isolate, not
5656
// simulate real traffic.
57-
bytes += buffer.length;
57+
bytes += buffer.byteLength;
5858
};
5959

6060
clientHandle.readStart();

benchmark/net/tcp-raw-pipe.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ function main({ dur, len, type }) {
4343
if (err)
4444
fail(err, 'connect');
4545

46-
clientHandle.onread = function(nread, buffer) {
46+
clientHandle.onread = function(buffer) {
4747
// we're not expecting to ever get an EOF from the client.
4848
// just lots of data forever.
49-
if (nread < 0)
50-
fail(nread, 'read');
49+
if (!buffer)
50+
fail('read');
5151

5252
const writeReq = new WriteWrap();
5353
writeReq.async = false;
54-
err = clientHandle.writeBuffer(writeReq, buffer);
54+
err = clientHandle.writeBuffer(writeReq, Buffer.from(buffer));
5555

5656
if (err)
5757
fail(err, 'write');
@@ -89,11 +89,11 @@ function main({ dur, len, type }) {
8989
if (err)
9090
fail(err, 'connect');
9191

92-
clientHandle.onread = function(nread, buffer) {
93-
if (nread < 0)
94-
fail(nread, 'read');
92+
clientHandle.onread = function(buffer) {
93+
if (!buffer)
94+
fail('read');
9595

96-
bytes += buffer.length;
96+
bytes += buffer.byteLength;
9797
};
9898

9999
connectReq.oncomplete = function(err) {

0 commit comments

Comments
 (0)