diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2012-01-23 22:30:28 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2012-01-23 22:30:28 +0400 |
commit | 667aae596cded9336f50574386683ec39ada43f2 (patch) | |
tree | 41918ad8d4801cc34215b054cb63dc83bd1ce8a5 /lib | |
parent | 2433eeb3850a91feb99bab530cb7183800166390 (diff) | |
parent | 6c0c00a2052ec613503a0322dcbabb6fcf41dab0 (diff) |
Merge branch 'v0.6'
Conflicts:
ChangeLog
doc/template.html
lib/cluster.js
lib/http.js
lib/tls.js
src/node.h
src/node_version.h
test/simple/test-cluster-kill-workers.js
Diffstat (limited to 'lib')
-rw-r--r-- | lib/child_process.js | 10 | ||||
-rw-r--r-- | lib/dgram.js | 34 | ||||
-rw-r--r-- | lib/http.js | 22 | ||||
-rw-r--r-- | lib/path.js | 4 | ||||
-rw-r--r-- | lib/tls.js | 19 | ||||
-rw-r--r-- | lib/tty.js | 7 | ||||
-rw-r--r-- | lib/util.js | 27 | ||||
-rw-r--r-- | lib/zlib.js | 20 |
8 files changed, 96 insertions, 47 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index 5ba6065cb04..9cdf7d6eecb 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -146,7 +146,7 @@ function setupChannel(target, channel) { var writeReq = channel.write(buffer, 0, buffer.length, sendHandle); if (!writeReq) { - throw new Error(errno + 'cannot write to IPC channel.'); + throw errnoException(errno, 'write', 'cannot write to IPC channel.'); } writeReq.oncomplete = nop; @@ -496,11 +496,15 @@ ChildProcess.prototype.spawn = function(options) { }; -function errnoException(errorno, syscall) { +function errnoException(errorno, syscall, errmsg) { // TODO make this more compatible with ErrnoException from src/node.cc // Once all of Node is using this function the ErrnoException from // src/node.cc should be removed. - var e = new Error(syscall + ' ' + errorno); + var message = syscall + ' ' + errorno; + if (errmsg) { + message += ' - ' + errmsg; + } + var e = new Error(message); e.errno = e.code = errorno; e.syscall = syscall; return e; diff --git a/lib/dgram.js b/lib/dgram.js index 26e0a2a3e81..d5c2e0da69c 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -223,7 +223,11 @@ Socket.prototype.address = function() { Socket.prototype.setBroadcast = function(arg) { - throw new Error('not yet implemented'); + if (this._handle.setBroadcast((arg) ? 1 : 0) == -1) { + throw errnoException(errno, 'setBroadcast'); + } + + return true; }; @@ -233,7 +237,11 @@ Socket.prototype.setTTL = function(arg) { Socket.prototype.setMulticastTTL = function(arg) { - throw new Error('not yet implemented'); + if (this._handle.setMulticastTTL(arg) == -1) { + throw errnoException(errno, 'setMulticastTTL'); + } + + return true; }; @@ -243,16 +251,26 @@ Socket.prototype.setMulticastLoopback = function(arg) { Socket.prototype.addMembership = function(multicastAddress, - multicastInterface) { - // are we ever going to support this in libuv? - throw new Error('not yet implemented'); + interfaceAddress) { + this._healthCheck(); + + if (!multicastAddress) { + throw new Error('multicast address must be specified'); + } + + return this._handle.addMembership(multicastAddress, interfaceAddress); }; Socket.prototype.dropMembership = function(multicastAddress, - multicastInterface) { - // are we ever going to support this in libuv? - throw new Error('not yet implemented'); + interfaceAddress) { + this._healthCheck(); + + if (!multicastAddress) { + throw new Error('multicast address must be specified'); + } + + return this._handle.dropMembership(multicastAddress, interfaceAddress); }; diff --git a/lib/http.js b/lib/http.js index 14e41ba24c9..7ad7765a668 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1181,13 +1181,23 @@ ClientRequest.prototype.onSocket = function(socket) { // Setup "drain" propogation. httpSocketSetup(socket); + var freeParser = function() { + if (parser) { + parsers.free(parser); + parser = null; + } + }; + var errorListener = function(err) { debug('HTTP SOCKET ERROR: ' + err.message + '\n' + err.stack); req.emit('error', err); // For Safety. Some additional errors might fire later on // and we need to make sure we don't double-fire the error event. req._hadError = true; - parser.finish(); + if (parser) { + parser.finish(); + freeParser(); + } socket.destroy(); } socket.on('error', errorListener); @@ -1196,6 +1206,7 @@ ClientRequest.prototype.onSocket = function(socket) { var ret = parser.execute(d, start, end - start); if (ret instanceof Error) { debug('parse error'); + freeParser(); socket.destroy(ret); } else if (parser.incoming && parser.incoming.upgrade) { // Upgrade or CONNECT @@ -1226,6 +1237,9 @@ ClientRequest.prototype.onSocket = function(socket) { // Got Upgrade header or CONNECT method, but have no handler. socket.destroy(); } + freeParser(); + } else if (parser.incoming && parser.incoming.complete) { + freeParser(); } }; @@ -1236,8 +1250,10 @@ ClientRequest.prototype.onSocket = function(socket) { req.emit('error', createHangUpError()); req._hadError = true; } - parser.finish(); - parsers.free(parser); // I don't know if this is necessary --Mikeal + if (parser) { + parser.finish(); + freeParser(); + } socket.destroy(); }; diff --git a/lib/path.js b/lib/path.js index 6a744dfeca7..bdae368c256 100644 --- a/lib/path.js +++ b/lib/path.js @@ -62,7 +62,7 @@ if (isWindows) { /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext] - var splitTailRe = /^([\s\S]+[\\\/](?!$)|[\\\/])?((?:[\s\S]+?)?(\.[^.]*)?)$/; + var splitTailRe = /^([\s\S]+[\\\/](?!$)|[\\\/])?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/\\]*)?)$/; // Function to split a filename into [root, dir, basename, ext] // windows version @@ -256,7 +256,7 @@ if (isWindows) { // Split a filename into [root, dir, basename, ext], unix version // 'root' is just a slash, or nothing. - var splitPathRe = /^(\/?)([\s\S]+\/(?!$)|\/)?((?:[\s\S]+?)?(\.[^.]*)?)$/; + var splitPathRe = /^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/; var splitPath = function(filename) { var result = splitPathRe.exec(filename); return [result[1] || '', result[2] || '', result[3] || '', result[4] || '']; diff --git a/lib/tls.js b/lib/tls.js index c8f2ed27d0d..faf81c06649 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -271,7 +271,11 @@ CryptoStream.prototype._done = function() { this.pair.encrypted._doneFlag && !this.pair._doneFlag) { // If both streams are done: - this.pair.destroy(); + if (!this.pair._secureEstablished) { + this.pair.error(); + } else { + this.pair.destroy(); + } } }; @@ -724,7 +728,6 @@ SecurePair.prototype.destroy = function() { } var self = this; - var error = this.ssl.error; this._doneFlag = true; this.ssl.error = null; @@ -739,20 +742,18 @@ SecurePair.prototype.destroy = function() { self.encrypted.emit('close'); self.cleartext.emit('close'); }); +}; + +SecurePair.prototype.error = function() { if (!this._secureEstablished) { + var error = this.ssl.error; if (!error) { error = new Error('socket hang up'); error.code = 'ECONNRESET'; } - this.emit('error', error); - } -}; - - -SecurePair.prototype.error = function() { - if (!this._secureEstablished) { this.destroy(); + this.emit('error', error); } else { var err = this.ssl.error; this.ssl.error = null; diff --git a/lib/tty.js b/lib/tty.js index 32ba512d525..dccda5a4812 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -225,6 +225,13 @@ ReadStream.prototype._emitKey = function(s) { case '[13~': key.name = 'f3'; break; case '[14~': key.name = 'f4'; break; + /* from Cygwin and used in libuv */ + case '[[A': key.name = 'f1'; break; + case '[[B': key.name = 'f2'; break; + case '[[C': key.name = 'f3'; break; + case '[[D': key.name = 'f4'; break; + case '[[E': key.name = 'f5'; break; + /* common */ case '[15~': key.name = 'f5'; break; case '[17~': key.name = 'f6'; break; diff --git a/lib/util.js b/lib/util.js index 8cc4739f275..d3b13066f88 100644 --- a/lib/util.js +++ b/lib/util.js @@ -296,29 +296,28 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str; - if (value.__lookupGetter__) { - if (value.__lookupGetter__(key)) { - if (value.__lookupSetter__(key)) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); - } + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); } else { - if (value.__lookupSetter__(key)) { - str = ctx.stylize('[Setter]', 'special'); - } + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); } } if (visibleKeys.indexOf(key) < 0) { name = '[' + key + ']'; } if (!str) { - if (ctx.seen.indexOf(value[key]) < 0) { + if (ctx.seen.indexOf(desc.value) < 0) { if (recurseTimes === null) { - str = formatValue(ctx, value[key], null); + str = formatValue(ctx, desc.value, null); } else { - str = formatValue(ctx, value[key], recurseTimes - 1); + str = formatValue(ctx, desc.value, recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (array) { diff --git a/lib/zlib.js b/lib/zlib.js index 339f1e71356..349c5c64d97 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -122,18 +122,18 @@ function zlibBuffer(engine, buffer, callback) { var buffers = []; var nread = 0; - engine.on('error', function(err) { - engine.removeListener('end'); - engine.removeListener('error'); + function onError(err) { + engine.removeListener('end', onEnd); + engine.removeListener('error', onError); callback(err); - }); + } - engine.on('data', function(chunk) { + function onData(chunk) { buffers.push(chunk); nread += chunk.length; - }); + } - engine.on('end', function() { + function onEnd() { var buffer; switch(buffers.length) { case 0: @@ -153,7 +153,11 @@ function zlibBuffer(engine, buffer, callback) { break; } callback(null, buffer); - }); + } + + engine.on('error', onError); + engine.on('data', onData); + engine.on('end', onEnd); engine.write(buffer); engine.end(); |