Skip to content

Commit

Permalink
Removed local socket usage as it is being removed from node
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 25, 2011
1 parent 6cfd9e3 commit b454ce7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/app-cluster.js
Expand Up @@ -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'))
Expand Down
1 change: 0 additions & 1 deletion examples/repl.js
Expand Up @@ -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'))
Expand Down
36 changes: 14 additions & 22 deletions lib/master.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -189,18 +190,6 @@ Master.prototype.resolve = function(path){
: this.dir + '/' + 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__.
Expand All @@ -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']);
};

/**
Expand Down Expand Up @@ -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']);
};

/**
Expand Down Expand Up @@ -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));
Expand Down

2 comments on commit b454ce7

@deedubs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tj
Copy link
Contributor Author

@tj tj commented on b454ce7 Oct 22, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.