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

2413 Commits

Author SHA1 Message Date
Ben Noordhuis
4231dab39f crypto: fix base64 padding regression
Commit 9901b69c introduces a small regression where the trailing base64
padding is no longer written out when Cipher#final is called. Rectify
that.

Fixes #4837.
2013-02-25 15:21:52 +01:00
isaacs
74c08403d8 lint 2013-02-22 16:30:27 -08:00
isaacs
27d1babaae streams: Pre-emptively buffer readables up to the highWaterMark
Also, this adds a test that guarantees that the ordering of several
push() calls in a row is always preserved in synchronous readable streams
2013-02-22 11:24:05 -08:00
isaacs
f9a0140ef1 http: Handle hangup writes more gently 2013-02-22 10:35:07 -08:00
isaacs
a63c28e6eb stream: Return false from push() more properly
There are cases where a push() call would return true, even though
the thing being pushed was in fact way way larger than the high
water mark, simply because the 'needReadable' was already set, and
would not get unset until nextTick.

In some cases, this could lead to an infinite loop of pushing data
into the buffer, never getting to the 'readable' event which would
unset the needReadable flag.

Fix by splitting up the emitReadable function, so that it always
sets the flag on this tick, even if it defers until nextTick to
actually emit the event.

Also, if we're not ending or already in the process of reading, it
now calls read(0) if we're below the high water mark.  Thus, the
highWaterMark value is the intended amount to buffer up to, and it
is smarter about hitting the target.
2013-02-21 15:23:18 -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
089ec58613 path: Throw TypeError on non-string args to path.resolve 2013-02-21 15:18:44 -08:00
Arianit Uka
055110dab0 path: join throws TypeError on non-string args
lib/path.js:
  - throws a TypeError on the filter if the argument is not a string.

test/simple/test-path.js:
  - removed the test to check if non-string types are filtered.
  - added a test to check if path.join throws TypeError on arguments that
    are not strings.
2013-02-21 11:50:47 -08:00
Fedor Indutny
ebc95f0716 tls: _handle.readStart/readStop for CryptoStream
lib/http.js is using stream._handle.readStart/readStop to control
data-flow coming out from underlying stream. If this methods are not
present - data might be buffered regardless of whether it'll be read.

see #4657
2013-02-21 23:29:18 +04:00
isaacs
bbcb8b3ae0 path: Do not coerce paths to strings on Windows
Fix #4795
2013-02-20 14:04:30 -08:00
Trevor Norris
d69a26b965 buffer: check logic simplification
Checks have been simplified and optimized for most-used cases.

Calling Buffer with another Buffer as the subject will now use the
SlowBuffer Copy method instead of the for loop.

No need to call for value coercion, just place the ternary inline.
2013-02-20 20:34:34 +01:00
isaacs
60238cce12 tls: Write pending data on socket drain
Fixes #4800
2013-02-19 11:41:39 -08:00
isaacs
09b1212254 http: Add fixme comment about ECONNRESET handling 2013-02-18 10:38:37 -08:00
isaacs
d75e39794b Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	lib/http.js
	src/node_version.h
	test/simple/test-http-header-response-splitting.js
2013-02-18 10:21:08 -08:00
Gil Pedersen
0a9930a230 stream: Pipe data in chunks matching read data
This creates better flow for large values of lowWaterMark.
2013-02-15 18:51:22 -08:00
isaacs
8476aefc8e fs: Change default WriteStream config, increase perf
This increases fs.WriteStream throughput dramatically by removing the
"higher default water marks" for fs.WriteStream.

Also includes a benchmark.  Current performance is significantly higher
than v0.8 for strings at all tested levels except size=1.  Buffer
performance is still lackluster.

Further improvement in the stream.Writable base class is required, but
this is a start.
2013-02-15 18:48:43 -08:00
Shigeki Ohtsu
cd372510bb timer: move setImmediate from timer to uv_check
uv_check is the robust place to invoke setImmediate callbacks after
process.nextTick and before timers(setTimeout/setInterval)
2013-02-15 16:11:05 -08:00
isaacs
987338fe31 http: Do not let Agent hand out destroyed sockets
Fix #4373
2013-02-14 16:03:40 -08:00
isaacs
c9dcf5718c http: Raise hangup error on destroyed socket write
Prior to v0.10, Node ignored ECONNRESET errors in many situations.
There *are* valid cases in which ECONNRESET should be ignored as a
normal part of the TCP dance, but in many others, it's a very relevant
signal that must be heeded with care.

