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

36 Commits

Author SHA1 Message Date
isaacs
61c9f78c63 Merge remote-tracking branch 'ry/v0.10' into master
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/ChangeLog
	deps/uv/config-unix.mk
	deps/uv/src/unix/stream.c
	deps/uv/src/version.c
	deps/uv/uv.gyp
	src/node.cc
	src/node_buffer.cc
	src/node_crypto.cc
	src/node_version.h
	src/stream_wrap.cc
	src/stream_wrap.h
2013-05-17 14:04:54 -07:00
isaacs
bdb78b9945 stream: don't create unnecessary buffers in Readable
If there is an encoding, and we do 'stream.push(chunk, enc)', and the
encoding argument matches the stated encoding, then we're converting from
a string, to a buffer, and then back to a string.  Of course, this is a
completely pointless bit of work, so it's best to avoid it when we know
that we can do so safely.
2013-05-14 11:36:04 -07:00
Bert Belder
bdc5881169 Merge branch 'v0.10'
Conflicts:
	tools/test.py
2013-05-13 11:13:39 -07:00
Robert Kowalski
dc92ff8585 doc: document stream.Writable 'error' event
Fixes #5255.
2013-05-08 18:15:50 -07:00
isaacs
9cfc92979b doc: stream writev cleanups 2013-04-27 23:41:16 -07:00
Fedor Indutny
21ed8df696 streams: introduce .cork/.uncork/._writev 2013-04-27 15:59:13 +04:00
isaacs
b0de1e4a41 stream: Fix unshift() race conditions
Fix #5272

The consumption of a readable stream is a dance with 3 partners.

1. The specific stream Author (A)
2. The Stream Base class (B), and
3. The Consumer of the stream (C)

When B calls the _read() method that A implements, it sets a 'reading'
flag, so that parallel calls to _read() can be avoided.  When A calls
stream.push(), B knows that it's safe to start calling _read() again.

If the consumer C is some kind of parser that wants in some cases to
pass the source stream off to some other party, but not before "putting
back" some bit of previously consumed data (as in the case of Node's
websocket http upgrade implementation).  So, stream.unshift() will
generally *never* be called by A, but *only* called by C.

Prior to this patch, stream.unshift() *also* unset the state.reading
flag, meaning that C could indicate the end of a read, and B would
dutifully fire off another _read() call to A.  This is inappropriate.
In the case of fs streams, and other variably-laggy streams that don't
tolerate overlapped _read() calls, this causes big problems.

Also, calling stream.shift() after the 'end' event did not raise any
kind of error, but would cause very strange behavior indeed.  Calling it
after the EOF chunk was seen, but before the 'end' event was fired would
also cause weird behavior, and could lead to data being lost, since it
would not emit another 'readable' event.

This change makes it so that:

1. stream.unshift() does *not* set state.reading = false
2. stream.unshift() is allowed up until the 'end' event.
3. unshifting onto a EOF-encountered and zero-length (but not yet
end-emitted) stream will defer the 'end' event until the new data is
consumed.
4. pushing onto a EOF-encountered stream is now an error.

So, if you read(), you have that single tick to safely unshift() data
back into the stream, even if the null chunk was pushed, and the length
was 0.
2013-04-11 16:12:48 -07:00
Iskren Ivov Chernev
2f4a62c5e1 doc: fix streams2 SimpleProtocol example
A non-existing variable `b` was used to queue data for reading.
2013-03-20 00:34:31 +01: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
Lars-Magnus Skog
4b20f3440d doc change for Readable._read() 2013-03-01 16:33:48 -08:00
isaacs
fc22986023 doc: Clarify advisory-ness of stream._read() argument 2013-03-01 14:26:35 -08:00
Gil Pedersen
13c8bc8917 doc: Update to reflect new _read() interface 2013-03-01 14:23:51 -08:00
Evan Oxfeld
16ddc545bd doc: Fix readable.unshift() example
Slice the portion of the buffer to unshift back into the read queue
2013-03-01 14:21:34 -08:00
isaacs
4926ffd14b doc: Provide 2 examples of SimpleProtocol parser
The first example uses Readable, and shows the use of
readable.unshift().  The second uses the Transform class, showing that
it's much simpler in this case.
2013-02-28 17:38:17 -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
Nathan Rajlich
1ba39226b2 doc: document the writable.end() callback function
Support for it was added in a9c4a20331.
2013-02-09 10:34:18 -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
a993f740f0 stream: Add readable.push(chunk) method 2013-01-10 13:49:53 -08:00
Andreas Madsen
ce30683012 doc: document the finish event
Since the stream implementer is not expected to overwrite
.end() the finish event is necessary in order to know when
no more data can be written
2012-12-26 14:56:02 -08:00
isaacs
982981442d doc: Nudge formatting to make json generator happy
Starting a line with `**bold**` text makes it think that it's a link,
and get confused.

This should really be fixed properly in the doc generator, but for now,
it's not a major issue.  It's probably just a matter of updating marked.
2012-12-21 11:32:29 -08:00
isaacs
20a88feb8f docs: streams2 2012-12-14 10:52:29 -08:00
Ben Noordhuis
b0d04ffbd8 doc: stream: clarify meaning of 'drain' some more
Courtesy of Lee Coltrane (@coltrane).
2012-10-03 13:38:03 +02:00
Ben Noordhuis
f624be4093 doc: stream: clarify meaning of 'drain' event 2012-10-03 00:49:27 +02:00
isaacs
b90c1502e5 doc: Correct stream.write fd mention
No streams actually work this way.
2012-10-01 14:30:02 -07:00
isaacs
559a98f0d7 doc: Formatting and grammar on stream api doc 2012-07-07 09:53:33 -07:00
Dominic Tarr
7accaeb490 correct documentation of Stream#destroy 2012-07-07 09:51:00 -07:00
Ben Kelly
c6185c8484 doc: Improve cross-linking in API docs markdown
Cross-link EventEmitter references in API docs to events.html

Fix broken cross-reference links with wrong anchor names in API docs.
2012-06-15 09:44:37 -07:00
Ben Noordhuis
05b81f333c doc: clarify stream 'close' event 2012-05-16 16:08:18 +02:00
isaacs
5164ae3838 Merge remote-tracking branch 'ry/v0.6' into v0.6-merge
Conflicts:
	ChangeLog
	deps/uv/include/uv-private/uv-unix.h
	deps/uv/src/unix/core.c
	deps/uv/src/unix/sunos.c
	deps/v8/src/runtime.cc
	doc/api/crypto.markdown
	lib/http.js
	src/node_version.h
	test/gc/test-http-client-timeout.js
	wscript
2012-05-15 11:37:34 -07:00
Philip Tellis
493beb23f2 doc: fs.ReadableStream does not have a destroySoon method 2012-05-09 23:32:50 +02:00
koichik
9f3c639a9c doc: fix setEncoding()
Fixes #3209.
2012-05-05 23:10:36 +09:00
domenic
5bc07cc90b doc: note that stream.pause is advisory 2012-04-17 14:14:09 +02:00
isaacs
2d44dcc8be doc: Add stability indicators to documentation 2012-03-03 17:03:52 -08:00
isaacs
7bfa5cf284 s/streams/stream/ 2012-02-29 16:04:55 -08:00