summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-08-21 09:40:10 -0700
committerisaacs <i@izs.me>2013-08-21 09:40:10 -0700
commitcdf2a661f2e89cbf1bebd553f32f0afb570fd936 (patch)
tree86346c1348fa1eca7c7c2b226c45aae3862556cb
parenta1b3273a9d47af9a42aabbebee83d102668e1732 (diff)
parent8d42c6344b7a96dbb42dd65e01617028d05d413a (diff)
downloadnode-cdf2a661f2e89cbf1bebd553f32f0afb570fd936.tar.gz
Merge remote-tracking branch 'ry/v0.10'
Conflicts: lib/tls.js
-rw-r--r--deps/http_parser/http_parser.c21
-rw-r--r--deps/http_parser/test.c18
-rw-r--r--doc/api/dgram.markdown23
-rw-r--r--doc/api/process.markdown22
-rw-r--r--doc/api/stream.markdown6
-rw-r--r--lib/_tls_legacy.js9
-rw-r--r--lib/fs.js2
-rw-r--r--test/simple/test-fs-read-stream.js26
8 files changed, 98 insertions, 29 deletions
diff --git a/deps/http_parser/http_parser.c b/deps/http_parser/http_parser.c
index 5e0a950a6..55d771622 100644
--- a/deps/http_parser/http_parser.c
+++ b/deps/http_parser/http_parser.c
@@ -936,6 +936,7 @@ size_t http_parser_execute (http_parser *parser,
} else if (parser->index == 2 && ch == 'P') {
parser->method = HTTP_COPY;
} else {
+ SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->method == HTTP_MKCOL) {
@@ -948,12 +949,14 @@ size_t http_parser_execute (http_parser *parser,
} else if (parser->index == 2 && ch == 'A') {
parser->method = HTTP_MKACTIVITY;
} else {
+ SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->method == HTTP_SUBSCRIBE) {
if (parser->index == 1 && ch == 'E') {
parser->method = HTTP_SEARCH;
} else {
+ SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->index == 1 && parser->method == HTTP_POST) {
@@ -964,13 +967,27 @@ size_t http_parser_execute (http_parser *parser,
} else if (ch == 'A') {
parser->method = HTTP_PATCH;
} else {
+ SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->index == 2) {
if (parser->method == HTTP_PUT) {
- if (ch == 'R') parser->method = HTTP_PURGE;
+ if (ch == 'R') {
+ parser->method = HTTP_PURGE;
+ } else {
+ SET_ERRNO(HPE_INVALID_METHOD);
+ goto error;
+ }
} else if (parser->method == HTTP_UNLOCK) {
- if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE;
+ if (ch == 'S') {
+ parser->method = HTTP_UNSUBSCRIBE;
+ } else {
+ SET_ERRNO(HPE_INVALID_METHOD);
+ goto error;
+ }
+ } else {
+ SET_ERRNO(HPE_INVALID_METHOD);
+ goto error;
}
} else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
parser->method = HTTP_PROPPATCH;
diff --git a/deps/http_parser/test.c b/deps/http_parser/test.c
index 81e0c3bdd..46d817bb3 100644
--- a/deps/http_parser/test.c
+++ b/deps/http_parser/test.c
@@ -3117,14 +3117,8 @@ main (void)
/// REQUESTS
- test_simple("hello world", HPE_INVALID_METHOD);
test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
-
- test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
- test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
- test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
-
// Well-formed but incomplete
test_simple("GET / HTTP/1.1\r\n"
"Content-Type: text/plain\r\n"
@@ -3167,13 +3161,23 @@ main (void)
}
static const char *bad_methods[] = {
+ "ASDF",
"C******",
+ "COLA",
+ "GEM",
+ "GETA",
"M****",
+ "MKCOLA",
+ "PROPPATCHA",
+ "PUN",
+ "PX",
+ "SA",
+ "hello world",
0 };
for (this_method = bad_methods; *this_method; this_method++) {
char buf[200];
sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
- test_simple(buf, HPE_UNKNOWN);
+ test_simple(buf, HPE_INVALID_METHOD);
}
const char *dumbfuck2 =
diff --git a/doc/api/dgram.markdown b/doc/api/dgram.markdown
index 92c8bc955..922cdfc54 100644
--- a/doc/api/dgram.markdown
+++ b/doc/api/dgram.markdown
@@ -132,13 +132,21 @@ informing the source that the data did not reach its intended recipient).
* `port` Integer
* `address` String, Optional
-* `callback` Function, Optional
+* `callback` Function with no parameters, Optional. Callback when
+ binding is done.
-For UDP sockets, listen for datagrams on a named `port` and optional `address`.
-If `address` is not specified, the OS will try to listen on all addresses.
+For UDP sockets, listen for datagrams on a named `port` and optional
+`address`. If `address` is not specified, the OS will try to listen on
+all addresses. After binding is done, a "listening" event is emitted
+and the `callback`(if specified) is called. Specifying both a
+"listening" event listener and `callback` is not harmful but not very
+useful.
-The `callback` argument, if provided, is added as a one-shot `'listening'`
-event listener.
+A bound datagram socket keeps the node process running to receive
+datagrams.
+
+If binding fails, an "error" event is generated. In rare case (e.g.
+binding a closed socket), an `Error` may be thrown by this method.
Example of a UDP server listening on port 41234:
@@ -146,6 +154,11 @@ Example of a UDP server listening on port 41234:
var server = dgram.createSocket("udp4");
+ server.on("error", function (err) {
+ console.log("server error:\n" + err.stack);
+ server.close();
+ });
+
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " +
rinfo.address + ":" + rinfo.port);
diff --git a/doc/api/process.markdown b/doc/api/process.markdown
index cfab68b86..31a8f0474 100644
--- a/doc/api/process.markdown
+++ b/doc/api/process.markdown
@@ -167,6 +167,28 @@ Example:
/usr/local/bin/node
+## process.execArgv
+
+This is the set of node-specific command line options from the
+executable that started the process. These options do not show up in
+`process.argv`, and do not include the node executable, the name of
+the script, or any options following the script name. These options
+are useful in order to spawn child processes with the same execution
+environment as the parent.
+
+Example:
+
+ $ node --harmony script.js --version
+
+results in process.execArgv:
+
+ ['--harmony']
+
+and process.argv:
+
+ ['/usr/local/bin/node', 'script.js', '--version']
+
+
## process.abort()
This causes node to emit an abort. This will cause node to exit and
diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown
index ecdfbdc50..27c47b967 100644
--- a/doc/api/stream.markdown
+++ b/doc/api/stream.markdown
@@ -1085,8 +1085,8 @@ connected in some way to the input, such as a [zlib][] stream or a
There is no requirement that the output be the same size as the input,
the same number of chunks, or arrive at the same time. For example, a
Hash stream will only ever have a single chunk of output which is
-provided when the input is ended. A zlib stream will either produce
-much smaller or much larger than its input.
+provided when the input is ended. A zlib stream will produce output
+that is either much smaller or much larger than its input.
Rather than implement the [`_read()`][] and [`_write()`][] methods, Transform
classes must implement the `_transform()` method, and may optionally
@@ -1174,7 +1174,7 @@ approach.
```javascript
var util = require('util');
-var Transform = require('stream').Transform);
+var Transform = require('stream').Transform;
util.inherits(SimpleProtocol, Transform);
function SimpleProtocol(options) {
diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js
index ae9e72cd8..4ede39f71 100644
--- a/lib/_tls_legacy.js
+++ b/lib/_tls_legacy.js
@@ -268,7 +268,14 @@ CryptoStream.prototype._read = function read(size) {
// Get NPN and Server name when ready
this.pair.maybeInitFinished();
- } while (read > 0 && !this._buffer.isFull && bytesRead < size);
+
+ // `maybeInitFinished()` can emit the 'secure' event which
+ // in turn destroys the connection in case of authentication
+ // failure and sets `this.pair.ssl` to `null`.
+ } while (read > 0 &&
+ !this._buffer.isFull &&
+ bytesRead < size &&
+ this.pair.ssl !== null);
// Create new buffer if previous was filled up
var pool = this._buffer.pool;
diff --git a/lib/fs.js b/lib/fs.js
index 29ef62f39..eb204c000 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1465,7 +1465,7 @@ ReadStream.prototype.open = function() {
var self = this;
fs.open(this.path, this.flags, this.mode, function(er, fd) {
if (er) {
- if (this.autoClose) {
+ if (self.autoClose) {
self.destroy();
}
self.emit('error', er);
diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js
index 9452f95c6..4d1eebb2c 100644
--- a/test/simple/test-fs-read-stream.js
+++ b/test/simple/test-fs-read-stream.js
@@ -171,10 +171,6 @@ function file7Next(){
});
file7.on('end', function(err) {
assert.equal(file7.data, 'xyz\n');
- process.nextTick(function() {
- assert(file7.closed);
- assert(file7.destroyed);
- });
});
}
@@ -182,10 +178,20 @@ function file7Next(){
var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
file8.on('data', function() {});
file8.on('error', common.mustCall(function() {}));
-file8.on('end', function() {
- process.nextTick(function() {
- assert(!file8.closed);
- assert(!file8.destroyed);
- assert(file8.fd);
- });
+
+// Make sure stream is destroyed when file does not exist.
+var file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
+file9.on('data', function() {});
+file9.on('error', common.mustCall(function() {}));
+
+process.on('exit', function() {
+ assert(file7.closed);
+ assert(file7.destroyed);
+
+ assert(!file8.closed);
+ assert(!file8.destroyed);
+ assert(file8.fd);
+
+ assert(!file9.closed);
+ assert(file9.destroyed);
});