Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Master.prototype.getWorker = function() {
return this.workers[pids[this.currentIndex++]];
};

Master.prototype.distribute = function(socket) {
Master.prototype.distribute = function(handle) {
var worker = this.getWorker()
var self = this;

Expand All @@ -38,13 +38,13 @@ Master.prototype.distribute = function(socket) {
socket.end('HTTP 1.1 500 Internal Server Error\nContent-Length:0');
}
else{
self.handoff(worker, socket);
self.handoff(worker, handle);
}
};

Master.prototype.handoff = function(worker, socket) {
Master.prototype.handoff = function(worker, handle) {
var self = this;
worker.send('socket', socket);
worker.send('handle', handle);
};

// create the server.
Expand Down Expand Up @@ -78,15 +78,16 @@ Master.prototype.start = function(callback) {
// add our connection handler:
// if cluster is used, then the socket is distributed to a worker.
// if cluster is not used, then handle in master.
self.server.on('connection', function(socket) {
if (clusterEnabled) {
socket.pause();
self.distribute(socket);
}
else {
self.worker.handleMessage('socket', socket);
}
});
if(clusterEnabled){
self.server._handle.onconnection = function(handle){
self.distribute(handle);
}
}
else{
self.server.on('connection', function(socket) {
self.worker.handleMessage('socket', socket);
});
}
};

// remove old file descriptor if needed.
Expand Down
9 changes: 7 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('lodash');
var http = require('http');
var net = require('net');
var util = require('util');
var events = require('events');

Expand Down Expand Up @@ -133,10 +134,14 @@ Worker.prototype.handleRequest = function(req, res) {
}
};

Worker.prototype.handleMessage = function(message, socket) {
Worker.prototype.handleMessage = function(message, data) {
if (message === 'socket') {
// call the http connection parsing stuff here.
http._connectionListener.call(this, socket);
http._connectionListener.call(this, data);
}
else if(message === 'handle'){
var sock = new net.Socket({'fd':data.fd});
http._connectionListener.call(this,sock);
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mixdown-server",
"version": "2.0.1",
"version": "2.0.2",
"main": "index",
"description": "Simple server for activiting a site.",
"keywords": [
Expand Down