Skip to content
Browse files

Removed local socket usage as it is being removed from node

  • Loading branch information...
1 parent 6cfd9e3 commit b454ce7e1830b1eb46d80d1ae2e23b53c113c58d @tj tj committed Aug 25, 2011
Showing with 15 additions and 25 deletions.
  1. +1 −1 docs/api.md
  2. +0 −1 examples/app-cluster.js
  3. +0 −1 examples/repl.js
  4. +14 −22 lib/master.js
View
2 docs/api.md
@@ -72,7 +72,7 @@
- `workers` Number of workers to spawn, defaults to the number of CPUs or `1`
- `working directory` Working directory defaulting to the script's dir
- `backlog` Connection backlog, defaulting to 128
- - `socket path` Master socket path defaulting to `./`
+ - `socket port` Master socket port defaulting to `8989`
- `timeout` Worker shutdown timeout in milliseconds, defaulting to `60000`
- `title` master process title defaulting to "cluster"
- `worker title` worker process title defaulting to "cluster worker"
View
1 examples/app-cluster.js
@@ -8,7 +8,6 @@ var cluster = require('../');
cluster('app.js')
.set('workers', 4)
- .set('socket path', '/tmp')
.use(cluster.logger('logs'))
.use(cluster.stats({ connections: true, requests: true }))
.use(cluster.repl(8888, '127.0.0.1'))
View
1 examples/repl.js
@@ -22,7 +22,6 @@ cluster.repl.define('echo', function(master, sock, msg){
// $ telnet localhots 8888
cluster(server)
.set('workers', 4)
- .set('socket path', '/tmp')
.use(cluster.logger('logs'))
.use(cluster.stats({ connections: true, requests: true }))
.use(cluster.repl(8888, '127.0.0.1'))
View
36 lib/master.js
@@ -42,7 +42,7 @@ var node = process.execPath;
* - `workers` Number of workers to spawn, defaults to the number of CPUs
* - 'working directory` Working directory defaulting to the script's dir
* - 'backlog` Connection backlog, defaulting to 128
- * - 'socket path` Master socket path defaulting to `./`
+ * - 'socket port` Master socket port defaulting to `8989`
* - 'timeout` Worker shutdown timeout in milliseconds, defaulting to 60,000
* - 'user` User id / name
* - 'group` Group id / name
@@ -97,7 +97,8 @@ var Master = module.exports = function Master(server) {
this.options = {
'backlog': 128
, 'working directory': this.dir
- , 'socket path': this.dir
+ , 'socket port': 8989
+ , 'socket addr': '127.0.0.1'
, 'timeout': 60000
, 'restart threshold': 'development' == this.env ? 5000 : 60000
, 'restart timeout': 'development' == this.env ? 5000 : 60000
@@ -127,7 +128,7 @@ var Master = module.exports = function Master(server) {
this.customFds = [1, 2];
// udp server for IPC
- this._server = dgram.createSocket('unix_dgram');
+ this._server = dgram.createSocket('udp4');
this._server.on('message', function(msg, info){
try {
msg = JSON.parse(msg.toString('ascii'));
@@ -190,18 +191,6 @@ Master.prototype.resolve = function(path){
};
/**
- * Return the path of the unix domain socket server used for IPC.
- *
- * @return {String}
- * @api public
- */
-
-Master.prototype.__defineGetter__('serverSocketPath', function(){
- var pid = process.env.CLUSTER_MASTER_PID || this.pid;
- return this.options['socket path'] + '/cluster.' + pid + '.server.sock';
-});
-
-/**
* Return `true` when the environment set by `Master#in()`
* matches __NODE_ENV__.
*
@@ -225,15 +214,20 @@ Master.prototype.__defineGetter__('environmentMatches', function(){
*/
Master.prototype.call = function(id, method){
- this.sock = this.sock || dgram.createSocket('unix_dgram');
+ this.sock = this.sock || dgram.createSocket('udp4');
var msg = new Buffer(utils.frame({
args: utils.toArray(arguments, 2)
, method: method
, id: id
}));
- this.sock.send(msg, 0, msg.length, this.serverSocketPath);
+ this.sock.send(
+ msg
+ , 0
+ , msg.length
+ , this.options['socket port']
+ , this.options['socket addr']);
};
/**
@@ -323,10 +317,8 @@ Master.prototype.setupIPC = function(){
this.defaultWorkers();
// udp server for IPC
- this._server.bind(this.serverSocketPath);
- this._server.on('listening', function(){
- self.emit('start');
- });
+ this._server.on('listening', function(){ self.emit('start'); });
+ this._server.bind(this.options['socket port'], this.options['socket addr']);
};
/**
@@ -748,7 +740,7 @@ Master.prototype.acceptFd = function(){
*/
Master.prototype._destroy = function(){
- try { unlink(this.serverSocketPath); } catch (err) {}
+ this._server.close();
if (this.fd) close(this.fd);
this.emit('close');
process.nextTick(process.exit.bind(process));

2 comments on commit b454ce7

@deedubs

Wow. This seems pretty unfortunate... Is this related to the windows support? Sure hope its worth it.

@tj
LearnBoost member
tj commented on b454ce7 Oct 22, 2011

yup, now we get the joys of some weird hybrid thinger that no longer feel like familiar posix apis

Please sign in to comment.
Something went wrong with that request. Please try again.