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

2074 Commits

Author SHA1 Message Date
Ben Noordhuis
3f7e88a852 buffer: accept negative indices in Buffer#slice()
A negative start or end parameter now indexes from the end of the
buffer. More in line with String#slice() and ArrayBuffer#slice().
2013-02-12 17:09:19 -08:00
isaacs
2789323902 net: Respect the 'readable' flag on sockets
Previously, we were only destroying sockets on end if their readable
side had already been ended.  This causes a problem for non-readable
streams, since we don't expect to ever see an 'end' event from those.

Treat the lack of a 'readable' flag the same as if it was an ended
readable stream.

Fix #4751
2013-02-12 16:49:26 -08:00
Fedor Indutny
c34326b286 test: fix tests after ECONNRESET patch 2013-02-12 15:00:13 +04:00
Victor Costan
e235bce2ba Fix crypto.hmac behavior with empty keys.
node 0.9.6 introduced Buffer changes that cause the key argument of
Hmac::HmacInit (used in crypto.createHmac) to be NULL when the key is
empty. This argument is passed to OpenSSL's HMAC_Init, which does not
like NULL keys.

This change works around the issue by passing an empty string to
HMAC_Init when the key is empty, and adds crypto.createHmac tests for
the edge cases of empty keys and values.
2013-02-12 14:11:22 +04:00
isaacs
02374d0c17 tls: Cycle data when underlying socket drains 2013-02-11 16:43:10 -08:00
Ben Noordhuis
f5f9e8da71 crypto: improve cipher/decipher error messages
Throw the OpenSSL error string instead of the rather less informative
error message "fail".
2013-02-11 23:19:48 +01:00
isaacs
862b164209 test: update http tests for ECONNRESET change 2013-02-11 12:31:21 -08:00
Ben Noordhuis
14a4245051 net: don't suppress ECONNRESET
Let ECONNRESET network errors bubble up so clients can detect them.

Commit c4454d2e suppressed and turned them into regular end-of-stream
events to fix the then-failing simple/test-regress-GH-1531 test. See
also issue #1571 for (scant) details.

It turns out that special handling is no longer necessary. Remove the
special casing and let the error bubble up naturally.

pummel/test-https-ci-reneg-attack and pummel/test-tls-ci-reneg-attack
are updated because they expected an EPIPE error code that is now an
ECONNRESET. Suppression of the ECONNRESET prevented the test from
detecting that the connection has been severed whereupon the next
write would fail with an EPIPE.

Fixes #1776.
2013-02-11 12:31:21 -08:00
Ben Noordhuis
c7b84a1d01 fs: fix immediate WriteStream#end()
Fix an exception that was raised when the WriteStream was closed
immediately after creating it:

  TypeError: Cannot read property 'fd' of undefined
      at WriteStream.close (fs.js:1537:18)
      <snip>

Avoid the TypeError and make sure the file descriptor is closed.

Fixes #4745.
2013-02-11 21:15:13 +01:00
Ben Noordhuis
ed3d553d82 typed arrays: make call-as-function work for ctors
Turn call-as-function calls into constructor calls. Makes the following
snippet work:

  var buf = ArrayBuffer(32);  // no 'new' but does the right thing
2013-02-11 17:38:32 +01:00
Ben Noordhuis
d5a5ae3c11 test: fix common.mustCall
Don't run the 'has function been called?' checks if the test is exiting
with an error because a failed check will mask the real exception.

v0.8 doesn't have the _fatalException machinery in src/node.js and
src/node.cc so it doesn't have this issue.
2013-02-11 13:37:33 +01:00
Ben Noordhuis
5a9d30bb86 typed arrays: copy Buffer in typed array constructor
Convert the Buffer to an ArrayBuffer. The typed_array.buffer property
should be an ArrayBuffer to avoid confusion: a Buffer doesn't have a
byteLength property and more importantly, its slice() method works
subtly different.

That means that before this commit:

  var buf = new Buffer(1);
  var arr = new Int8Array(buf);
  assert.equal(arr.buffer, buf);
  assert(arr.buffer instanceof Buffer);

