0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

34 Commits

Author SHA1 Message Date
isaacs
c0d500102a stream: Fix early end in Writables on zero-length writes
Doing this causes problems:

    z.write(Buffer(0));
    z.end();

Fix by not ending Writable streams while they're still in the process of
writing something.
2013-03-24 14:23:21 -07:00
isaacs
e0cec37d50 stream: Remove unnecessary nextTick usage in Writable
Fix #4928
2013-03-06 11:44:29 -08:00
isaacs
312289b791 stream: Use class for write buffer entries 2013-03-05 14:27:16 -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
049903e333 stream: Split Writable logic into small functions
1. Get rid of unnecessary 'finishing' flag
2. Dont check both ending and ended. Extraneous.

Also: Remove extraneous 'finishing' flag, and don't check both 'ending'
and 'ended', since checking just 'ending' is sufficient.
2013-03-05 14:26:34 -08:00
isaacs
384f1be739 stream: Writable.end(chunk) after end is an error
Calling end(data) calls write(data).  Doing this after end should
raise a 'write after end' error.

However, because end() calls were previously ignored on already
ended streams, this error was confusingly suppressed, even though the
data never is written, and cannot get to the other side.

This is a re-hash of 5222d19a11, but
without assuming that the data passed to end() is valid, and thus
breaking a bunch of tests.
2013-03-03 17:26:38 -08:00
Ben Noordhuis
80ea63b958 Revert "stream: Writable.end(chunk) after end is an error"
It's breaking ~22 tests, Needs further investigation.

This reverts commit 5222d19a11.
2013-03-03 02:21:28 +01:00
isaacs
5222d19a11 stream: Writable.end(chunk) after end is an error
Calling end(data) calls write(data).  Doing this after end should
raise a 'write after end' error.

However, because end() calls were previously ignored on already
ended streams, this error was confusingly suppressed, even though the
data never is written, and cannot get to the other side.
2013-03-02 16:09:16 -08:00
isaacs
2106ef000c net: Provide better error when writing after FIN
The stock writable stream "write after end" message is overly vague, if
you have clearly not called end() yourself yet.

When we receive a FIN from the other side, and call destroySoon() as a
result, then generate an EPIPE error (which is what would happen if you
did actually write to the socket), with a message explaining what
actually happened.
2013-03-02 11:26:39 -08:00
isaacs
86433979c6 stream: Writables are not pipe()able
This handles the fact that stream.Writable inherits from the Stream class,
meaning that it has the legacy pipe() method.  Override that with a pipe()
method that emits an error.

Ensure that Duplex streams ARE still pipe()able, however.

Since the 'readable' flag on streams is sometimes temporary, it's probably
better not to put too much weight on that.  But if something is an instanceof
Writable, rather than of Readable or Duplex, then it's safe to say that
reading from it is the wrong thing to do.

Fix #3647
2013-02-26 18:54:05 -08:00
isaacs
34046084c0 stream: Do not switch to objectMode implicitly
Only handle objects if explicitly told to do so in the options
object.  Non-buffer/string chunks are an error if not already in
objectMode.

Close #4662
2013-02-25 07:38:10 -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
33b2aebb6d stream: Writable should ignore encoding for buffers
Fix #4727
Fix einaros/ws#159
2013-02-07 08:50:18 -08:00
Nathan Rajlich
a9c4a20331 stream: make Writable#end() accept a callback function
This is more backwards-compatible with stream1 streams like `fs.WriteStream`
which would allow a callback function to be passed in as the only argument.

Closes #4719.
2013-02-05 15:12:06 -08:00
Raynos
444bbd4fa7 streams: Support objects other than Buffers
We detect for non-string and non-buffer values in onread and
turn the stream into an "objectMode" stream.

If we are in "objectMode" mode then howMuchToRead will
always return 1, state.length will always have 1 appended
to it when there is a new item and fromList always takes
the first value from the list.

This means that for object streams, the n in read(n) is
ignored and read() will always return a single value

Fixed a bug with unpipe where the pipe would break because
the flowing state was not reset to false.

Fixed a bug with sync cb(null, null) in _read which would
forget to end the readable stream
2013-01-24 07:49:27 -08:00
isaacs
20a3c5d09c streams2: Do not allow hwm < lwm
There was previously an assert() in there, but this part of the code is
so high-volume that the added cost made a measurable dent in http_simple.

Just checking inline is fine, though, and prevents a lot of potential
hazards.
2013-01-14 16:03:38 -08:00
isaacs
f9caf7020c streams: Speed up by doing less work in the state ctors 2012-12-21 00:07:34 +00:00
isaacs
9f4c0988c3 streams2: Process write buffer in a loop, not recursively
This fixes pummel/test-net-write-callbacks
2012-12-19 10:55:23 -08:00
isaacs
f63af64eb8 test-pummel: Add call validation in net-write-callbacks 2012-12-19 10:55:23 -08:00
isaacs
82c7c84e25 net: Handle sync writable streams synchronously
This fixes the case where stderr doesn't flush before the process exits.
2012-12-17 15:08:57 -08:00
isaacs
3751c0fe40 streams2: Still emit error if there was a write() cb 2012-12-14 17:46:23 -08:00
isaacs
5760244cc6 streams2: Writable only emit 'finish' once 2012-12-14 10:52:28 -08:00
isaacs
b15e19a232 streams2: Remove function.bind() usage
It's too slow, unfortunately.
2012-12-13 17:00:32 -08:00
isaacs
0118584433 streams2: Writable organization, add 'finishing' flag 2012-12-13 17:00:31 -08:00
isaacs
63ac07b32b streams2: Export Readable/Writable State classes 2012-12-13 17:00:30 -08:00
isaacs
e82d06bef9 streams2: Fix regression from Duplex ctor assignment 2012-12-13 17:00:28 -08:00
isaacs
71e2b61388 streams2: Support write(chunk,[encoding],[callback]) 2012-12-13 17:00:27 -08:00
isaacs
0678480b57 streams2: Allow Writables to opt out of pre-buffer-izing 2012-12-13 17:00:27 -08:00
isaacs
545f512619 streams2: ctor guards on Stream classes 2012-12-13 17:00:26 -08:00
isaacs
06e321d0f9 streams2: Correct drain/return logic
It was testing the length *before* adding the current chunk, which
is the opposite of correct.

Also, the return value was flipped.
2012-12-13 17:00:25 -08:00
isaacs
02f017d24f streams2: Allow 0 as a lowWaterMark value 2012-12-13 17:00:25 -08:00
isaacs
639fbe28d1 streams2: Convert strings to buffers before passing to _write() 2012-12-13 17:00:23 -08:00
isaacs
420e07c577 streams2: The new stream base classes 2012-12-13 17:00:23 -08:00