aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/stream_base_commons.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/stream_base_commons.js')
-rw-r--r--lib/internal/stream_base_commons.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js
index 709395fa91..31291e751d 100644
--- a/lib/internal/stream_base_commons.js
+++ b/lib/internal/stream_base_commons.js
@@ -16,6 +16,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
const kMaybeDestroy = Symbol('kMaybeDestroy');
const kUpdateTimer = Symbol('kUpdateTimer');
+const kAfterAsyncWrite = Symbol('kAfterAsyncWrite');
function handleWriteReq(req, data, encoding) {
const { handle } = req;
@@ -52,11 +53,33 @@ function handleWriteReq(req, data, encoding) {
}
}
-function createWriteWrap(handle, oncomplete) {
+function onWriteComplete(status) {
+ const stream = this.handle[owner_symbol];
+
+ if (stream.destroyed) {
+ if (typeof this.callback === 'function')
+ this.callback(null);
+ return;
+ }
+
+ if (status < 0) {
+ const ex = errnoException(status, 'write', this.error);
+ stream.destroy(ex, this.callback);
+ return;
+ }
+
+ stream[kUpdateTimer]();
+ stream[kAfterAsyncWrite](this);
+
+ if (typeof this.callback === 'function')
+ this.callback(null);
+}
+
+function createWriteWrap(handle) {
var req = new WriteWrap();
req.handle = handle;
- req.oncomplete = oncomplete;
+ req.oncomplete = onWriteComplete;
req.async = false;
req.bytes = 0;
req.buffer = null;
@@ -160,6 +183,7 @@ module.exports = {
writevGeneric,
writeGeneric,
onStreamRead,
+ kAfterAsyncWrite,
kMaybeDestroy,
kUpdateTimer,
};