diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-18 23:18:50 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-20 12:09:29 +0200 |
commit | ca9eb718fbf2cd2c60c7aeb3ca33413e17fcbbf0 (patch) | |
tree | b9415d0e2f6005a651276cbc40d23196a8c02ddf /lib/cluster.js | |
parent | 0161ec87af3d71b10d8ce679c8a1a64358fae8dc (diff) | |
download | node-new-ca9eb718fbf2cd2c60c7aeb3ca33413e17fcbbf0.tar.gz |
src, lib: update after internal api change
Libuv now returns errors directly. Make everything in src/ and lib/
follow suit.
The changes to lib/ are not strictly necessary but they remove the need
for the abominations that are process._errno and node::SetErrno().
Diffstat (limited to 'lib/cluster.js')
-rw-r--r-- | lib/cluster.js | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/cluster.js b/lib/cluster.js index 11ccbac5cd..b5859348e0 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -58,13 +58,20 @@ function SharedHandle(key, address, port, addressType, backlog, fd) { this.key = key; this.errno = ''; this.workers = []; + this.handle = null; + this.errno = 0; + // FIXME(bnoordhuis) Polymorphic return type for lack of a better solution. + var rval; if (addressType === 'udp4' || addressType === 'udp6') - this.handle = dgram._createSocketHandle(address, port, addressType, fd); + rval = dgram._createSocketHandle(address, port, addressType, fd); else - this.handle = net._createServerHandle(address, port, addressType, fd); + rval = net._createServerHandle(address, port, addressType, fd); - this.errno = this.handle ? '' : process._errno; + if (typeof rval === 'number') + this.errno = rval; + else + this.handle = rval; } SharedHandle.prototype.add = function(worker, send) { @@ -116,10 +123,15 @@ RoundRobinHandle.prototype.add = function(worker, send) { var self = this; function done() { - if (self.handle.getsockname) - send(null, { sockname: self.handle.getsockname() }, null); - else + if (self.handle.getsockname) { + var out = {}; + var err = self.handle.getsockname(out); + // TODO(bnoordhuis) Check err. + send(null, { sockname: out }, null); + } + else { send(null, null, null); // UNIX socket. + } self.handoff(worker); // In case there are connections pending. } @@ -143,7 +155,7 @@ RoundRobinHandle.prototype.remove = function(worker) { return true; }; -RoundRobinHandle.prototype.distribute = function(handle) { +RoundRobinHandle.prototype.distribute = function(err, handle) { this.handles.push(handle); var worker = this.free.shift(); if (worker) this.handoff(worker); @@ -164,7 +176,7 @@ RoundRobinHandle.prototype.handoff = function(worker) { if (reply.accepted) handle.close(); else - self.distribute(handle); // Worker is shutting down. Send to another. + self.distribute(0, handle); // Worker is shutting down. Send to another. self.handoff(worker); }); }; @@ -476,8 +488,9 @@ function workerInit() { function onerror(message, cb) { function listen(backlog) { - process._errno = message.errno; - return -1; + // Translate 'EADDRINUSE' error back to numeric value. This function + // is called as sock._handle.listen(). + return process.binding('uv')['UV_' + message.errno]; } function close() { } @@ -503,10 +516,8 @@ function workerInit() { delete handles[key]; key = undefined; } - function getsockname() { - var rv = {}; - if (key) return util._extend(rv, message.sockname); - return rv; + function getsockname(out) { + if (key) util._extend(out, message.sockname); } // Faux handle. Mimics a TCPWrap with just enough fidelity to get away // with it. Fools net.Server into thinking that it's backed by a real @@ -530,7 +541,7 @@ function workerInit() { var server = handles[key]; var accepted = (typeof server !== 'undefined'); send({ ack: message.seq, accepted: accepted }); - if (accepted) server.onconnection(handle); + if (accepted) server.onconnection(0, handle); } Worker.prototype.disconnect = function() { |