summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-04-01 20:56:11 +0200
committerAnna Henningsen <anna@addaleax.net>2018-04-12 15:39:36 +0200
commit93967d00e9feb944b1ec907dabaaf32f243e5806 (patch)
treeba719457a670a5e3a4fc25f3544341e33198c26d
parentbb6de0d4a844959fddd00e28d190d3d3ccbef8c9 (diff)
downloadandroid-node-v8-93967d00e9feb944b1ec907dabaaf32f243e5806.tar.gz
android-node-v8-93967d00e9feb944b1ec907dabaaf32f243e5806.tar.bz2
android-node-v8-93967d00e9feb944b1ec907dabaaf32f243e5806.zip
net,http2: merge write error handling & property names
Merge error handling for `net.Socket`s and `Http2Stream`s, and align the callback property names as `callback`. Refs: https://github.com/nodejs/node/issues/19060 PR-URL: https://github.com/nodejs/node/pull/19734 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
-rw-r--r--lib/internal/http2/core.js2
-rw-r--r--lib/internal/stream_base_commons.js15
-rw-r--r--lib/net.js24
3 files changed, 19 insertions, 22 deletions
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 0aa9904001..c9f4f36748 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -1657,7 +1657,6 @@ class Http2Stream extends Duplex {
const req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID];
- req.callback = cb;
writeGeneric(this, req, data, encoding, cb);
@@ -1690,7 +1689,6 @@ class Http2Stream extends Duplex {
var req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID];
- req.callback = cb;
writevGeneric(this, req, data, cb);
diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js
index d902a50152..b252b1d8ff 100644
--- a/lib/internal/stream_base_commons.js
+++ b/lib/internal/stream_base_commons.js
@@ -61,15 +61,24 @@ function writevGeneric(self, req, data, cb) {
// Retain chunks
if (err === 0) req._chunks = chunks;
- if (err)
- return self.destroy(errnoException(err, 'write', req.error), cb);
+ afterWriteDispatched(self, req, err, cb);
}
function writeGeneric(self, req, data, encoding, cb) {
var err = handleWriteReq(req, data, encoding);
- if (err)
+ afterWriteDispatched(self, req, err, cb);
+}
+
+function afterWriteDispatched(self, req, err, cb) {
+ if (err !== 0)
return self.destroy(errnoException(err, 'write', req.error), cb);
+
+ if (!req.async) {
+ cb();
+ } else {
+ req.callback = cb;
+ }
}
module.exports = {
diff --git a/lib/net.js b/lib/net.js
index 68dde9cac3..c367712686 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -754,23 +754,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
return false;
}
- var ret;
var req = createWriteWrap(this._handle, afterWrite);
if (writev)
- ret = writevGeneric(this, req, data, cb);
+ writevGeneric(this, req, data, cb);
else
- ret = writeGeneric(this, req, data, encoding, cb);
-
- // Bail out if handle.write* returned an error
- if (ret) return ret;
-
- if (!req.async) {
- cb();
- return;
- }
-
- req.cb = cb;
- this[kLastWriteQueueSize] = req.bytes;
+ writeGeneric(this, req, data, encoding, cb);
+ if (req.async)
+ this[kLastWriteQueueSize] = req.bytes;
};
@@ -845,7 +835,7 @@ function afterWrite(status, handle, err) {
if (status < 0) {
var ex = errnoException(status, 'write', this.error);
debug('write failure', ex);
- self.destroy(ex, this.cb);
+ self.destroy(ex, this.callback);
return;
}
@@ -854,8 +844,8 @@ function afterWrite(status, handle, err) {
if (self !== process.stderr && self !== process.stdout)
debug('afterWrite call cb');
- if (this.cb)
- this.cb.call(undefined);
+ if (this.callback)
+ this.callback.call(undefined);
}