@@ -57,7 +57,7 @@ Worker.prototype.isConnected = function isConnected() {
5757
5858// Master/worker specific methods are defined in the *Init() functions.
5959
60- function SharedHandle ( key , address , port , addressType , backlog , fd ) {
60+ function SharedHandle ( key , address , port , addressType , backlog , fd , flags ) {
6161 this . key = key ;
6262 this . workers = [ ] ;
6363 this . handle = null ;
@@ -66,7 +66,7 @@ function SharedHandle(key, address, port, addressType, backlog, fd) {
6666 // FIXME(bnoordhuis) Polymorphic return type for lack of a better solution.
6767 var rval ;
6868 if ( addressType === 'udp4' || addressType === 'udp6' )
69- rval = dgram . _createSocketHandle ( address , port , addressType , fd ) ;
69+ rval = dgram . _createSocketHandle ( address , port , addressType , fd , flags ) ;
7070 else
7171 rval = net . _createServerHandle ( address , port , addressType , fd ) ;
7272
@@ -438,7 +438,8 @@ function masterInit() {
438438 var args = [ message . address ,
439439 message . port ,
440440 message . addressType ,
441- message . fd ] ;
441+ message . fd ,
442+ message . index ] ;
442443 var key = args . join ( ':' ) ;
443444 var handle = handles [ key ] ;
444445 if ( handle === undefined ) {
@@ -456,7 +457,8 @@ function masterInit() {
456457 message . port ,
457458 message . addressType ,
458459 message . backlog ,
459- message . fd ) ;
460+ message . fd ,
461+ message . flags ) ;
460462 }
461463 if ( ! handle . data ) handle . data = message . data ;
462464
@@ -485,7 +487,7 @@ function masterInit() {
485487 cluster . emit ( 'listening' , worker , info ) ;
486488 }
487489
488- // Round-robin only. Server in worker is closing, remove from list.
490+ // Server in worker is closing, remove from list.
489491 function close ( worker , message ) {
490492 var key = message . key ;
491493 var handle = handles [ key ] ;
@@ -500,6 +502,7 @@ function masterInit() {
500502
501503function workerInit ( ) {
502504 var handles = { } ;
505+ var indexes = { } ;
503506
504507 // Called from src/node.js
505508 cluster . _setupWorker = function ( ) {
@@ -528,15 +531,22 @@ function workerInit() {
528531 } ;
529532
530533 // 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 ( {
536545 act : 'queryServer' ,
537- fd : fd ,
546+ index : indexes [ key ] ,
538547 data : null
539- } ;
548+ } , options ) ;
549+
540550 // Set custom data on handle (i.e. tls tickets key)
541551 if ( obj . _getServerData ) message . data = obj . _getServerData ( ) ;
542552 send ( message , function ( reply , handle ) {
@@ -549,9 +559,9 @@ function workerInit() {
549559 } ) ;
550560 obj . once ( 'listening' , function ( ) {
551561 cluster . worker . state = 'listening' ;
552- var address = obj . address ( ) ;
562+ const address = obj . address ( ) ;
553563 message . act = 'listening' ;
554- message . port = address && address . port || port ;
564+ message . port = address && address . port || options . port ;
555565 send ( message ) ;
556566 } ) ;
557567 } ;
@@ -563,6 +573,7 @@ function workerInit() {
563573 // closed. Avoids resource leaks when the handle is short-lived.
564574 var close = handle . close ;
565575 handle . close = function ( ) {
576+ send ( { act : 'close' , key : key } ) ;
566577 delete handles [ key ] ;
567578 return close . apply ( this , arguments ) ;
568579 } ;
0 commit comments