@ -127,12 +127,11 @@ function RoundRobinHandle(key, address, port, addressType, backlog, fd) {
else
else
this . server . listen ( address ) ; // UNIX socket path.
this . server . listen ( address ) ; // UNIX socket path.
var self = this ;
this . server . once ( 'listening' , ( ) => {
this . server . once ( 'listening' , function ( ) {
this . handle = this . server . _ handle ;
self . handle = self . server . _ handle ;
this . handle . onconnection = ( err , handle ) => this . distribute ( err , handle ) ;
self . handle . onconnection = self . distribute . bind ( self ) ;
this . server . _ handle = null ;
self . server . _ handle = null ;
this . server = null ;
self . server = null ;
} ) ;
} ) ;
}
}
@ -140,18 +139,17 @@ RoundRobinHandle.prototype.add = function(worker, send) {
assert ( worker . id in this . all === false ) ;
assert ( worker . id in this . all === false ) ;
this . all [ worker . id ] = worker ;
this . all [ worker . id ] = worker ;
var self = this ;
const done = ( ) => {
function done ( ) {
if ( this . handle . getsockname ) {
if ( self . handle . getsockname ) {
var out = { } ;
var out = { } ;
self . handle . getsockname ( out ) ;
this . handle . getsockname ( out ) ;
// TODO(bnoordhuis) Check err.
// TODO(bnoordhuis) Check err.
send ( null , { sockname : out } , null ) ;
send ( null , { sockname : out } , null ) ;
} else {
} else {
send ( null , null , null ) ; // UNIX socket.
send ( null , null , null ) ; // UNIX socket.
}
}
self . handoff ( worker ) ; // In case there are connections pending.
this . handoff ( worker ) ; // In case there are connections pending.
}
} ;
if ( this . server === null ) return done ( ) ;
if ( this . server === null ) return done ( ) ;
// Still busy binding.
// Still busy binding.
@ -193,13 +191,13 @@ RoundRobinHandle.prototype.handoff = function(worker) {
return ;
return ;
}
}
var message = { act : 'newconn' , key : this . key } ;
var message = { act : 'newconn' , key : this . key } ;
var self = this ;
sendHelper ( worker . process , message , handle , function ( reply ) {
sendHelper ( worker . process , message , handle , ( reply ) => {
if ( reply . accepted )
if ( reply . accepted )
handle . close ( ) ;
handle . close ( ) ;
else
else
self . distribute ( 0 , handle ) ; // Worker is shutting down. Send to another.
this . distribute ( 0 , handle ) ; // Worker is shutting down. Send to another.
self . handoff ( worker ) ;
this . handoff ( worker ) ;
} ) ;
} ) ;
} ;
} ;
@ -414,7 +412,7 @@ function masterInit() {
cluster . disconnect = function ( cb ) {
cluster . disconnect = function ( cb ) {
var workers = Object . keys ( cluster . workers ) ;
var workers = Object . keys ( cluster . workers ) ;
if ( workers . length === 0 ) {
if ( workers . length === 0 ) {
process . nextTick ( intercom . emit . bind ( intercom , 'disconnect' ) ) ;
process . nextTick ( ( ) => intercom . emit ( 'disconnect' ) ) ;
} else {
} else {
for ( var key in workers ) {
for ( var key in workers ) {
key = workers [ key ] ;
key = workers [ key ] ;
@ -436,7 +434,7 @@ function masterInit() {
signo = signo || 'SIGTERM' ;
signo = signo || 'SIGTERM' ;
var proc = this . process ;
var proc = this . process ;
if ( this . isConnected ( ) ) {
if ( this . isConnected ( ) ) {
this . once ( 'disconnect' , proc . kill . bind ( proc , signo ) ) ;
this . once ( 'disconnect' , ( ) => proc . kill ( signo ) ) ;
this . disconnect ( ) ;
this . disconnect ( ) ;
return ;
return ;
}
}