Exacerbating this problem, if the OutgoingMessage does not have a
req.connection._handle, it assumes that it is in the process of
connecting, and thus buffers writes up in an array.

The problem happens when you reuse a socket between two requests, and it
is destroyed abruptly in between them.  The writes will be buffered,
because the socket has no handle, but it's not ever going to GET a
handle, because it's not connecting, it's destroyed.

The proper fix is to treat ECONNRESET correctly.  However, this is a
behavior/semantics change, and cannot land in a stable branch.

Fix #4775
2013-02-14 16:03:40 -08:00
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
isaacs
02374d0c17 tls: Cycle data when underlying socket drains 2013-02-11 16:43:10 -08:00
isaacs
1762dd7ed9 stream: read(0) should not always trigger _read(n,cb)
This is causing the CryptoStreams to get into an awful state when
there is a tight loop calling connection.write(chunk) waiting for
a false return.

Because CryptoStreams use read(0) to cycle data, this was causing
the encrypted side to pull way too much data in from the cleartext
side, since the read(0) would make it always call _read.

The unfortunate side effect, fixed in the next patch, is that
CryptoStreams don't automatically cycle when the Socket drains.
2013-02-11 16:43:09 -08:00
isaacs
6bd450155c stream: Empty strings/buffers do not signal EOF any longer 2013-02-11 16:43:09 -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
isaacs
33b2aebb6d stream: Writable should ignore encoding for buffers
Fix #4727
Fix einaros/ws#159
2013-02-07 08:50:18 -08:00
Bert Belder
255bc945c2 http: protect against response splitting attacks
This patch is a back-port of 3c293ba.
Closes #4696
2013-02-07 14:39:47 +01: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
Fedor Indutny
d59beb9f68 tls: port CryptoStream to streams2 2013-02-06 23:23:54 +04: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
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
Ben Noordhuis
8d14668992 zlib: reduce memory consumption, release early
In zlibBuffer(), don't wait for the garbage collector to reclaim the zlib memory
but release it manually. Reduces memory consumption by a factor of 10 or more
with some workloads.

Test case:

  function f() {
    require('zlib').deflate('xxx', g);
  }
  function g() {
    setTimeout(f, 5);
  }
  f();

Observe RSS memory usage with and without this commit. After 10,000 iterations,
RSS stabilizes at ~35 MB with this commit. Without, RSS is over 300 MB and keeps
growing.

Cause: whenever the JS object heap hits the high-water mark, the V8 GC sweeps
it clean, then tries to grow it in order to avoid more sweeps in the near
future. Rule of thumb: the bigger the JS heap, the lazier the GC can be.

A side effect of a bigger heap is that objects now live longer. This is harmless
in general but it affects zlib context objects because those are tied to large
buffers that live outside the JS heap, on the order of 16K per context object.

Ergo, don't wait for the GC to reclaim the memory - it may take a long time.

Fixes #4172.
2013-02-05 22:25:54 +01:00
Ben Noordhuis
cd42f56178 buffer: optimize Buffer.prototype.write(s, 'hex')
Move the implementation to C++ land. This is similar to commit 3f65916
but this time for the write() function and the Buffer(s, 'hex')
constructor.

Speeds up the benchmark below about 24x (2.6s vs 1:02m).

  var s = 'f';
  for (var i = 0; i < 26; ++i) s += s;  // 64 MB
  Buffer(s, 'hex');
2013-02-02 01:01:42 +01:00
Ben Noordhuis
3f65916fa9 buffer: optimize Buffer.prototype.toString('hex')
Move the implementation to C++ land. The old JS implementation used
string concatenation, was dog slow and consumed copious amounts of
memory for large buffers. Example:

  var buf = Buffer(0x1000000);  // 16 MB
  buf.toString('hex')           // Used 3+ GB of memory.

The new implementation operates in O(n) time and space.

