GeezerVison is showing github.com — net,http2: merge write error handling & property names · nodejs/node@e85c20b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1657,7 +1657,6 @@ class Http2Stream extends Duplex { | 1657 | 1657 |
| 1658 | 1658 | const req = createWriteWrap(this[kHandle], afterDoStreamWrite); | 1659 | 1659 | req.stream = this[kID]; | 1660 | | - req.callback = cb; | 1661 | 1660 |
| 1662 | 1661 | writeGeneric(this, req, data, encoding, cb); | 1663 | 1662 |
| @@ -1690,7 +1689,6 @@ class Http2Stream extends Duplex { | 1690 | 1689 |
| 1691 | 1690 | var req = createWriteWrap(this[kHandle], afterDoStreamWrite); | 1692 | 1691 | req.stream = this[kID]; | 1693 | | - req.callback = cb; | 1694 | 1692 |
| 1695 | 1693 | writevGeneric(this, req, data, cb); | 1696 | 1694 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/stream_base_commons.js +12-3Lines changed: 12 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,15 +61,24 @@ function writevGeneric(self, req, data, cb) { | 61 | 61 | // Retain chunks | 62 | 62 | if (err === 0) req._chunks = chunks; | 63 | 63 |
| 64 | | - if (err) | 65 | | - return self.destroy(errnoException(err, 'write', req.error), cb); | | 64 | + afterWriteDispatched(self, req, err, cb); | 66 | 65 | } | 67 | 66 |
| 68 | 67 | function writeGeneric(self, req, data, encoding, cb) { | 69 | 68 | var err = handleWriteReq(req, data, encoding); | 70 | 69 |
| 71 | | - if (err) | | 70 | + afterWriteDispatched(self, req, err, cb); | | 71 | +} | | 72 | + | | 73 | +function afterWriteDispatched(self, req, err, cb) { | | 74 | + if (err !== 0) | 72 | 75 | return self.destroy(errnoException(err, 'write', req.error), cb); | | 76 | + | | 77 | + if (!req.async) { | | 78 | + cb(); | | 79 | + } else { | | 80 | + req.callback = cb; | | 81 | + } | 73 | 82 | } | 74 | 83 |
| 75 | 84 | module.exports = { | |
Collapse file Copy file name to clipboardExpand all lines: lib/net.js +7-17Lines changed: 7 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -754,23 +754,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) { | 754 | 754 | return false; | 755 | 755 | } | 756 | 756 |
| 757 | | - var ret; | 758 | 757 | var req = createWriteWrap(this._handle, afterWrite); | 759 | 758 | if (writev) | 760 | | - ret = writevGeneric(this, req, data, cb); | | 759 | + writevGeneric(this, req, data, cb); | 761 | 760 | else | 762 | | - ret = writeGeneric(this, req, data, encoding, cb); | 763 | | - | 764 | | - // Bail out if handle.write* returned an error | 765 | | - if (ret) return ret; | 766 | | - | 767 | | - if (!req.async) { | 768 | | - cb(); | 769 | | - return; | 770 | | - } | 771 | | - | 772 | | - req.cb = cb; | 773 | | - this[kLastWriteQueueSize] = req.bytes; | | 761 | + writeGeneric(this, req, data, encoding, cb); | | 762 | + if (req.async) | | 763 | + this[kLastWriteQueueSize] = req.bytes; | 774 | 764 | }; | 775 | 765 |
| 776 | 766 |
| @@ -845,7 +835,7 @@ function afterWrite(status, handle, err) { | 845 | 835 | if (status < 0) { | 846 | 836 | var ex = errnoException(status, 'write', this.error); | 847 | 837 | debug('write failure', ex); | 848 | | - self.destroy(ex, this.cb); | | 838 | + self.destroy(ex, this.callback); | 849 | 839 | return; | 850 | 840 | } | 851 | 841 |
| @@ -854,8 +844,8 @@ function afterWrite(status, handle, err) { | 854 | 844 | if (self !== process.stderr && self !== process.stdout) | 855 | 845 | debug('afterWrite call cb'); | 856 | 846 |
| 857 | | - if (this.cb) | 858 | | - this.cb.call(undefined); | | 847 | + if (this.callback) | | 848 | + this.callback.call(undefined); | 859 | 849 | } | 860 | 850 |
| 861 | 851 |
| |
|