0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
Commit Graph

20 Commits

Author SHA1 Message Date
isaacs
c38ce9bc0a stream: Guarantee ordering of 'finish' event
In synchronous Writable streams (where the _write cb is called on the
current tick), the 'finish' event (and thus the end() callback) can in
some cases be called before all the write() callbacks are called.

Use a counter, and have stream.Transform rely on the 'prefinish' event
instead of the 'finish' event.

This has zero effect on most streams, but it corrects an edge case and
makes it perform more deterministically, which is a Good Thing.
2013-05-09 09:35:32 -07:00
Rafael Garcia
bd0d45818e stream: unused variable 2013-04-05 12:05:58 -07:00
Rafael Garcia
ea4f0b4a6b stream: remove vestiges of previous _transform API 2013-04-05 12:05:58 -07:00
Gil Pedersen
c3aae9cf95 stream: Fix stall in Transform under very specific conditions
The stall is exposed in the test, though the test itself asserts before
it stalls.

The test is constructed to replicate the stalling state of a complex
Passthrough usecase since I was not able to reliable trigger the stall.

Some of the preconditions for triggering the stall are:
  * rs.length >= rs.highWaterMark
  * !rs.needReadable
  * _transform() handler that can return empty transforms
  * multiple sync write() calls

Combined this can trigger a case where rs.reading is not cleared when
further progress requires this. The fix is to always clear rs.reading.
2013-03-21 17:49:12 -07:00
isaacs
90368770e6 stream: Emit error on stream object, not global
Apparently this function got abstracted out at some point, and 'this'
wasn't changed to the correct object.
2013-03-08 07:35:41 -08:00
isaacs
b0f6789a78 stream: Remove bufferSize option
Now that highWaterMark increases when there are large reads, this
greatly reduces the number of calls necessary to _read(size), assuming
that _read actually respects the size argument.
2013-03-06 11:44:30 -08:00
isaacs
426b4c6258 stream: _write takes an encoding argument
This vastly reduces the overhead of decodeStrings:false streams,
such as net and http.
2013-03-05 14:27:15 -08:00
isaacs
cd68d86c32 stream: Remove output function from _transform
Just use stream.push(outputChunk) instead.
2013-03-05 14:27:15 -08:00
isaacs
88644eaa2d stream: There is no _read cb, there is only push
This makes it so that `stream.push(chunk)` is the only way to signal the
end of reading, removing the confusing disparity between the
callback-style _read method, and the fact that most real-world streams
do not have a 1:1 corollation between the "please give me data" event,
and the actual arrival of a chunk of data.

It is still possible, of course, to implement a `CallbackReadable` on
top of this.  Simply provide a method like this as the callback:

    function readCallback(er, chunk) {
      if (er)
        stream.emit('error', er);
      else
        stream.push(chunk);
    }

However, *only* fs streams actually would behave in this way, so it
makes not a lot of sense to make TCP, TLS, HTTP, and all the rest have
to bend into this uncomfortable paradigm.
2013-02-28 17:38:17 -08:00
isaacs
e03bc472f0 stream: Start out in sync=true state
The Readable and Writable classes will nextTick certain things
if in sync mode.  The sync flag gets unset after a call to _read
or _write.  However, most of these behaviors should also be
deferred until nextTick if no reads have been made (for example,
the automatic '_read up to hwm' behavior on Readable.push(chunk))

Set the sync flag to true in the constructor, so that it will not
trigger an immediate 'readable' event, call to _read, before the
user has had a chance to set a _read method implementation.
2013-02-25 07:38:10 -08:00
isaacs
3b2e9d2648 stream: remove lowWaterMark feature
It seems like a good idea on the face of it, but lowWaterMarks are
actually not useful, and in practice should always be set to zero.

It would be worthwhile for writers if we actually did some kind of
writev() type of thing, but actually this just delays calling write()
and the overhead of doing a bunch of Buffer copies is not worth the
slight benefit of calling write() fewer times.
2013-02-21 15:23:18 -08:00
isaacs
e26622bd18 stream: Correct Transform class backpressure
The refactor in b43e544140 to use
stream.push() in Transform inadvertently caused it to immediately
consume all the written data, regardless of whether or not the readable
side was being consumed.

Only pull data through the _transform() process when the readable side
is being consumed.

Fix #4667
2013-01-28 08:40:45 -08:00
isaacs
b43e544140 stream: Use push() for Transform._output()
This also slightly changes the semantics, in that a 'readable'
event may be triggered by the first write() call, even if a
user has not yet called read().

This happens because the Transform _write() handler is calling
read(0) to start the flow of data.  Technically, the new behavior
is more 'correct', since it is more in line with the semantics
of the 'readable' event in other streams.
2013-01-10 13:49:54 -08:00
isaacs
b15e19a232 streams2: Remove function.bind() usage
It's too slow, unfortunately.
2012-12-13 17:00:32 -08:00
isaacs
f20fd22abd streams2: Add high water mark for Readable
Also, organize the numeric settings a bit on the ReadableState class
2012-12-13 17:00:30 -08:00
isaacs
545f512619 streams2: ctor guards on Stream classes 2012-12-13 17:00:26 -08:00
isaacs
8acb416ad0 streams2: Handle immediate synthetic transforms properly 2012-12-13 17:00:26 -08:00
isaacs
caa853bb06 transform: Automatically read() on _write when read buffer is empty 2012-12-13 17:00:25 -08:00
isaacs
3b59fd70f4 streams2: Make Transform streams pull-style
That is, the transform is triggered by a _read, not by a _write.

This way, backpressure works properly.
2012-12-13 17:00:24 -08:00
isaacs
420e07c577 streams2: The new stream base classes 2012-12-13 17:00:23 -08:00