Fixes #4700.
2013-02-01 23:07:17 +01: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
isaacs
f64d1febc8 lint 2013-01-29 23:57:23 -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
6311f1c30a dgram: avoid EventEmitter leak warning
When a datagram socket hasn't been bound yet, node will defer `send()`
operations until binding has completed. Before this patch a `listening`
listener would be installed every time `send` was called. This triggered
an EventEmitter leak warning when more than 10 packets were sent in a
tight loop. Therefore switch to using a single `listening` listener, and
use an array to enqueue outbound packets.
2013-01-28 22:19:02 +01:00
Bert Belder
5e7e51c2fe cluster: support datagram sockets 2013-01-28 22:12:21 +01:00
Fedor Indutny
c13354e339 child_process: move binding init in constructor
Doing this in net.Socket constructor has much more overhead, and
error is actually may happen before the construction of socket object.
2013-01-28 21:24:45 +04:00
isaacs
4c78a52a3a net: Initialize _connection, _handle in Socket ctor
The better to reduce the hidden classes
2013-01-28 09:09:34 -08:00
isaacs
faf78604ca http: Don't dump twice 2013-01-28 08:54:08 -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
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
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
cbe3941db9 buffer: error and misc cleanup
Changed types of errors thrown to be more indicative of what the error
represents. Also removed a few unnecessary uses of the v8 fully
quantified typename.
2013-01-25 11:59:26 +01: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
Fedor Indutny
82f1d340c1 tls: make slab buffer's size configurable
see #4636
2013-01-24 08:47:07 -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
Fedor Indutny
00abc243dd child_process: remove .track option
Since net.Server's `connection` property is deprecated now, we don't
need API to track socket's state to keep `connection`s value up-to-date.
2013-01-20 02:23:42 +04:00
isaacs
539bf1d7b7 console: Support formatting options in trace()
Fix #4589
2013-01-18 15:39:08 -08:00
isaacs
3d7818fc42 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	src/node_version.h
	test/simple/test-buffer.js
2013-01-18 12:58:16 -08:00
Ben Noordhuis
6b713b5253 cluster: make --prof work for workers
Profiling in clustered environments doesn't work out of the box.

By default, V8 writes the profile data of all processes to a single
v8.log.

Running that log file through a tick processor produces bogus numbers
because many events won't match up with the recorded memory mappings
and you end up with graphs where 80+% of ticks is unaccounted for.

Fixing the tick processor to deal with multi-process output is not very
useful because the processes may be running wildly disparate workloads.

That's why we fix up the command line arguments to include
a "--logfile=v8-%p.log" argument (where %p is expanded to the PID)
unless it already contains a --logfile argument.

Fixes #4617.
2013-01-18 12:56:40 +01:00
Dan Milon
7295bb9435 dns: make error message match errno 2013-01-18 12:13:32 +01:00
Fedor Indutny
31583be042 tls: follow RFC6125 more stricly
* Allow wildcards only in left-most part of hostname identifier.
* Do not match CN if altnames are present
2013-01-18 03:48:05 +04:00
Fedor Indutny
e70d1bfe64 Revert "Revert "tls: allow wildcards in common name""
This reverts commit 30e237041d.

