diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/child_process.js | 18 | ||||
-rw-r--r-- | lib/cluster.js | 26 | ||||
-rw-r--r-- | lib/fs.js | 12 | ||||
-rw-r--r-- | lib/net.js | 6 | ||||
-rw-r--r-- | lib/os.js | 8 | ||||
-rw-r--r-- | lib/sys.js | 11 | ||||
-rw-r--r-- | lib/util.js | 16 |
7 files changed, 52 insertions, 45 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index dcff85ab3e..a34313f61e 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -25,7 +25,6 @@ var Process = process.binding('process_wrap').Process; var inherits = require('util').inherits; var constants; // if (!constants) constants = process.binding('constants'); -var LF = '\n'.charCodeAt(0); var Pipe; @@ -76,8 +75,8 @@ function setupChannel(target, channel) { if (isWindows) { var setSimultaneousAccepts = function(handle) { - var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS - && process.env.NODE_MANY_ACCEPTS != '0') ? true : false; + var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS && + process.env.NODE_MANY_ACCEPTS != '0') ? true : false; if (handle._simultaneousAccepts != simultaneousAccepts) { handle.setSimultaneousAccepts(simultaneousAccepts); @@ -101,7 +100,7 @@ function setupChannel(target, channel) { var message = JSON.parse(json); target.emit('message', message, recvHandle); - start = i+1; + start = i + 1; } jsonBuffer = jsonBuffer.slice(start); @@ -112,7 +111,7 @@ function setupChannel(target, channel) { }; target.send = function(message, sendHandle) { - if (!target._channel) throw new Error("channel closed"); + if (!target._channel) throw new Error('channel closed'); // For overflow protection don't write if channel queue is too deep. if (channel.writeQueueSize > 1024 * 1024) { @@ -129,7 +128,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 new Error(errno + 'cannot write to IPC channel.'); } writeReq.oncomplete = nop; @@ -151,16 +150,16 @@ exports.fork = function(modulePath, args, options) { args.unshift(modulePath); if (options.stdinStream) { - throw new Error("stdinStream not allowed for fork()"); + throw new Error('stdinStream not allowed for fork()'); } if (options.customFds) { - throw new Error("customFds not allowed for fork()"); + throw new Error('customFds not allowed for fork()'); } // Leave stdin open for the IPC channel. stdout and stderr should be the // same as the parent's. - options.customFds = [ -1, 1, 2 ]; + options.customFds = [-1, 1, 2]; // Just need to set this - child process won't actually use the fd. // For backwards compat - this can be changed to 'NODE_CHANNEL' before v0.6. @@ -331,7 +330,6 @@ var spawn = exports.spawn = function(file, args, options) { var env = (options ? options.env : null) || process.env; var envPairs = []; - var keys = Object.keys(env); for (var key in env) { envPairs.push(key + '=' + env[key]); } diff --git a/lib/cluster.js b/lib/cluster.js index cc2f98cd5b..6c7d2dfa83 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -81,11 +81,11 @@ function startMaster() { // Quickly try to kill all the workers. // TODO: be session leader - will cause auto SIGHUP to the children. eachWorker(function(worker) { - debug("kill worker " + worker.pid); + debug('kill worker ' + worker.pid); worker.kill(); - }) + }); - console.error("Exception in cluster master process: " + + console.error('Exception in cluster master process: ' + e.message + '\n' + e.stack); process.exit(1); }); @@ -96,21 +96,21 @@ function handleWorkerMessage(worker, message) { // This can only be called from the master. assert(cluster.isMaster); - debug("recv " + JSON.stringify(message)); + debug('recv ' + JSON.stringify(message)); switch (message.cmd) { case 'online': - debug("Worker " + worker.pid + " online"); + debug('Worker ' + worker.pid + ' online'); worker.online = true; break; case 'queryServer': - var key = message.address + ":" + - message.port + ":" + + var key = message.address + ':' + + message.port + ':' + message.addressType; var response = { _queryId: message._queryId }; - if (key in servers == false) { + if (!(key in servers)) { // Create a new server. debug('create new server ' + key); servers[key] = net._createServerHandle(message.address, @@ -136,7 +136,7 @@ function eachWorker(cb) { cb(workers[id]); } } -}; +} cluster.fork = function() { @@ -176,19 +176,19 @@ cluster.fork = function() { // Internal function. Called from src/node.js when worker process starts. cluster._startWorker = function() { assert(cluster.isWorker); - workerId = parseInt(process.env.NODE_WORKER_ID); + workerId = parseInt(process.env.NODE_WORKER_ID, 10); queryMaster({ cmd: 'online' }); // Make callbacks from queryMaster() process.on('message', function(msg, handle) { - debug("recv " + JSON.stringify(msg)); + debug('recv ' + JSON.stringify(msg)); if (msg._queryId && msg._queryId in queryCallbacks) { var cb = queryCallbacks[msg._queryId]; if (typeof cb == 'function') { cb(msg, handle); } - delete queryCallbacks[msg._queryId] + delete queryCallbacks[msg._queryId]; } }); }; @@ -219,7 +219,7 @@ cluster._getServer = function(address, port, addressType, cb) { assert(cluster.isWorker); queryMaster({ - cmd: "queryServer", + cmd: 'queryServer', address: address, port: port, addressType: addressType @@ -422,17 +422,17 @@ fs.readlinkSync = function(path) { return binding.readlink(pathModule._makeLong(path)); }; -fs.symlink = function(destination, path, mode_, callback) { - var mode = (typeof(mode_) == 'string' ? mode_ : null); +fs.symlink = function(destination, path, type_, callback) { + var type = (typeof(type_) == 'string' ? type_ : null); var callback_ = arguments[arguments.length - 1]; callback = (typeof(callback_) == 'function' ? callback_ : null); binding.symlink(pathModule._makeLong(destination), - pathModule._makeLong(path), mode, callback); + pathModule._makeLong(path), type, callback); }; -fs.symlinkSync = function(destination, path, mode) { +fs.symlinkSync = function(destination, path, type) { return binding.symlink(pathModule._makeLong(destination), - pathModule._makeLong(path), mode); + pathModule._makeLong(path), type); }; fs.link = function(srcpath, dstpath, callback) { @@ -1092,7 +1092,7 @@ ReadStream.prototype._read = function() { // thread pool another read() finishes up the pool, and allocates a new // one. var thisPool = pool; - var toRead = Math.min(pool.length - pool.used, this.bufferSize); + var toRead = Math.min(pool.length - pool.used, ~~this.bufferSize); var start = pool.used; if (this.pos !== undefined) { diff --git a/lib/net.js b/lib/net.js index 19858e80df..e182173953 100644 --- a/lib/net.js +++ b/lib/net.js @@ -465,7 +465,11 @@ function afterWrite(status, handle, req, buffer) { if (self.destroyed) { return; } - // TODO check status. + + if (status) { + self.destroy(errnoException(errno, 'write')); + return; + } timers.active(this); @@ -37,12 +37,8 @@ exports.platform = function() { return process.platform; }; -var warnNetworkInterfaces = true; exports.getNetworkInterfaces = function() { - if (warnNetworkInterfaces) { - console.error("os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()"); - console.trace(); - warnNetworkInterfaces = false; - } + require('util')._deprecationWarning('os', + 'os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()'); return exports.networkInterfaces(); }; diff --git a/lib/sys.js b/lib/sys.js index d53a3dd95e..0039b89d20 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -21,15 +21,8 @@ var util = require('util'); -var sysWarning; -if (!sysWarning) { - sysWarning = 'The "sys" module is now called "util". ' + - 'It should have a similar interface.'; - if (process.env.NODE_DEBUG && process.env.NODE_DEBUG.indexOf('sys') != -1) - console.trace(sysWarning); - else - console.error(sysWarning); -} +util._deprecationWarning('sys', + 'The "sys" module is now called "util". It should have a similar interface.'); exports.print = util.print; exports.puts = util.puts; diff --git a/lib/util.js b/lib/util.js index b00da2de9d..cd4cc0e964 100644 --- a/lib/util.js +++ b/lib/util.js @@ -518,3 +518,19 @@ exports.inherits = function(ctor, superCtor) { } }); }; + +var deprecationWarnings; + +exports._deprecationWarning = function(moduleId, message) { + if (!deprecationWarnings) + deprecationWarnings = {}; + else if (message in deprecationWarnings) + return; + + deprecationWarnings[message] = true; + + if ((new RegExp('\\b' + moduleId + '\\b')).test(process.env.NODE_DEBUG)) + console.trace(message); + else + console.error(message); +}; |