Commit c60d8b6e authored by Jérémy Lal's avatar Jérémy Lal

Imported Upstream version 0.4.7

parent f52f9d81
......@@ -170,4 +170,6 @@ Arnout Kazemier <info@3rd-Eden.com>
George Stagas <gstagas@gmail.com>
Scott McWhirter <scott.mcwhirter@joyent.com>
Jakub Lekstan <jakub.lekstan@dreamlab.pl>
Tim Baumann <tim@timbaumann.info>
Robert Mustacchi <rm@joyent.com>
2011.04.22, Version 0.4.7 (stable)
* Don't emit error on ECONNRESET from read() #670
* Fix: Multiple pipes to the same stream were broken #929
(Felix Geisendörfer)
* URL parsing/formatting corrections #954 (isaacs)
* make it possible to do repl.start('', stream) (Wade Simmons)
* Add os.loadavg for SunOS (Robert Mustacchi)
* Fix timeouts with floating point numbers #897
* Improve docs.
2011.04.13, Version 0.4.6 (stable)
* Don't error on ENOTCONN from shutdown() #670
......
......@@ -2,6 +2,7 @@
* [Synopsis](synopsis.html)
* [Globals](globals.html)
* [STDIO](stdio.html)
* [Timers](timers.html)
* [Modules](modules.html)
* [C/C++ Addons](addons.html)
......
@include synopsis
@include globals
@include stdio
@include timers
@include modules
@include addons
......
......@@ -18,7 +18,7 @@
</header>
<h2 id="table_of_Contents">Table of Contents</h2>
<ul><li><a href="synopsis.html">Synopsis</a></li><li><a href="globals.html">Globals</a></li><li><a href="timers.html">Timers</a></li><li><a href="modules.html">Modules</a></li><li><a href="addons.html">C/C++ Addons</a></li><li><a href="process.html">Process</a></li><li><a href="util.html">Utilities</a></li><li><a href="events.html">Events</a></li><li><a href="buffers.html">Buffers</a></li><li><a href="streams.html">Streams</a></li><li><a href="crypto.html">Crypto</a></li><li><a href="tls.html">TLS/SSL</a></li><li><a href="string_decoder.html">String Decoder</a></li><li><a href="fs.html">File System</a></li><li><a href="path.html">Path</a></li><li><a href="net.html">Net</a></li><li><a href="dgram.html">UDP/Datagram</a></li><li><a href="dns.html">DNS</a></li><li><a href="http.html">HTTP</a></li><li><a href="https.html">HTTPS</a></li><li><a href="url.html">URL</a></li><li><a href="querystring.html">Query Strings</a></li><li><a href="readline.html">Readline</a></li><li><a href="repl.html">REPL</a></li><li><a href="vm.html">VM</a></li><li><a href="child_processes.html">Child Processes</a></li><li><a href="assert.html">Assertion Testing</a></li><li><a href="tty.html">TTY</a></li><li><a href="os.html">OS</a></li><li><a href="debugger.html">Debugger</a></li><li>Appendixes<ul><li><a href="appendix_1.html">Appendix 1: Recommended Third-party Modules</a></li><li><a href="appendix_2.html">Appendix 2: Deprecated API's</a></li></ul></li></ul>
<ul><li><a href="synopsis.html">Synopsis</a></li><li><a href="globals.html">Globals</a></li><li><a href="stdio.html">STDIO</a></li><li><a href="timers.html">Timers</a></li><li><a href="modules.html">Modules</a></li><li><a href="addons.html">C/C++ Addons</a></li><li><a href="process.html">Process</a></li><li><a href="util.html">Utilities</a></li><li><a href="events.html">Events</a></li><li><a href="buffers.html">Buffers</a></li><li><a href="streams.html">Streams</a></li><li><a href="crypto.html">Crypto</a></li><li><a href="tls.html">TLS/SSL</a></li><li><a href="string_decoder.html">String Decoder</a></li><li><a href="fs.html">File System</a></li><li><a href="path.html">Path</a></li><li><a href="net.html">Net</a></li><li><a href="dgram.html">UDP/Datagram</a></li><li><a href="dns.html">DNS</a></li><li><a href="http.html">HTTP</a></li><li><a href="https.html">HTTPS</a></li><li><a href="url.html">URL</a></li><li><a href="querystring.html">Query Strings</a></li><li><a href="readline.html">Readline</a></li><li><a href="repl.html">REPL</a></li><li><a href="vm.html">VM</a></li><li><a href="child_processes.html">Child Processes</a></li><li><a href="assert.html">Assertion Testing</a></li><li><a href="tty.html">TTY</a></li><li><a href="os.html">OS</a></li><li><a href="debugger.html">Debugger</a></li><li>Appendixes<ul><li><a href="appendix_1.html">Appendix 1: Recommended Third-party Modules</a></li><li><a href="appendix_2.html">Appendix 2: Deprecated API's</a></li></ul></li></ul>
</div>
<script type="text/javascript" src="assets/sh_main.js"></script>
<script type="text/javascript" src="assets/sh_javascript.min.js"></script>
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
</div>
<hr />
</header>
<div id="toc"><h2>Table Of Contents</h2><ul><li><a href="#global_Objects">Global Objects</a><ul><li><a href="#global">global</a></li><li><a href="#process">process</a></li><li><a href="#require">require()</a></li><li><a href="#require.resolve">require.resolve()</a></li><li><a href="#require.paths">require.paths</a></li><li><a href="#__filename">__filename</a></li><li><a href="#__dirname">__dirname</a></li><li><a href="#module">module</a></li><li><a href="#setTimeout">setTimeout(cb, ms)</a></li><li><a href="#clearTimeout">clearTimeout(t)</a></li><li><a href="#setInterval">setInterval(cb, ms)</a></li><li><a href="#clearInterval">clearInterval(t)</a></li></ul></li></ul><hr /></div>
<div id="toc"><h2>Table Of Contents</h2><ul><li><a href="#global_Objects">Global Objects</a><ul><li><a href="#global">global</a></li><li><a href="#process">process</a></li><li><a href="#console">console</a></li><li><a href="#require">require()</a></li><li><a href="#require.resolve">require.resolve()</a></li><li><a href="#require.paths">require.paths</a></li><li><a href="#__filename">__filename</a></li><li><a href="#__dirname">__dirname</a></li><li><a href="#module">module</a></li><li><a href="#setTimeout">setTimeout(cb, ms)</a></li><li><a href="#clearTimeout">clearTimeout(t)</a></li><li><a href="#setInterval">setInterval(cb, ms)</a></li><li><a href="#clearInterval">clearInterval(t)</a></li></ul></li></ul><hr /></div>
<h2 id="global_Objects">Global Objects</h2>
<p>These object are available in all modules. Some of these objects aren't
......@@ -35,6 +35,10 @@ scope; <code>var something</code> inside a Node module will be local to that mod
<p>The process object. See the <a href="process.html#process">process object</a> section.</p>
<h3 id="console">console</h3>
<p>Used to print to stdout and stderr. See the <a href="stdio.html">stdio</a> section.</p>
<h3 id="require">require()</h3>
<p>To require modules. See the <a href="modules.html#modules">Modules</a> section.
......@@ -81,7 +85,8 @@ the same filename passed in as a command line argument.</p>
<p>A reference to the current module. In particular
<code>module.exports</code> is the same as the <code>exports</code> object. See <code>src/node.js</code>
for more information.</p>
for more information.
<code>module</code> isn't actually a global but rather local to each module.</p>
<h3 id="setTimeout">setTimeout(cb, ms)</h3>
......@@ -92,8 +97,6 @@ for more information.</p>
<h3 id="clearInterval">clearInterval(t)</h3>
<p>The timer functions are global variables. See the <a href="timers.html">timers</a> section.</p>
<p><code>module</code> isn't actually a global but rather local to each module.</p>
</div>
<script type="text/javascript" src="assets/sh_main.js"></script>
<script type="text/javascript" src="assets/sh_javascript.min.js"></script>
......
......@@ -262,6 +262,11 @@ be called before <code>response.end()</code> is called.</p>
<p>If you call <code>response.write()</code> or <code>response.end()</code> before calling this, the
implicit/mutable headers will be calculated and call this function for you.</p>
<p>Note: that Content-Length is given in bytes not characters. The above example
works because the string <code>'hello world'</code> contains only single byte characters.
If the body contains higher coded characters then <code>Buffer.byteLength()</code>
should be used to determine the number of bytes in a given encoding.</p>
<h3 id="response.statusCode">response.statusCode</h3>
<p>When using implicit headers (not calling <code>response.writeHead()</code> explicitly), this property
......
......@@ -18,7 +18,7 @@
</header>
<h2 id="table_of_Contents">Table of Contents</h2>
<ul><li><a href="synopsis.html">Synopsis</a></li><li><a href="globals.html">Globals</a></li><li><a href="timers.html">Timers</a></li><li><a href="modules.html">Modules</a></li><li><a href="addons.html">C/C++ Addons</a></li><li><a href="process.html">Process</a></li><li><a href="util.html">Utilities</a></li><li><a href="events.html">Events</a></li><li><a href="buffers.html">Buffers</a></li><li><a href="streams.html">Streams</a></li><li><a href="crypto.html">Crypto</a></li><li><a href="tls.html">TLS/SSL</a></li><li><a href="string_decoder.html">String Decoder</a></li><li><a href="fs.html">File System</a></li><li><a href="path.html">Path</a></li><li><a href="net.html">Net</a></li><li><a href="dgram.html">UDP/Datagram</a></li><li><a href="dns.html">DNS</a></li><li><a href="http.html">HTTP</a></li><li><a href="https.html">HTTPS</a></li><li><a href="url.html">URL</a></li><li><a href="querystring.html">Query Strings</a></li><li><a href="readline.html">Readline</a></li><li><a href="repl.html">REPL</a></li><li><a href="vm.html">VM</a></li><li><a href="child_processes.html">Child Processes</a></li><li><a href="assert.html">Assertion Testing</a></li><li><a href="tty.html">TTY</a></li><li><a href="os.html">OS</a></li><li><a href="debugger.html">Debugger</a></li><li>Appendixes<ul><li><a href="appendix_1.html">Appendix 1: Recommended Third-party Modules</a></li><li><a href="appendix_2.html">Appendix 2: Deprecated API's</a></li></ul></li></ul>
<ul><li><a href="synopsis.html">Synopsis</a></li><li><a href="globals.html">Globals</a></li><li><a href="stdio.html">STDIO</a></li><li><a href="timers.html">Timers</a></li><li><a href="modules.html">Modules</a></li><li><a href="addons.html">C/C++ Addons</a></li><li><a href="process.html">Process</a></li><li><a href="util.html">Utilities</a></li><li><a href="events.html">Events</a></li><li><a href="buffers.html">Buffers</a></li><li><a href="streams.html">Streams</a></li><li><a href="crypto.html">Crypto</a></li><li><a href="tls.html">TLS/SSL</a></li><li><a href="string_decoder.html">String Decoder</a></li><li><a href="fs.html">File System</a></li><li><a href="path.html">Path</a></li><li><a href="net.html">Net</a></li><li><a href="dgram.html">UDP/Datagram</a></li><li><a href="dns.html">DNS</a></li><li><a href="http.html">HTTP</a></li><li><a href="https.html">HTTPS</a></li><li><a href="url.html">URL</a></li><li><a href="querystring.html">Query Strings</a></li><li><a href="readline.html">Readline</a></li><li><a href="repl.html">REPL</a></li><li><a href="vm.html">VM</a></li><li><a href="child_processes.html">Child Processes</a></li><li><a href="assert.html">Assertion Testing</a></li><li><a href="tty.html">TTY</a></li><li><a href="os.html">OS</a></li><li><a href="debugger.html">Debugger</a></li><li>Appendixes<ul><li><a href="appendix_1.html">Appendix 1: Recommended Third-party Modules</a></li><li><a href="appendix_2.html">Appendix 2: Deprecated API's</a></li></ul></li></ul>
</div>
<script type="text/javascript" src="assets/sh_main.js"></script>
<script type="text/javascript" src="assets/sh_javascript.min.js"></script>
......
<!DOCTYPE html>
<html>
<head>
<title>stdio - Node.js Manual &amp; Documentation</title>
<link type="image/x-icon" rel="icon" href="/favicon.ico" />
<link type="image/x-icon" rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="assets/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="assets/sh.css" type="text/css" media="all"/>
</head>
<body>
<div id="container">
<header>
<h1>Node.js Manual &amp; Documentation</h1>
<div id="gtoc">
<p><a href="index.html">Index</a> | <a href="all.html">View on single page</a></p>
</div>
<hr />
</header>
<div id="toc"><h2>Table Of Contents</h2><ul><li><a href="#console">console</a><ul><li><a href="#console.log">console.log()</a></li><li><a href="#console.info">console.info()</a></li><li><a href="#console.warn">console.warn()</a></li><li><a href="#console.error">console.error()</a></li><li><a href="#console.dir">console.dir(obj)</a></li><li><a href="#console.time">console.time(label)</a></li><li><a href="#console.timeEnd">console.timeEnd(label)</a></li><li><a href="#console.trace">console.trace()</a></li><li><a href="#console.assert">console.assert()</a></li></ul></li></ul><hr /></div>
<h2 id="console">console</h2>
<p>Browser-like object for printing to stdout and stderr.</p>
<h3 id="console.log">console.log()</h3>
<p>Prints to stdout with newline. This function can take multiple arguments in a
<code>printf()</code>-like way. Example:</p>
<pre><code>console.log('count: %d', count);</code></pre>
<p>If formating elements are not found in the first string then <code>util.inspect</code>
is used on each argument.</p>
<h3 id="console.info">console.info()</h3>
<p>Same as <code>console.log</code>.</p>
<h3 id="console.warn">console.warn()</h3>
<h3 id="console.error">console.error()</h3>
<p>Same as <code>console.log</code> but prints to stderr.</p>
<h3 id="console.dir">console.dir(obj)</h3>
<p>Uses <code>util.inspect</code> on <code>obj</code> and prints resulting string to stderr.</p>
<h3 id="console.time">console.time(label)</h3>
<p>Mark a time.</p>
<h3 id="console.timeEnd">console.timeEnd(label)</h3>
<p>Finish timer, record output. Example</p>
<pre><code>console.time('100-elements');
while (var i = 0; i &lt; 100; i++) {
;
}
console.timeEnd('100-elements');</code></pre>
<h3 id="console.trace">console.trace()</h3>
<p>Print a stack trace to stderr of the current position.</p>
<h3 id="console.assert">console.assert()</h3>
<p>Same as <code>assert.ok()</code>.</p>
</div>
<script type="text/javascript" src="assets/sh_main.js"></script>
<script type="text/javascript" src="assets/sh_javascript.min.js"></script>
<script type="text/javascript">highlight(undefined, undefined, 'pre');</script>
</body>
</html>
\ No newline at end of file
......@@ -16,6 +16,11 @@ scope; `var something` inside a Node module will be local to that module.
The process object. See the [process object](process.html#process) section.
### console
Used to print to stdout and stderr. See the [stdio](stdio.html) section.
### require()
To require modules. See the [Modules](modules.html#modules) section.
......@@ -66,6 +71,7 @@ Example: running `node example.js` from `/Users/mjr`
A reference to the current module. In particular
`module.exports` is the same as the `exports` object. See `src/node.js`
for more information.
`module` isn't actually a global but rather local to each module.
### setTimeout(cb, ms)
### clearTimeout(t)
......@@ -73,5 +79,3 @@ for more information.
### clearInterval(t)
The timer functions are global variables. See the [timers](timers.html) section.
`module` isn't actually a global but rather local to each module.
......@@ -259,6 +259,11 @@ be called before `response.end()` is called.
If you call `response.write()` or `response.end()` before calling this, the
implicit/mutable headers will be calculated and call this function for you.
Note: that Content-Length is given in bytes not characters. The above example
works because the string `'hello world'` contains only single byte characters.
If the body contains higher coded characters then `Buffer.byteLength()`
should be used to determine the number of bytes in a given encoding.
### response.statusCode
When using implicit headers (not calling `response.writeHead()` explicitly), this property
......
## console
Browser-like object for printing to stdout and stderr.
### console.log()
Prints to stdout with newline. This function can take multiple arguments in a
`printf()`-like way. Example:
console.log('count: %d', count);
If formating elements are not found in the first string then `util.inspect`
is used on each argument.
### console.info()
Same as `console.log`.
### console.warn()
### console.error()
Same as `console.log` but prints to stderr.
### console.dir(obj)
Uses `util.inspect` on `obj` and prints resulting string to stderr.
### console.time(label)
Mark a time.
### console.timeEnd(label)
Finish timer, record output. Example
console.time('100-elements');
while (var i = 0; i < 100; i++) {
;
}
console.timeEnd('100-elements');
### console.trace()
Print a stack trace to stderr of the current position.
### console.assert()
Same as `assert.ok()`.
......@@ -26,13 +26,12 @@
<li><a href="#download">Download</a></li>
<li><a href="https://github.com/joyent/node/raw/master/ChangeLog">ChangeLog</a></li>
<li><a href="#about">About</a></li>
<li><a href="http://nodejs.org/docs/v0.4.6/api">v0.4.6 docs</a></li>
<br/>
<li><B><a href="https://github.com/joyent/node/wiki">Wiki</a></B></li>
<li><B><a href="http://blog.nodejs.org/">Blog</a></B></li>
<br/>
<li><B><a href="http://jobs.nodejs.org/">Jobs</a></B></li>
<li><a href="http://nodejs.org/docs/v0.4.7/api">v0.4.7 docs</a></li>
<br/>
<li><a href="https://github.com/joyent/node/wiki">Wiki</a></li>
<li><a href="http://blog.nodejs.org/">Blog</a></li>
<li><a href="http://jobs.nodejs.org/">Jobs</a></li>
<li><a href="https://github.com/joyent/node/wiki/Community">Community</a></li>
<li><a href="http://chat.nodejs.org/">Demo</a></li>
</ol>
</div>
......@@ -56,8 +55,8 @@ var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
</pre>
<p>
......@@ -67,10 +66,10 @@ console.log('Server running at http://127.0.0.1:8124/');
</p>
<pre class="sh_none">
% node example.js
Server running at http://127.0.0.1:8124/</pre>
Server running at http://127.0.0.1:1337/</pre>
<p>
Here is an example of a simple TCP server which listens on port 8124
Here is an example of a simple TCP server which listens on port 1337
and echoes whatever you send it:
</p>
......@@ -80,9 +79,9 @@ var net = require('net');
var server = net.createServer(function (socket) {
socket.write("Echo server\r\n");
socket.pipe(socket);
})
});
server.listen(8124, "127.0.0.1");
server.listen(1337, "127.0.0.1");
</pre>
<p>
......@@ -108,9 +107,9 @@ server.listen(8124, "127.0.0.1");
</p>
<p>
2011.04.13
<a href="http://nodejs.org/dist/node-v0.4.6.tar.gz">node-v0.4.6.tar.gz</a>
(<a href="http://nodejs.org/docs/v0.4.6/api/index.html">Documentation</a>)
2011.04.22
<a href="http://nodejs.org/dist/node-v0.4.7.tar.gz">node-v0.4.7.tar.gz</a>
(<a href="http://nodejs.org/docs/v0.4.7/api/index.html">Documentation</a>)
</p>
<p>Historical: <a href="http://nodejs.org/dist">versions</a>, <a href="http://nodejs.org/docs">docs</a></p>
......
......@@ -635,7 +635,11 @@ Socket.prototype._onReadable = function() {
pool.length - pool.used);
DTRACE_NET_SOCKET_READ(this, bytesRead);
} catch (e) {
self.destroy(e);
if (e.code == 'ECONNRESET') {
self.destroy();
} else {
self.destroy(e);
}
return;
}
......
......@@ -93,7 +93,7 @@ function REPLServer(prompt, stream) {
process.stdin.resume();
}
self.prompt = prompt || '> ';
self.prompt = (prompt != undefined ? prompt : '> ');
function complete(text) {
return self.complete(text);
......@@ -105,7 +105,7 @@ function REPLServer(prompt, stream) {
this.commands = {};
defineDefaultCommands(this);
if (rli.enabled && !disableColors) {
if (rli.enabled && !disableColors && exports.writer === util.inspect) {
// Turn on ANSI coloring.
exports.writer = function(obj, showHidden, depth) {
return util.inspect(obj, showHidden, depth, true);
......
......@@ -28,9 +28,13 @@ function Stream() {
util.inherits(Stream, events.EventEmitter);
exports.Stream = Stream;
var pipes = [];
Stream.prototype.pipe = function(dest, options) {
var source = this;
pipes.push(dest);
function ondata(chunk) {
if (dest.writable) {
if (false === dest.write(chunk)) source.pause();
......@@ -52,10 +56,18 @@ Stream.prototype.pipe = function(dest, options) {
if (!options || options.end !== false) {
function onend() {
var index = pipes.indexOf(dest);
pipes.splice(index, 1);
if (pipes.indexOf(dest) > -1) {
return;
}
dest.end();
}
source.on('end', onend);
source.on('close', onend);
}
/*
......@@ -73,34 +85,35 @@ Stream.prototype.pipe = function(dest, options) {
source.emit('resume');
};
}
var onpause = function() {
source.pause();
}
dest.on('pause', onpause);
var onresume = function() {
if (source.readable) source.resume();
};
dest.on('resume', onresume);
var cleanup = function () {
source.removeListener('data', ondata);
dest.removeListener('drain', ondrain);
source.removeListener('end', onend);
source.removeListener('close', onend);
dest.removeListener('pause', onpause);
dest.removeListener('resume', onresume);
source.removeListener('end', cleanup);
source.removeListener('close', cleanup);
dest.removeListener('end', cleanup);
dest.removeListener('close', cleanup);
}
source.on('end', cleanup);
source.on('close', cleanup);
......
......@@ -24,25 +24,40 @@ exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
// Reference: RFC 3986, RFC 1808, RFC 2396
// define these here so at least they only have to be
// compiled once on the first module load.
var protocolPattern = /^([a-z0-9]+:)/,
var protocolPattern = /^([a-z0-9]+:)/i,
portPattern = /:[0-9]+$/,
delims = ['<', '>', '"', '\'', '`', /\s/],
// RFC 2396: characters reserved for delimiting URLs.
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
// RFC 2396: characters not allowed for various reasons.
unwise = ['{', '}', '|', '\\', '^', '~', '[', ']', '`'].concat(delims),
nonHostChars = ['/', '?', ';', '#'].concat(unwise),
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
autoEscape = ['\''],
// Characters that are never ever allowed in a hostname.
// Note that any invalid chars are also handled, but these
// are the ones that are *expected* to be seen, so we fast-path
// them.
nonHostChars = ['%', '/', '?', ';', '#']
.concat(unwise).concat(autoEscape),
hostnameMaxLen = 255,
hostnamePartPattern = /^[a-z0-9][a-z0-9A-Z-]{0,62}$/,
hostnamePartPattern = /^[a-zA-Z0-9][a-z0-9A-Z-]{0,62}$/,
hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z-]{0,62})(.*)$/,
// protocols that can allow "unsafe" and "unwise" chars.
unsafeProtocol = {
'javascript': true,
'javascript:': true
},
// protocols that never have a hostname.
hostlessProtocol = {
'javascript': true,
'javascript:': true,
'file': true,
'file:': true
},
// protocols that always have a path component.
pathedProtocol = {
'http': true,
'https': true,
......@@ -54,6 +69,7 @@ var protocolPattern = /^([a-z0-9]+:)/,
'gopher:': true,
'file:': true
},
// protocols that always contain a // bit.
slashedProtocol = {
'http': true,
'https': true,
......@@ -74,10 +90,19 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
var out = {},
rest = url;
// cut off any delimiters.
// This is to support parse stuff like "<http://foo.com>"
for (var i = 0, l = rest.length; i < l; i++) {
if (delims.indexOf(rest.charAt(i)) === -1) break;
}
if (i !== 0) rest = rest.substr(i);
var proto = protocolPattern.exec(rest);
if (proto) {
proto = proto[0];
out.protocol = proto;
var lowerProto = proto.toLowerCase();
out.protocol = lowerProto;
rest = rest.substr(proto.length);
}
......@@ -119,6 +144,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
var key = keys[i];
out[key] = p[key];
}
// we've indicated that there is a hostname,
// so even if it's empty, it has to be present.
out.hostname = out.hostname || '';
......@@ -130,17 +156,49 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
var hostparts = out.hostname.split(/\./);
for (var i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i];
if (!part) continue;
if (!part.match(hostnamePartPattern)) {
out.hostname = '';
var validParts = hostparts.slice(0, i);
var notHost = hostparts.slice(i + 1);
var bit = part.match(hostnamePartStart);
if (bit) {
validParts.push(bit[1]);
notHost.unshift(bit[2]);
}
if (notHost.length) {
rest = '/' + notHost.join('.') + rest
}
out.hostname = validParts.join('.');
break;
}
}
}
// hostnames are always lower case.
out.hostname = out.hostname.toLowerCase();
out.host = ((out.auth) ? out.auth + '@' : '') +
(out.hostname || '') +
((out.port) ? ':' + out.port : '');
out.href += out.host;
}
// now rest is set to the post-host stuff.
// chop off any delim chars.
if (!unsafeProtocol[proto]) {
if (!unsafeProtocol[lowerProto]) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
for (var i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i];
var esc = encodeURIComponent(ae);
if (esc === ae) {
esc = escape(ae);
}
rest = rest.split(ae).join(esc);
}
// Now make sure that delims never appear in a url.
var chop = rest.length;
for (var i = 0, l = delims.length; i < l; i++) {
var c = rest.indexOf(delims[i]);
......
......@@ -43,7 +43,7 @@ int Start (int argc, char *argv[]);
/* Converts a unixtime to V8 Date */
#define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
#define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->IntegerValue())/1000.0);
#define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->NumberValue())/1000.0);
#define NODE_DEFINE_CONSTANT(target, constant) \
(target)->Set(v8::String::NewSymbol(#constant), \
......
......@@ -27,7 +27,7 @@
#define NODE_MAJOR_VERSION 0
#define NODE_MINOR_VERSION 4
#define NODE_PATCH_VERSION 6
#define NODE_PATCH_VERSION 7
#define NODE_VERSION_IS_RELEASE 1
#ifndef NODE_STRINGIFY
......
......@@ -31,6 +31,7 @@
#include <errno.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/loadavg.h>
#if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
#define PROCFS_FILE_OFFSET_BITS_HACK 1
......@@ -249,6 +250,14 @@ double Platform::GetUptime() {
}
int Platform::GetLoadAvg(Local<Array> *loads) {
HandleScope scope;
double loadavg[3];
(void) getloadavg(loadavg, 3);
(*loads)->Set(0, Number::New(loadavg[LOADAVG_1MIN]));
(*loads)->Set(1, Number::New(loadavg[LOADAVG_5MIN]));
(*loads)->Set(2, Number::New(loadavg[LOADAVG_15MIN]));
return 0;
}
......
var common = require('../common');
var assert = require('assert');
var t = Date.now();
var diff;
setTimeout(function () {
diff = Date.now() - t;
console.error(diff);
}, 0.1);
process.on('exit', function() {
assert.ok(diff < 10);
});
......@@ -28,10 +28,13 @@ var util = require('util');
function Writable () {
this.writable = true;
this.endCalls = 0;
stream.Stream.call(this);
}
util.inherits(Writable, stream.Stream);
Writable.prototype.end = function () {}
Writable.prototype.end = function () {
this.endCalls++;
}
function Readable () {
this.readable = true;
......@@ -56,6 +59,9 @@ for (i = 0; i < limit; i++) {
r.emit('end')
}
assert.equal(0, r.listeners('end').length);
assert.equal(limit, w.endCalls);
w.endCalls = 0;
for (i = 0; i < limit; i++) {
r = new Readable()
......@@ -63,6 +69,19 @@ for (i = 0; i < limit; i++) {
r.emit('close')
}
assert.equal(0, r.listeners('close').length);
assert.equal(limit, w.endCalls);
w.endCalls = 0;
var r2;
r = new Readable()
r2 = new Readable();
r.pipe(w)
r2.pipe(w)
r.emit('close')
r2.emit('close')
assert.equal(1, w.endCalls);
r = new Readable();
......
......@@ -32,6 +32,99 @@ var parseTests = {
'href': '//some_path',
'pathname': '//some_path'
},
'HTTP://www.example.com/' : {
'href': 'http://www.example.com/',
'protocol': 'http:',
'host': 'www.example.com',
'hostname': 'www.example.com',
'pathname': '/'
},
'http://www.ExAmPlE.com/' : {
'href': 'http://www.example.com/',
'protocol': 'http:',
'host': 'www.example.com',
'hostname': 'www.example.com',
'pathname': '/'
},
'http://user:pw@www.ExAmPlE.com/' : {
'href': 'http://user:pw@www.example.com/',
'protocol': 'http:',
'auth': 'user:pw',
'host': 'user:pw@www.example.com',
'hostname': 'www.example.com',
'pathname': '/'
},
'http://USER:PW@www.ExAmPlE.com/' : {
'href': 'http://USER:PW@www.example.com/',
'protocol': 'http:',
'auth': '