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

73 Commits

Author SHA1 Message Date
micnic
20285ad177 lib: Consistent error messages in all modules
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-09 20:08:36 +01:00
Fábio Santos
85b74de9de stream: fix signature of _write() in a comment
This comment was a bit misleading, since it was missing the `encoding`
argument.

PR-URL: https://github.com/nodejs/node/pull/3248
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-10-13 22:32:21 -07:00
Sakthipriyan Vairamani
9cd44bb2b6 util: prepend '(node) ' to deprecation messages
Changes included in this commit are

   1. Making the deprecation messages consistent. The messages will be in
      the following format

           x is deprecated. Use y instead.

      If there is no alternative for `x`, then the ` Use y instead.` part
      will not be there in the message.

   2. All the internal deprecation messages are printed with the prefix
      `(node) `, except when the `--trace-deprecation` flag is set.

Fixes: https://github.com/nodejs/io.js/issues/1883
PR-URL: https://github.com/nodejs/io.js/pull/1892
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-07-03 16:32:29 +02:00
Roman Reiss
b5b8ff117c lib: don't use global Buffer
Port of https://github.com/joyent/node/pull/8603

The race condition present in the original PR didn't occur, so no
workaround was needed.

PR-URL: https://github.com/nodejs/io.js/pull/1794
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-06-11 20:24:44 +02:00
Brian White
5abd4ac079 lib: simplify nextTick() usage
This commit removes unnecessary nextTick() closures and adds some
shared nextTick() callbacks for better re-use.

PR-URL: https://github.com/nodejs/io.js/pull/1612
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-05-25 10:14:18 -04:00
Yosuke Furukawa
19ffb5cf1c lib: fix eslint styles
PR-URL: https://github.com/iojs/io.js/pull/1539
Fixes: https://github.com/iojs/io.js/issues/1253
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-09 12:10:02 +09:00
Trevor Norris
10e31ba56c node: allow multiple arguments passed to nextTick
PR-URL: https://github.com/iojs/io.js/pull/1077
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-15 17:02:21 -06:00
Brian White
4dc6ae2181 lib: remove unused variables
PR-URL: https://github.com/iojs/io.js/pull/1290
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-31 15:58:42 -04:00
Sam Newman
50daee7243 stream: simpler stream constructon
Adds simplified constructor pattern, allowing users
to provide "read", "write", "transform", "flush", and
"writev" functions as stream options in lieu of subclassing.

Semver: minor
PR-URL: https://github.com/iojs/io.js/pull/697
Fixes: https://github.com/iojs/readable-stream/issues/102
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-02-04 20:19:39 -08:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).

Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31 23:47:29 -05:00
cjihrig
40ffed8f3f stream: use nop as write() callback if omitted
This commit introduces a nop function that is used as the
Writable.prototype.write() callback when one is not provided.
This saves on function object creation.

PR-URL: https://github.com/iojs/io.js/pull/564
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-01-23 09:43:31 -05:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Ben Noordhuis
94e147500c Merge remote-tracking branch 'joyent/v0.12' into v1.x
I was originally going to do this after the v0.11.15 release, but as
that release is three weeks overdue now, I decided not to wait any
longer; we don't want the delta to get too big.

Conflicts:
	lib/net.js
	test/simple/simple.status

PR-URL: https://github.com/iojs/io.js/pull/236
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2015-01-05 17:26:47 +01:00
Chris Dickinson
91586661c9 stream: switch _writableState.buffer to queue
In cases where many small writes are made to a stream
lacking _writev, the array data structure backing the
WriteReq buffer would greatly increase GC pressure.

Specifically, in the fs.WriteStream case, the
clearBuffer routine would only clear a single WriteReq
from the buffer before exiting, but would cause the
entire backing array to be GC'd. Switching to [].shift
lessened pressure, but still the bulk of the time was
spent in memcpy.

This replaces that structure with a linked list-backed
queue so that adding and removing from the queue is O(1).
In the _writev case, collecting the buffer requires an
O(N) loop over the buffer, but that was already being
performed to collect callbacks, so slowdown should be
neglible.

PR-URL: https://github.com/joyent/node/pull/8826
Reviewed-by: Timothy J Fontaine <tjfontaine@gmail.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-12-18 09:39:05 -08:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01:00
Brian White
874dd590cf streams: make setDefaultEncoding() throw
PR-URL: https://github.com/joyent/node/pull/8529
Fixes: f04f3a0 "streams: set default encoding for writable streams"
[trev.norris@gmail.com: update tests to check if throws]
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-10-09 16:48:59 -07:00
Johnny Ray
f04f3a0d01 streams: set default encoding for writable streams
Add API Writable#setDefaultEncoding().

