File tree Expand file tree Collapse file tree 2 files changed +3
-17
lines changed
Expand file tree Collapse file tree 2 files changed +3
-17
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ var http = require('http'),
22 sticky = require ( '../' ) ;
33
44sticky ( 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} ) ;
Original file line number Diff line number Diff 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!' ) ;
You can’t perform that action at this time.
0 commit comments