Skip to content

Commit

Permalink
[fix] Automatically close the connection when done.
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Apr 7, 2013
1 parent 83b8481 commit c69ad61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bin/thor
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var cluster = require('cluster')
, robin = [];

cluster.setupMaster({
exec: path.resolve(__dirname, '../thunderbolt.js')
exec: path.resolve(__dirname, '../mjolnir.js')
, silent: false
, args: [
cli.generator
Expand Down Expand Up @@ -78,13 +78,14 @@ Object.keys(cluster.workers).forEach(function each(id) {

case 'close':
delete ids[data.id];
console.log('dead');

metrics.close(data);
worker.emit('close::'+ data.id);
break;

case 'error':
delete ids[data.id];

metrics.error(data);
worker.emit('error::'+ data.id);
break;
Expand Down
12 changes: 9 additions & 3 deletions thunderbolt.js → mjolnir.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ process.on('message', function message(task) {
});

// Only write as long as we are allowed to send messages
if (--task.messages) write(socket, task, task.id);
if (--task.messages) {
write(socket, task, task.id);
} else {
socket.close();
}
});

socket.on('close', function close() {
var internal = socket._socket || {};

process.send({
type: 'close', id: task.id,
read: socket._socket.bytesRead,
send: socket._socket.bytesWritten
read: internal.bytesRead || 0,
send: internal.bytesWritten || 0
});
});

Expand Down

0 comments on commit c69ad61

Please sign in to comment.