PR-URL: https://github.com/joyent/node/pull/8483
Fixes: https://github.com/joyent/node/issues/7159
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-10-07 17:04:10 -07:00
Andrew Oppenlander
e1fec22f97 streams: set default hwm properly for Duplex
Default highWaterMark is now set properly when using stream Duplex's
writableObjectMode and readableObjectMode options.

Added condition to the already existing split objectMode test to ensure
the highWaterMark is being set to the correct default value on both the
ReadableState and WritableState for readableObjectMode and
writableObjectMode.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-10 13:28:55 +03:00
Vladimir Kurchatkin
82fca9136d stream: don't try to finish if buffer is not empty
fixes #5715
2014-05-06 06:50:25 -07:00
Vladimir Kurchatkin
d0fc5538d1 stream: split objectMode for Duplex
This commit introduces `readableObjectMode` and
`writableObjectMode` options for Duplex streams.
This can be used mostly to make parsers and
serializers with Transform streams.

Also the docs section about stream state objects
is removed, because it is not relevant anymore.
The example from the section is remade to show
new options.

fixes #6284

Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
2014-04-30 10:44:31 -07:00
Timothy J Fontaine
d58c206862 Merge remote-tracking branch 'upstream/v0.10'
Conflicts:
	lib/_stream_writable.js
2014-02-10 11:21:09 -08:00
Fedor Indutny
e2a1d9a9ac stream: use errorEmitted from _writableState 2014-02-10 11:06:03 -08:00
Fedor Indutny
dee5270a6c net: do not re-emit stream errors
fix #7015
2014-02-10 10:59:52 -08:00
Fedor Indutny
d019eac5b5 tls: emit clientError on early socket close
fix #6903
2014-01-24 22:09:17 +04:00
Timothy J Fontaine
429b58701a Merge remote-tracking branch 'upstream/v0.10'
Conflicts:
	deps/uv/ChangeLog
	deps/uv/build.mk
	deps/uv/src/version.c
	deps/uv/test/test-ipc.c
	deps/v8/src/objects.cc
	src/node.cc
	src/node_os.cc
2014-01-13 14:56:12 -08:00
ayanamist
b922b5e90d stream: writes may return false but forget to emit drain
If a write is above the highWaterMark, _write still manages to
fully send it synchronously, _writableState.length will be adjusted down
to 0 synchronously with the write returning false, but 'drain' will
not be emitted until process.nextTick.

If another small write which is below highWaterMark is issued before
process.nextTick happens, _writableState.needDrain will be reset to false,
and the drain event will never be fired.

So we should check needDrain before setting it up, which prevents it
from inproperly resetting to false.
2014-01-05 19:44:45 +04:00
Mathias Buus
ba72570eae stream: change default hwm for objectMode to 16 2013-08-27 18:02:30 -07:00
isaacs
a3da3e7312 stream: Pass 'buffer' encoding to decoded writables
Since the encoding is no longer relevant once it is decoded to a Buffer,
it is confusing and incorrect to pass the encoding as 'utf8' or whatever
in those cases.

Closes #6119
2013-08-27 14:53:06 -07:00
Matthew Aynalem
c171c490f2 fixes #6031 spelling errors
explictly => explicitly
accesss => access
througput => throughput
epxression => expression
communiction => communication
becuase => because
repersent => represent
condonitions => conditions
decompresion => decompression
intentially => intentionally
eventes => events
listning => listening
resicved => received
becuase => because
fundimental => fundamental
colapse => collapse
privlages => privileges
sufficently => sufficiently
hapepns => happens
expliclitly => explicitly
thier => their
shold => should
2013-08-19 16:42:16 -07:00
Brian White
6d842897c5 lib: remove unused variables and functions 2013-08-15 17:19:17 -07:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
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
d5158574c6 stream: Make default encoding configurable
Pretty much everything assumes strings to be utf-8, but crypto
traditionally used binary strings, so we need to keep the default
that way until most users get off of that pattern.
2013-05-14 11:36:05 -07:00
isaacs
a58454226f stream: Handle multi-corking properly
This adds proper support for the following situation:

    w.cork();
    w.write(...);
    w.cork();
    w.write(...);
    w.uncork();
    w.write(...);
    w.uncork();

This is relevant when you have a function (as we do in HTTP) that wants
to use cork, but in some cases, want to have a cork/uncork *around*
that function, without losing the benefits of writev.
2013-05-09 09:35:32 -07:00
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
Fedor Indutny
21ed8df696 streams: introduce .cork/.uncork/._writev 2013-04-27 15:59:13 +04:00
isaacs
c93af860a0 stream: call write cb before finish event
Since 049903e, an end callback could be called before a write
callback if end() is called before the write is done. This patch
resolves the issue.

In collaboration with @gne

Fixes felixge/node-formidable#209
Fixes #5215
2013-04-09 02:09:51 +04:00
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