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>
This commit is contained in:
Anna Henningsen 2018-04-01 20:56:11 +02:00 коммит произвёл James M Snell
Родитель 2a3a66afb3
Коммит e85c20b511
3 изменённых файлов: 19 добавлений и 22 удалений

Просмотреть файл

@ -1657,7 +1657,6 @@ class Http2Stream extends Duplex {
const req = createWriteWrap(this[kHandle], afterDoStreamWrite); const req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID]; req.stream = this[kID];
req.callback = cb;
writeGeneric(this, req, data, encoding, cb); writeGeneric(this, req, data, encoding, cb);
@ -1690,7 +1689,6 @@ class Http2Stream extends Duplex {
var req = createWriteWrap(this[kHandle], afterDoStreamWrite); var req = createWriteWrap(this[kHandle], afterDoStreamWrite);
req.stream = this[kID]; req.stream = this[kID];
req.callback = cb;
writevGeneric(this, req, data, cb); writevGeneric(this, req, data, cb);

Просмотреть файл

@ -61,15 +61,24 @@ function writevGeneric(self, req, data, cb) {
// Retain chunks // Retain chunks
if (err === 0) req._chunks = chunks; if (err === 0) req._chunks = chunks;
if (err) afterWriteDispatched(self, req, err, cb);
return self.destroy(errnoException(err, 'write', req.error), cb);
} }
function writeGeneric(self, req, data, encoding, cb) { function writeGeneric(self, req, data, encoding, cb) {
var err = handleWriteReq(req, data, encoding); 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); return self.destroy(errnoException(err, 'write', req.error), cb);
if (!req.async) {
cb();
} else {
req.callback = cb;
}
} }
module.exports = { module.exports = {

Просмотреть файл

@ -754,23 +754,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
return false; return false;
} }
var ret;
var req = createWriteWrap(this._handle, afterWrite); var req = createWriteWrap(this._handle, afterWrite);
if (writev) if (writev)
ret = writevGeneric(this, req, data, cb); writevGeneric(this, req, data, cb);
else else
ret = writeGeneric(this, req, data, encoding, cb); writeGeneric(this, req, data, encoding, cb);
if (req.async)
// Bail out if handle.write* returned an error this[kLastWriteQueueSize] = req.bytes;
if (ret) return ret;
if (!req.async) {
cb();
return;
}
req.cb = cb;
this[kLastWriteQueueSize] = req.bytes;
}; };
@ -845,7 +835,7 @@ function afterWrite(status, handle, err) {
if (status < 0) { if (status < 0) {
var ex = errnoException(status, 'write', this.error); var ex = errnoException(status, 'write', this.error);
debug('write failure', ex); debug('write failure', ex);
self.destroy(ex, this.cb); self.destroy(ex, this.callback);
return; return;
} }
@ -854,8 +844,8 @@ function afterWrite(status, handle, err) {
if (self !== process.stderr && self !== process.stdout) if (self !== process.stderr && self !== process.stdout)
debug('afterWrite call cb'); debug('afterWrite call cb');
if (this.cb) if (this.callback)
this.cb.call(undefined); this.callback.call(undefined);
} }