@@ -57,7 +57,7 @@ Worker.prototype.isConnected = function isConnected() {
57
57
58
58
// Master/worker specific methods are defined in the *Init() functions.
59
59
60
- function SharedHandle ( key , address , port , addressType , backlog , fd ) {
60
+ function SharedHandle ( key , address , port , addressType , backlog , fd , flags ) {
61
61
this . key = key ;
62
62
this . workers = [ ] ;
63
63
this . handle = null ;
@@ -66,7 +66,7 @@ function SharedHandle(key, address, port, addressType, backlog, fd) {
66
66
// FIXME(bnoordhuis) Polymorphic return type for lack of a better solution.
67
67
var rval ;
68
68
if ( addressType === 'udp4' || addressType === 'udp6' )
69
- rval = dgram . _createSocketHandle ( address , port , addressType , fd ) ;
69
+ rval = dgram . _createSocketHandle ( address , port , addressType , fd , flags ) ;
70
70
else
71
71
rval = net . _createServerHandle ( address , port , addressType , fd ) ;
72
72
@@ -438,7 +438,8 @@ function masterInit() {
438
438
var args = [ message . address ,
439
439
message . port ,
440
440
message . addressType ,
441
- message . fd ] ;
441
+ message . fd ,
442
+ message . index ] ;
442
443
var key = args . join ( ':' ) ;
443
444
var handle = handles [ key ] ;
444
445
if ( handle === undefined ) {
@@ -456,7 +457,8 @@ function masterInit() {
456
457
message . port ,
457
458
message . addressType ,
458
459
message . backlog ,
459
- message . fd ) ;
460
+ message . fd ,
461
+ message . flags ) ;
460
462
}
461
463
if ( ! handle . data ) handle . data = message . data ;
462
464
@@ -485,7 +487,7 @@ function masterInit() {
485
487
cluster . emit ( 'listening' , worker , info ) ;
486
488
}
487
489
488
- // Round-robin only. Server in worker is closing, remove from list.
490
+ // Server in worker is closing, remove from list.
489
491
function close ( worker , message ) {
490
492
var key = message . key ;
491
493
var handle = handles [ key ] ;
@@ -500,6 +502,7 @@ function masterInit() {
500
502
501
503
function workerInit ( ) {
502
504
var handles = { } ;
505
+ var indexes = { } ;
503
506
504
507
// Called from src/node.js
505
508
cluster . _setupWorker = function ( ) {
@@ -528,15 +531,22 @@ function workerInit() {
528
531
} ;
529
532
530
533
// obj is a net#Server or a dgram#Socket object.
531
- cluster . _getServer = function ( obj , address , port , addressType , fd , cb ) {
532
- var message = {
533
- addressType : addressType ,
534
- address : address ,
535
- port : port ,
534
+ cluster . _getServer = function ( obj , options , cb ) {
535
+ const key = [ options . address ,
536
+ options . port ,
537
+ options . addressType ,
538
+ options . fd ] . join ( ':' ) ;
539
+ if ( indexes [ key ] === undefined )
540
+ indexes [ key ] = 0 ;
541
+ else
542
+ indexes [ key ] ++ ;
543
+
544
+ const message = util . _extend ( {
536
545
act : 'queryServer' ,
537
- fd : fd ,
546
+ index : indexes [ key ] ,
538
547
data : null
539
- } ;
548
+ } , options ) ;
549
+
540
550
// Set custom data on handle (i.e. tls tickets key)
541
551
if ( obj . _getServerData ) message . data = obj . _getServerData ( ) ;
542
552
send ( message , function ( reply , handle ) {
@@ -549,9 +559,9 @@ function workerInit() {
549
559
} ) ;
550
560
obj . once ( 'listening' , function ( ) {
551
561
cluster . worker . state = 'listening' ;
552
- var address = obj . address ( ) ;
562
+ const address = obj . address ( ) ;
553
563
message . act = 'listening' ;
554
- message . port = address && address . port || port ;
564
+ message . port = address && address . port || options . port ;
555
565
send ( message ) ;
556
566
} ) ;
557
567
} ;
@@ -563,6 +573,7 @@ function workerInit() {
563
573
// closed. Avoids resource leaks when the handle is short-lived.
564
574
var close = handle . close ;
565
575
handle . close = function ( ) {
576
+ send ( { act : 'close' , key : key } ) ;
566
577
delete handles [ key ] ;
567
578
return close . apply ( this , arguments ) ;
568
579
} ;
0 commit comments