Skip to content

Commit dcae5b8

Browse files
committed
lib: update to support 0.10
1 parent f834a14 commit dcae5b8

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

example/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var http = require('http'),
22
sticky = require('../');
33

44
sticky(http.createServer(function(req, res) {
5-
res.end('worker: ' + process.env.NODE_WORKER_ID);
5+
res.end('worker: ' + process.pid);
66
})).listen(3000, function() {
77
console.log('server started on 3000 port');
88
});

lib/sticky-session.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,18 @@ module.exports = function sticky(num, callback) {
4949
var worker,
5050
ipHash = hash((c.remoteAddress || '').split(/\./g), seed);
5151

52-
// Pause socket (so we won't loose any data)
53-
c.pause();
54-
5552
// Pass connection to worker
5653
worker = workers[ipHash % workers.length];
57-
worker.send('sticky-session:connection', c._handle);
58-
59-
// And detach socket from master process
60-
c._handle.close();
54+
worker.send('sticky-session:connection', c);
6155
});
6256
} else {
6357
server = typeof callback === 'function' ? callback() : callback;
6458

6559
// Worker process
66-
process.on('message', function(msg, handle) {
60+
process.on('message', function(msg, socket) {
6761
if (msg !== 'sticky-session:connection') return;
68-
var socket = new net.Socket({ handle: handle });
69-
70-
// Socket is non-writable by default
71-
socket.readable = socket.writable = true;
7262

7363
server.emit('connection', socket);
74-
75-
// Unpause it
76-
socket.pause();
77-
socket.resume();
7864
});
7965

8066
if (!server) throw new Error('Worker hasn\'t created server!');

0 commit comments

Comments
 (0)