aboutsummaryrefslogtreecommitdiff
path: root/lib/_stream_writable.js
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2016-04-12 12:30:03 +0200
committerMatteo Collina <hello@matteocollina.com>2016-04-14 08:30:32 +0200
commit0b1d89f35a43c27e4aa666c41defb39e586d39f2 (patch)
tree259e1b644afa10f81d8b0d0815f8b5cad6779a81 /lib/_stream_writable.js
parenta11d506decd2820221d6cd770990a585ca0261d5 (diff)
downloadandroid-node-v8-0b1d89f35a43c27e4aa666c41defb39e586d39f2.tar.gz
android-node-v8-0b1d89f35a43c27e4aa666c41defb39e586d39f2.tar.bz2
android-node-v8-0b1d89f35a43c27e4aa666c41defb39e586d39f2.zip
streams: support unlimited synchronous cork/uncork cycles
net streams can request multiple chunks to be written in a synchronous fashion. If this is combined with cork/uncork, en error is currently thrown because of a regression introduced in: https://github.com/nodejs/node/commit/89aeab901ac9e34c79be3854f1aa41f2a4fb6888 (https://github.com/nodejs/node/pull/4354). Fixes: https://github.com/nodejs/node/issues/6154 PR-URL: https://github.com/nodejs/node/pull/6164 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Mathias Buus <mathiasbuus@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/_stream_writable.js')
-rw-r--r--lib/_stream_writable.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index b6e621fd1e..98ca05da39 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -112,10 +112,9 @@ function WritableState(options, stream) {
// count buffered requests
this.bufferedRequestCount = 0;
- // create the two objects needed to store the corked requests
- // they are not a linked list, as no new elements are inserted in there
+ // allocate the first CorkedRequest, there is always
+ // one allocated and free to use, and we maintain at most two
this.corkedRequestsFree = new CorkedRequest(this);
- this.corkedRequestsFree.next = new CorkedRequest(this);
}
WritableState.prototype.getBuffer = function writableStateGetBuffer() {
@@ -387,12 +386,16 @@ function clearBuffer(stream, state) {
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
- // doWrite is always async, defer these to save a bit of time
+ // doWrite is almost always async, defer these to save a bit of time
// as the hot path ends with doWrite
state.pendingcb++;
state.lastBufferedRequest = null;
- state.corkedRequestsFree = holder.next;
- holder.next = null;
+ if (holder.next) {
+ state.corkedRequestsFree = holder.next;
+ holder.next = null;
+ } else {
+ state.corkedRequestsFree = new CorkedRequest(state);
+ }
} else {
// Slow case, write chunks one-by-one
while (entry) {