Works properly with b4b750b
2013-01-18 03:47:47 +04:00
Fedor Indutny
4488a69fac child_process: do not keep list of sent sockets
Keeping list of all sockets that were sent to child process causes memory
leak and thus unacceptable (see #4587). However `server.close()` should
still work properly.

This commit introduces two options:

* child.send(socket, { track: true }) - will send socket and track its status.
  You should use it when you want to receive `close` event on sent sockets.
* child.send(socket) - will send socket without tracking it status. This
  performs much better, because of smaller number of RTT between master and
  child.

With both of these options `server.close()` will wait for all sent
sockets to get closed.
2013-01-18 03:13:41 +04:00
Fedor Indutny
44cd121c63 Revert "child_process: do not keep list of sent sockets"
This reverts commit db5ee0b3de.
2013-01-18 03:13:10 +04:00
Fedor Indutny
db5ee0b3de child_process: do not keep list of sent sockets
Keeping list of all sockets that were sent to child process causes memory
leak and thus unacceptable (see #4587). However `server.close()` should
still work properly.

This commit introduces two options:

* child.send(socket, { track: true }) - will send socket and track its status.
  You should use it when you want `server.connections` to be a reliable
  number, and receive `close` event on sent sockets.
* child.send(socket) - will send socket without tracking it status. This
  performs much better, because of smaller number of RTT between master and
  child.

With both of these options `server.close()` will wait for all sent
sockets to get closed.
2013-01-17 13:46:31 -08:00
isaacs
b7d76a1a7b Revert "events: Don't crash on events named __proto__"
Unfortunately, it's just too slow to do this in events.js.  Users will
just have to live with not having events named __proto__ or toString.

This reverts commit b48e303af0.
2013-01-17 13:20:22 -08:00
isaacs
1528de2373 stdio: Set readable/writable flags properly
Set the readable/writable flags properly in net streams that have
a handle passed in (such as TTY streams).

Fix #4606
2013-01-17 10:42:44 -08:00
isaacs
b48e303af0 events: Don't crash on events named __proto__
This prefixes all event names internally with 'ev'.
2013-01-17 09:21:45 -08:00
Ben Noordhuis
30e237041d Revert "tls: allow wildcards in common name"
This reverts commit 45024e7b75.

It's making test/simple/test-tls-check-server-identity.js fail:

  AssertionError: Test#4 failed: { host: 'b.a.com',
    cert: { subject: { CN: '*.a.com' } },
    result: false }
      at <omitted>/test/simple/test-tls-check-server-identity.js:201:10
2013-01-17 16:32:00 +01:00
Ben Noordhuis
498200b87c buffer: reject negative SlowBuffer offsets
Reject negative offsets in SlowBuffer::MakeFastBuffer(), it allows
the creation of buffers that point to arbitrary addresses.

Reported by Trevor Norris.
2013-01-17 01:22:11 +01:00
Felix Böhm
7465cf911a module: assert that require() is called with a string
as requested in #4577
2013-01-16 12:25:06 -08:00
isaacs
b9ffc537e6 lint: Prefer double-quotes over single 2013-01-16 12:07:12 -08:00
Ryunosuke SATO
61741f9a83 repl: fix how to module requiring in code comment
This module requiring style is old.
This API has been changed in Node 0.1.16 726865af.
2013-01-16 10:59:22 -08:00
James Campos
c93c99c7c3 assert that require() has a truthy path 2013-01-16 10:49:19 -08:00
isaacs
14e8f806de stream: Properly handle large reads from push-streams
Problem 1: If stream.push() triggers a 'readable' event, and the user
calls `read(n)` with some n > the highWaterMark, then the push() will
return false (indicating that they should not push any more), but no
future 'readable' event is coming (because we're above the
highWaterMark).

Solution: return true from push() when needReadable is set.

Problem 2: A read(n) for n != 0, after the stream had encountered an
EOF, would not trigger the 'end' event if the EOF was pushed in
synchronously by the _read() function.

Solution: Check for ended in stream.read() and schedule an end event if
the length now equals 0.

Fix #4585
2013-01-16 10:45:11 -08:00
Trevor Norris
7393740c7b buffer: improve read/write speed with assert
Improved assert check order of execution and added additional checks on
parameters to ensure no bad values make it through (e.g. negative offset
values).
2013-01-16 10:17:20 -08:00
Trevor Norris
22b84e6216 buffer: floating point read/write improvements
Improvements:
* floating point operations are approx 4x's faster
* Now write quiet NaN's
* all read/write on floating point now done in C, so no more need for
  lib/buffer_ieee754.js
* float values have more accurate min/max value checks
* add additional benchmarks for buffers read/write
* created benchmark/_bench_timer.js which is a simple library that
  can be included into any benchmark and provides an intelligent tracker
  for sync and async tests
* add benchmarks for DataView set methods
* add checks and tests to make sure offset is greater than 0
2013-01-16 10:17:20 -08:00
Alexandr Emelin
eef0ccbcaf http: fix duplicate var initialization
IncomingMessage function contained duplicate initialization
of this._pendings. Line with one of those expressions has been
removed.
2013-01-16 17:10:14 +01:00
Mathias Bynens
bc764f3dff punycode: update to v1.2.0
This update adds support for RFC 3490 separators for improved
compatibility with web browsers.
2013-01-16 16:53:11 +01:00
Fedor Indutny
b4b750b6a5 tls: follow RFC6125 more stricly
* Allow wildcards only in left-most part of hostname identifier.
* Do not match CN if altnames are present
2013-01-14 17:18:30 -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
27fafd4648 stream: Do not call endReadable on a non-empty stream
Say that a stream's current read queue has 101 bytes in it, and the
underlying resource has ended (ie, reached EOF).

If you do something like this:

    stream.read(100); // leave a byte behind
    stream.read(0); // read(0) for some reason

then the read(0) will get 0 from the howMuchToRead function.  Since the
stream was ended, this was incorrectly treating the 0 as a "there is no
more in the buffer", and emitting 'end' before that last byte was read.

Why have the read(0) in the first place?  We do this in some cases to
trigger the last few bytes of a net socket (such as a child process's
stdio pipes).  This was causing issues when piping a `git archive` job
to a file: the resulting tarball was incomplete, because it occasionally
was not getting the last chunk.
2013-01-14 15:22:42 -08:00
Bert Belder
a6b8f63660 buffer: zero-length buffers shouldn't be slab-backed 2013-01-14 22:20:03 +01:00
Bert Belder
e501ce4b21 buffer: zero-length buffers shouldn't be slab-backed 2013-01-14 22:19:22 +01:00
Fedor Indutny
45024e7b75 tls: allow wildcards in common name
see #4592
2013-01-14 21:31:34 +04:00
Fedor Indutny
4dd70bb12c tls: allow wildcards in common name
see #4592
2013-01-14 21:10:03 +04:00
Ben Noordhuis
f3e78bd3c2 http: fix "Cannot call method 'emit' of null"
Fix the following exception:

  http.js:974
    this._httpMessage.emit('close');
                      ^
  TypeError: Cannot call method 'emit' of null
      at Socket.onServerResponseClose (http.js:974:21)
      at Socket.EventEmitter.emit (events.js:124:20)
      at net.js:421:10
      at process._tickCallback (node.js:386:13)
      at process._makeCallback (node.js:304:15)

Fixes #4586.
2013-01-14 17:28:32 +01:00
Nathan Rajlich
bac537b186 repl: fix lint 2013-01-12 12:14:39 -08:00
Felix Böhm
9bce5e8f3e repl: make built-in modules available by default
Closes #3564.
Closes #4578.
2013-01-12 12:10:29 -08:00
isaacs
97db62b4d9 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	Makefile
	src/node_version.h
2013-01-11 10:18:07 -08:00
Bert Belder
6a91eab097 path: make basename and extname ignore trailing slashes
Fixes #4536
2013-01-11 18:50:09 +01:00
Bert Belder
7be27240b5 Revert "path: fix bugs related to paths with trailing slashes"
It only does the right thing on unix, and the implementation
isn't great either.

This reverts commit bb1c03989f.
2013-01-11 16:19:21 +01:00
isaacs
dc0c524ce6 http: Set _dumped=false initially
The better to keep the IncomingMessage class isomorphic and avoid
creating additional hidden classes.
2013-01-10 18:16:43 -08:00
Andreas Madsen
bb1c03989f path: fix bugs related to paths with trailing slashes 2013-01-10 17:58:37 -08:00
isaacs
9ece63b1d7 http: Don't switch the socket into old-mode 2013-01-10 13:50:06 -08:00
isaacs
bc8feb151c http: Use stream.push() instead of touching _readableState 2013-01-10 13:50:06 -08:00
isaacs
840401c024 net: Use readable.push() instead of private methods 2013-01-10 13:50:05 -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
530585b2d1 stream: Use push() for readable.wrap() 2013-01-10 13:49:53 -08:00
isaacs
a993f740f0 stream: Add readable.push(chunk) method 2013-01-10 13:49:53 -08:00
Shigeki Ohtsu
1211946a8c stream: fix typo
Also: Revert "stream: Override addListener as well as on"

This reverts commit 18c985919d.
2013-01-08 23:13:02 -08:00
isaacs
18c985919d stream: Override addListener as well as on
For the compatibility switch.
2013-01-08 14:27:01 -08:00
Fedor Indutny
45941811dc streams: set listener first, emit 'data' later
When switching into compatibility mode by setting `data` event listener,
`_read()` method will be called immediately. If method implementation
invokes callback in the same tick - all emitted `data` events will be
discarded, because `data` listener wasn't set yet.
2013-01-08 22:13:09 +04:00
Shigeki Ohtsu
9b363b022f net: fix bufferSize include writableStream length
socket.bufferSize missed to include the length of internal buffers in
writableStream.
2013-01-08 04:59:50 +01:00
Ben Noordhuis
ad6769fc92 dgram: don't assert on send('string')
Raise a TypeError when the argument to send() or sendto() is anything
but a Buffer.

Fixes the following assertion:

  $ node -e 'require("dgram").createSocket("udp4").send("BAM")'
  node: ../../src/udp_wrap.cc:220: static v8::Handle<v8::Value>
  node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
  `Buffer::HasInstance(args[0])' failed.
  Aborted (core dumped)

Fixes #4496.
2013-01-08 04:32:40 +01:00
isaacs
df3563aa65 child_process: Pull through untouched stdio streams
Otherwise child procs will never emit a 'close' event if you don't
ever consume their streams, because they will never hit the EOF.
2013-01-07 08:36:49 -08:00
isaacs
3e6f737eaf stream: Clean up more effectively in pipe() 2013-01-07 08:36:49 -08:00
Maciej Małecki
a5d4e74891 child_process: don't resume() created socket
Calling `resume()` on a stream switches it to the old mode which causes
piping stdio from a child process to fail.

Fixes joyent/node#4510.
2013-01-07 08:36:49 -08:00
Bradley Meck
70ad9bbcbd child_process: make fork() execPath configurable
Allows for arbitrary path to executable spawned using `fork`. This
fixes some issues around running multiple versions of node with workers
and allows arbitrary IPC with compatible executables.

Fixes #3248.
2013-01-06 22:55:30 +01:00
James Hight
3f76419a04 net: add localAddress and localPort to Socket 2013-01-05 17:05:13 +01:00
Shigeki Ohtsu
2b6c561040 fs: remove unused default option in WriteStream
No bufferSize option is used in stream.Writable and fs.WriteStream.
2013-01-04 19:02:05 +01:00
Shigeki Ohtsu
829f96bada fs: pool size coincide with ReadStream bufferSize
pool size of file reading in ReadableStream can be adjustable
with a bufferSize option.
2013-01-04 19:00:16 +01:00
Nirk Niggler
0459a23063 REPL: fix floating point number parsing
In JS, the expression ".1" is a floating point number.  Issue 4268 concerns the
REPL interpreting floating point numbers that lead with a "." as keywords.  The
original bugfix worked for this specific case but not for the general case:

    var x = [
        .1,
        .2,
        .3
    ];

The attached change and test (`.1+.1` should be `.2`) fix the bug.

Closes #4513.
2013-01-03 17:11:54 -08:00
Ben Noordhuis
aad2013508 repl: allow overriding builtins
Don't give names of built-in libraries special treatment.
Changes the REPL's behavior from this:

  > var path = 42
  > path
  A different "path" already exists globally

To this:

  > var path = 42
  > path
  42

Fixes #4512.
2013-01-03 19:58:47 +01:00
Ben Noordhuis
9e32c2ef3e dgram: fix double implicit bind error
Calling send() on an unbound socket forces an implicit bind to
a random port.

332fea5 made the 'listening' event asynchronous. Unfortunately,
it also introduced a bug where the implicit bind was tried more
than once if send() was called again before the first bind operation
completed.

Address that by keeping track of the bind status and making sure that
bind() is called only once.

Fixes #4499.
2012-12-31 17:53:00 +01:00
isaacs
e11668b244 net: Don't go through Stream API when ondata is used
This speeds up http_simple by around 6%.
2012-12-29 15:32:25 -08:00
isaacs
f423287453 http: Separate out the storeHeader closure 2012-12-29 15:32:25 -08:00
isaacs
ba94f9d6f8 timers: Move list.ontimeout to separate function 2012-12-29 15:32:25 -08:00
isaacs
aec2f733f9 net: Move createWriteReq to separate function 2012-12-29 15:32:25 -08:00
isaacs
9785ab6057 http: Replace "in" usage with "=== undefined"
Speeds up http benchmarks.
2012-12-29 15:32:25 -08:00
lukebayes
ae1b0ca7a5 assert: improve support for new execution contexts
More detailed information in GH-693
2012-12-29 11:19:14 -08:00
isaacs
ec8ebaf300 domain: use camelCase instead of snake_case
While it's true that error objects have a history of getting snake_case
properties attached by the host system, it's a point of confusion to
Node users that comes up a lot.  It's still 'experimental', so best to
change this sooner rather than later.
2012-12-29 10:37:31 -08:00
isaacs
4401bb47bf domain: Do not use uncaughtException handler
This adds a process._fatalException method which is called into from
C++ in order to either emit the 'uncaughtException' method, or emit
'error' on the active domain.

The 'uncaughtException' event is an implementation detail that it would
be nice to deprecate one day, so exposing it as part of the domain
machinery is not ideal.

Fix #4375
2012-12-29 10:37:30 -08:00
Ben Noordhuis
c6e958d44d fs: make 'end' work with ReadStream without 'start'
Make `fs.createReadStream({ end: 42 })` work.

Before this commit, it worked only when used like this:
`fs.createReadStream({ start: 0, end: 42 })` - only when `start` was specified
by the caller.

Fixes #4423.
2012-12-28 18:33:51 +01:00
Ben Noordhuis
910e24b53d fs: remove fs.sendfile()
Said function has been broken (and useless) since v0.6.0. Remove it altogether.

Fixes #3854.
2012-12-28 18:24:35 +01:00
Ryunosuke SATO
c4fc0febfa https: optimize https.createConnection()
Stop using `arguments` for performance and readability.
2012-12-28 16:42:51 +01:00
bentaber
e576208eba net: socket.readyState corrections
socket.readyState, .readable, and .writable behavior changed as
a result of the new streaming interfaces. Updated to be backwards
compatible with current API and adds regression test.

closes #4461
2012-12-27 17:53:28 -08:00
Ryunosuke SATO
fde338bf83 stream: speed up instantiation of readable stream
- Stream.apply -> Stream.call
2012-12-27 17:46:34 -08:00
Ryunosuke SATO
697484df82 domain: speed up domain.create
Use `EventEmitter.call` instead of `EventEmitter.apply` because of performance.
2012-12-27 17:45:36 -08:00
Ryunosuke SATO
8936868e9b http: remove unused variable
The module variable `END_OF_FILE` was no longer needed from 1d369317.
2012-12-27 15:09:04 -08:00
isaacs
d76eacd4e6 http: Handle end only when stream is not dumped
This fixes regression introduced in some cases by 8bf0c15
2012-12-26 15:57:49 -08:00
isaacs
54740c8b24 lint 2012-12-26 15:26:53 -08:00
Ryunosuke SATO
0db521d0b0 repl: remove 'repl' from automatic loading libs
In repl, calling `repl` twice shows the following message:
```
> repl
A different "repl" already exists globally
```
2012-12-26 15:25:00 -08:00
Ryunosuke SATO
31cffae2ba repl: add 'domain' to automatic loading libs
`domain` should be a member of automatic loading libs in `repl`.

Conflicts:

	lib/repl.js
2012-12-26 15:23:31 -08:00
Shigeki Ohtsu
8bf0c15a5b stream2: fix to emit end event on http.ClientResponse 2012-12-26 15:20:48 -08:00
Andreas Madsen
d68ee22dda stream: do only fake drain when unpiped stream is the source
If the destination had multiply read streams piped to it,
they would all decrease the awaitDrain state and thereby
start the flow
2012-12-26 14:56:02 -08:00
Andreas Madsen
5daa701aba stream: fix event handler leak in readstream pipe and unpipe
After a stream was unpiped there would stil be residual event handlers
2012-12-26 14:56:02 -08:00
Ryunosuke SATO
27a91387ae util: fix deprecation message in util.pump 2012-12-26 14:54:56 -08:00
Ben Taber
526d852565 net: allow socket end before connect
Fix a bug where calling .end() on a socket without calling .connect() first
throws a TypeError:

  TypeError: Cannot read property 'shutdown' of undefined
      at Socket.onSocketFinish (net.js:194:20)
      at Socket.EventEmitter.emit (events.js:91:17)
      at Socket.Writable.end (_stream_writable.js:281:10)
      at Socket.end (net.js:352:31)

Fixes #4463.
2012-12-25 22:18:56 +01:00
Nathan Rajlich
837df70b75 repl: don't touch require.cache
Fixes #3226.

Consider a production server that uses a REPL to debug. Creating the instance
would wipe out the global cache of modules, and subsequent "require" calls in
the server would be reloaded from disk. The REPL should observe only, without
altering, its environment.
2012-12-21 11:42:40 -08:00
isaacs
244924823e stdio: Do not read from stdout/err
This fixes windows stdio pipes in streams2 land.
2012-12-21 11:05:46 -08:00
isaacs
fb915ed957 lint 2012-12-21 16:51:43 +00:00
isaacs
c048c814c7 http: Trivial fix for comments and 'this.read' 2012-12-21 16:48:32 +00:00
isaacs
f9caf7020c streams: Speed up by doing less work in the state ctors 2012-12-21 00:07:34 +00:00