And now:

  var buf = new Buffer(1);
  var arr = new Int8Array(buf);
  assert.notEqual(arr.buffer, buf);
  assert(arr.buffer instanceof ArrayBuffer);
2013-02-10 21:31:41 +01:00
Ben Noordhuis
fe103357ae typed arrays: make DataView throw on non-ArrayBuffer
Make the DataView constructor throw an exception when the first
argument is not an ArrayBuffer. Follows the spec and the browsers.
2013-02-10 15:22:40 +01:00
Ben Noordhuis
234551a22a buffer: fix Buffer::HasInstance() check
It was returning true for typed arrays. Check that the object was
instantiated with the Buffer constructor.
2013-02-10 15:22:40 +01:00
Ben Noordhuis
144e21ed30 Revert "typed arrays: only share ArrayBuffer backing store"
We're going to fix this differently. The real bug is that
Buffer::HasInstance() returns true for typed arrays.

This reverts commit 01ee551e70.
2013-02-10 15:22:27 +01:00
Ben Noordhuis
fd9d8b5e4a Revert "typed arrays: copy non-ArrayBuffer in DataView ctor"
We're going to follow browser behavior here.

This reverts commit 7b0770bff5.
2013-02-10 15:22:27 +01:00
isaacs
33b2aebb6d stream: Writable should ignore encoding for buffers
Fix #4727
Fix einaros/ws#159
2013-02-07 08:50:18 -08:00
isaacs
5cc3569f6d Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	deps/npm/html/api/bin.html
	deps/npm/html/api/bugs.html
	deps/npm/html/api/commands.html
	deps/npm/html/api/config.html
	deps/npm/html/api/deprecate.html
	deps/npm/html/api/docs.html
	deps/npm/html/api/edit.html
	deps/npm/html/api/explore.html
	deps/npm/html/api/help-search.html
	deps/npm/html/api/init.html
	deps/npm/html/api/install.html
	deps/npm/html/api/link.html
	deps/npm/html/api/load.html
	deps/npm/html/api/ls.html
	deps/npm/html/api/npm.html
	deps/npm/html/api/outdated.html
	deps/npm/html/api/owner.html
	deps/npm/html/api/pack.html
	deps/npm/html/api/prefix.html
	deps/npm/html/api/prune.html
	deps/npm/html/api/publish.html
	deps/npm/html/api/rebuild.html
	deps/npm/html/api/restart.html
	deps/npm/html/api/root.html
	deps/npm/html/api/run-script.html
	deps/npm/html/api/search.html
	deps/npm/html/api/shrinkwrap.html
	deps/npm/html/api/start.html
	deps/npm/html/api/stop.html
	deps/npm/html/api/submodule.html
	deps/npm/html/api/tag.html
	deps/npm/html/api/test.html
	deps/npm/html/api/uninstall.html
	deps/npm/html/api/unpublish.html
	deps/npm/html/api/update.html
	deps/npm/html/api/version.html
	deps/npm/html/api/view.html
	deps/npm/html/api/whoami.html
	deps/npm/html/doc/README.html
	deps/npm/html/doc/adduser.html
	deps/npm/html/doc/bin.html
	deps/npm/html/doc/bugs.html
	deps/npm/html/doc/build.html
	deps/npm/html/doc/bundle.html
	deps/npm/html/doc/cache.html
	deps/npm/html/doc/changelog.html
	deps/npm/html/doc/coding-style.html
	deps/npm/html/doc/completion.html
	deps/npm/html/doc/config.html
	deps/npm/html/doc/dedupe.html
	deps/npm/html/doc/deprecate.html
	deps/npm/html/doc/developers.html
	deps/npm/html/doc/disputes.html
	deps/npm/html/doc/docs.html
	deps/npm/html/doc/edit.html
	deps/npm/html/doc/explore.html
	deps/npm/html/doc/faq.html
	deps/npm/html/doc/folders.html
	deps/npm/html/doc/global.html
	deps/npm/html/doc/help-search.html
	deps/npm/html/doc/help.html
	deps/npm/html/doc/index.html
	deps/npm/html/doc/init.html
	deps/npm/html/doc/install.html
	deps/npm/html/doc/json.html
	deps/npm/html/doc/link.html
	deps/npm/html/doc/ls.html
	deps/npm/html/doc/npm.html
	deps/npm/html/doc/outdated.html
	deps/npm/html/doc/owner.html
	deps/npm/html/doc/pack.html
	deps/npm/html/doc/prefix.html
	deps/npm/html/doc/prune.html
	deps/npm/html/doc/publish.html
	deps/npm/html/doc/rebuild.html
	deps/npm/html/doc/registry.html
	deps/npm/html/doc/removing-npm.html
	deps/npm/html/doc/restart.html
	deps/npm/html/doc/rm.html
	deps/npm/html/doc/root.html
	deps/npm/html/doc/run-script.html
	deps/npm/html/doc/scripts.html
	deps/npm/html/doc/search.html
	deps/npm/html/doc/semver.html
	deps/npm/html/doc/shrinkwrap.html
	deps/npm/html/doc/star.html
	deps/npm/html/doc/start.html
	deps/npm/html/doc/stop.html
	deps/npm/html/doc/submodule.html
	deps/npm/html/doc/tag.html
	deps/npm/html/doc/test.html
	deps/npm/html/doc/uninstall.html
	deps/npm/html/doc/unpublish.html
	deps/npm/html/doc/update.html
	deps/npm/html/doc/version.html
	deps/npm/html/doc/view.html
	deps/npm/html/doc/whoami.html
	deps/npm/man/man1/global.1
	deps/npm/man/man1/ls.1
	deps/npm/man/man1/npm.1
	deps/npm/man/man1/rm.1
	deps/npm/man/man3/npm.3
	deps/npm/node_modules/glob/glob.js
	deps/npm/node_modules/glob/package.json
	deps/npm/node_modules/node-gyp/package.json
	deps/npm/node_modules/npm-registry-client/package.json
	deps/npm/node_modules/npmconf/package.json
	deps/npm/node_modules/read-installed/package.json
	deps/npm/node_modules/rimraf/package.json
	deps/npm/node_modules/rimraf/rimraf.js
	deps/npm/package.json
	deps/uv/src/win/error.c
	doc/api/crypto.markdown
	lib/zlib.js
	src/node_version.h
	src/node_zlib.cc
	test/simple/test-buffer.js
