From 0e7b61229aa602e55c5fb034a63d7da97eecff3b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 8 Feb 2018 04:59:10 +0100 Subject: src: refactor WriteWrap and ShutdownWraps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Encapsulate stream requests more: - `WriteWrap` and `ShutdownWrap` classes are now tailored to the streams on which they are used. In particular, for most streams these are now plain `AsyncWrap`s and do not carry the overhead of unused libuv request data. - Provide generic `Write()` and `Shutdown()` methods that wrap around the actual implementations, and make *usage* of streams easier, rather than implementing; for example, wrap objects don’t need to be provided by callers anymore. - Use `EmitAfterWrite()` and `EmitAfterShutdown()` handlers to call the corresponding JS handlers, rather than always trying to call them. This makes usage of streams by other C++ code easier and leaner. Also fix up some tests that were previously not actually testing asynchronicity when the comments indicated that they would. PR-URL: https://github.com/nodejs/node/pull/18676 Reviewed-By: Ben Noordhuis Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- benchmark/net/tcp-raw-c2s.js | 2 +- benchmark/net/tcp-raw-pipe.js | 4 ++-- benchmark/net/tcp-raw-s2c.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'benchmark/net') diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index 2be3bb3b53..4b6dd9c3f2 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -118,7 +118,7 @@ function client(type, len) { fail(err, 'write'); } - function afterWrite(err, handle, req) { + function afterWrite(err, handle) { if (err) fail(err, 'write'); diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index 2fc03f08cd..dfde3d40b5 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -51,7 +51,7 @@ function main({ dur, len, type }) { if (err) fail(err, 'write'); - writeReq.oncomplete = function(status, handle, req, err) { + writeReq.oncomplete = function(status, handle, err) { if (err) fail(err, 'write'); }; @@ -130,7 +130,7 @@ function main({ dur, len, type }) { fail(err, 'write'); } - function afterWrite(err, handle, req) { + function afterWrite(err, handle) { if (err) fail(err, 'write'); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 339f5e393d..fe0bffd812 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -74,14 +74,14 @@ function main({ dur, len, type }) { fail(err, 'write'); } else if (!writeReq.async) { process.nextTick(function() { - afterWrite(null, clientHandle, writeReq); + afterWrite(0, clientHandle); }); } } - function afterWrite(status, handle, req, err) { - if (err) - fail(err, 'write'); + function afterWrite(status, handle) { + if (status) + fail(status, 'write'); while (clientHandle.writeQueueSize === 0) write(); -- cgit v1.2.3