2013-02-06 16:29:30 -08:00
Ben Noordhuis
7b0770bff5 typed arrays: copy non-ArrayBuffer in DataView ctor
This is commit 01ee551, except for the DataView type this time.

Make the behavior of DataView consistent with that of typed arrays:
make a copy of the backing store.
2013-02-06 22:26:50 +01:00
Fedor Indutny
c024d2d8c0 streams: both finish and close should unpipe
Otherwise sockets that are 'finish'ed won't be unpiped and `writing to
ended stream` error will arise.

This might sound unrealistic, but it happens in net.js. When
`socket.allowHalfOpen === false`, EOF will cause `.destroySoon()` call which
ends the writable side of net.Socket.
2013-02-06 20:38:20 +04:00
Ben Noordhuis
b58efe7709 test: add cluster EADDRINUSE test
Check that having a worker bind to a port that's already taken doesn't
leave the master process in a confused state. Releasing the port and
trying again should Just Work[TM].
2013-02-06 15:10:53 +01:00
Ben Noordhuis
01ee551e70 typed arrays: only share ArrayBuffer backing store
Follow browser behavior, only share the backing store when it's a
ArrayBuffer. That is:

  var abuf = new ArrayBuffer(32);
  var a = new Int8Array(abuf);
  var b = new Int8Array(abuf);
  a[0] = 0;
  b[0] = 1;
  assert(a[0] === b[0]);  // a and b share memory

But:

  var a = new Int8Array(32);
  var b = new Int8Array(a);
  a[0] = 0;
  b[0] = 1;
  assert(a[0] !== b[0]);  // a and b don't share memory

The typed arrays spec allows both `a[0] === b[0]` and `a[0] !=== b[0]`
but Chrome and Firefox implement the behavior where memory is not
shared.

Copying the memory is less efficient but let's do it anyway for the
sake of the Principle of Least Surprise.

Fixes #4714.
2013-02-06 14:21:35 +01: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
isaacs
916aebabb8 debugger: Make the debugger timeout configurable
If the NODE_DEBUGGER_TIMEOUT environment variable is set, then use
that as the number of ms to wait for the debugger to start.

This is primarily to work around a race condition that almost never
happens in real usage with the debugger, but happens EVERY FRACKING
TIME when the debugger tests run as part of 'make test'.
2013-02-01 15:58:51 -08:00
isaacs
a6c18472cd stream: Don't stop reading on zero-length decoded output
Fixes regression introduced in 7e1cf84c9e
2013-01-31 13:33:37 -08:00
isaacs
7e1cf84c9e stream: Don't signal EOF on '' or Buffer(0)
Those values, if passed to the _read() cb, will not signal an EOF.  Only
null or undefined will mark the end of data, and trigger the end event.

However, great care must be taken if you are returning an empty string
or buffer!  There must be some other thing somewhere that will trigger
a read() call, because there will never be a readable event fired later.

This is in preparation for CryptoStreams being ported to streams2, where
it is safe to simply stop reading, because the crypto cycle process will
cause it to read(0) again at some future date.
2013-01-31 11:59:36 -08:00
Ben Noordhuis
3fe6aba558 os: rename tmpDir() to tmpdir() for consistency
Make the casing consistent with the other os.* functions but keep
os.tmpDir() around as an alias.
2013-01-30 04:24:58 +01:00
isaacs
60f18ede39 readline: treat bare \r as a line ending
Fixes #3305
2013-01-29 18:21:31 -08:00
Ben Noordhuis
9bd9c546c8 readline: make \r\n emit one 'line' event
Make lines ending \r\n emit one 'line' event, not two (where the second
one is an empty string).

This adds a new keypress name: 'return' (as in: 'carriage return').

Fixes #3305.
2013-01-29 17:15:24 +01:00
isaacs
bda45a8be1 Revert "net: Avoid tickDepth warnings on small writes"
This commit breaks simple/test-stream2-stderr-sync.  Need to figure out
a better way, or just accept that `(function W(){stream.write(b,W)})()`
is going to be noisy.  People should really be using the `'drain'` event
for this use-case anyway.

This reverts commit 02f7d1bfd8.
2013-01-28 17:15:22 -08:00
isaacs
02f7d1bfd8 net: Avoid tickDepth warnings on small writes
Always defer the _write callback.  The optimization here was only
relevant in some oddball edge cases that we don't actually care about.

Our benchmarks confirm that just always deferring the Socket._write cb
is perfectly fine to do, and in some cases, even slightly more
performant.
2013-01-28 16:16:21 -08:00
Bert Belder
5e7e51c2fe cluster: support datagram sockets 2013-01-28 22:12:21 +01: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
Fedor Indutny
0d7a0216dc net: initialize TCPWrap when receiving socket
TCPWrap::Initialize() and PipeWrap::Initialize() should be called before
any data will be read from received socket. But, because of lazy
initialization of these bindings, Initialize() method isn't called.

Init bindings manually upon socket receiving.

See #4669
2013-01-28 16:37:09 +04:00
Ben Noordhuis
a39f669bc7 test: move simple/test-http-dns-fail to test/internet
The test times out when the upstream DNS resolver takes too long to
respond.

See #4672.
2013-01-28 12:41:56 +01:00
Ben Noordhuis
acd0df4ad9 test: fix pummel test out-of-memory errors
Fix the following OOM error in pummel/test-net-connect-memleak
and pummel/test-tls-connect-memleak:

  FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of
  memory

Commit v8/v8@91afd39 increases the size of the deoptimization table
to the extent that a 64M float array pushes it over the brink. Switch
to SMIs so it stays below the limit.

pummel/test-net-connect-memleak is still failing albeit with a different
error this time. Needs further investigation.

  === release test-net-connect-memleak ===
  Path: pummel/test-net-connect-memleak
  -64 kB reclaimed
  assert.js:102
    throw new assert.AssertionError({
          ^
  AssertionError: false == true
      at done [as _onTimeout] (/home/bnoordhuis/src/nodejs/master/
  test/pummel/test-net-connect-memleak.js:48:3)
      at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
      at process._makeCallback (node.js:306:20)
2013-01-27 22:01:14 +01:00
isaacs
15508589a1 addon: Pass module object to NODE_MODULE init function
mainly to allow native addons to export single functions on
rather than being restricted to operating on an existing
object.

Init functions now receive exports as the first argument, like
before, but also the module object as the second argument, if they
support it.

Related to #4634

cc: @rvagg
2013-01-25 14:25:35 -08:00
Trevor Norris
65249ccd9b buffer: slow buffer copy compatibility fix
Fix issue where SlowBuffers couldn't be passed as target to Buffer
copy().

Also included checks to see if Argument parameters are defined before
assigning their values. This offered ~3x's performance gain.

Backport of 16bbecc from master branch. Closes #4633.
2013-01-25 10:42:38 -08:00
Trevor Norris
49175e6ae2 buffer: clean up copy() asserts and tests
Argument checks were simplified by setting all undefined/NaN or out of
bounds values equal to their defaults.

Also copy() tests had a flaw that each buffer had the same bit pattern at
the same offset. So even if the copy failed, the bit-by-bit comparison
would have still been true. This was fixed by filling each buffer with a
unique value before copy operations.
2013-01-25 11:59:21 +01:00
Trevor Norris
16bbeccd40 buffer: slow buffer copy compatibility fix
Fix issue where SlowBuffers couldn't be passed as target to Buffer
copy().

Also included checks to see if Argument parameters are defined before
assigning their values. This offered ~3x's performance gain.
2013-01-25 11:58:51 +01:00
Andy Burke
595b5974d7 Add bytesWritten to tls.CryptoStream
This adds a proxy for bytesWritten to the tls.CryptoStream.  This
change makes the connection object more similar between HTTP and
HTTPS requests in an effort to avoid confusion.

See issue #4650 for more background information.
2013-01-24 16:48:49 -08:00
isaacs
6e05faa3d0 test: Add transform objectMode test 2013-01-24 10:12:19 -08:00
Fedor Indutny
82f1d340c1 tls: make slab buffer's size configurable
see #4636
2013-01-24 08:47:07 -08:00
isaacs
5d3c51d937 test: Add test for negative stream drain counter 2013-01-24 07:49:27 -08:00
isaacs
782149ddc3 streams2: Handle sync read callbacks nicely 2013-01-24 07:49:27 -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
Ben Noordhuis
4a7a98fd0a http: close connection on 204 and chunked encoding
This is similar to commit 2cbf458 but this time for 204 No Content
instead of 304 Not Modified responses.

When the user sends a 204 response with a Transfer-Encoding: chunked
header, suppress sending the zero chunk and force the connection to
close.
2013-01-24 11:23:36 +01:00
Ben Noordhuis
2cbf4586df http: close connection on 304 and chunked encoding
Force the connection to close when the response is a 304 Not Modified
and the user has set a "Transfer-Encoding: chunked" header.

RFC 2616 mandates that 304 responses MUST NOT have a body but node.js
used to send out a zero chunk anyway to accommodate clients that don't
have special handling for 304 responses.

It was pointed out that this might confuse reverse proxies to the point
of creating security liabilities, so suppress the zero chunk and force
the connection to close.
2013-01-23 01:47:24 +01:00
Ben Noordhuis
d7bf7ed993 zlib: don't assert on malformed dictionary
Handle Z_DATA_ERROR errors from inflateSetDictionary() gracefully.
Fixes the following assertion:

  node: ../src/node_zlib.cc:167: static void node::ZCtx::Process
  (uv_work_t*): Assertion `ctx->err_ == 0 && "Failed to set
  dictionary"' failed.
  Aborted (core dumped)

Fixes #4632.
2013-01-22 13:34:43 +01:00
Ben Noordhuis
1c32eb4ae2 zlib: don't assert on missing dictionary
Handle Z_NEED_DICT errors graciously. Fixes the following assertion:

  node: ../src/node_zlib.cc:161: static void node::ZCtx::Process
  (uv_work_t*): Assertion`ctx->dictionary_ != __null && "Stream
  has no dictionary"' failed.
  Aborted (core dumped)

Fixes #4632.
2013-01-22 13:34:43 +01:00