@@ -35,7 +35,7 @@ const handleConversion = {
35
35
'net.Native' : {
36
36
simultaneousAccepts : true ,
37
37
38
- send : function ( message , handle ) {
38
+ send : function ( message , handle , options ) {
39
39
return handle ;
40
40
} ,
41
41
@@ -47,7 +47,7 @@ const handleConversion = {
47
47
'net.Server' : {
48
48
simultaneousAccepts : true ,
49
49
50
- send : function ( message , server ) {
50
+ send : function ( message , server , options ) {
51
51
return server . _handle ;
52
52
} ,
53
53
@@ -60,7 +60,7 @@ const handleConversion = {
60
60
} ,
61
61
62
62
'net.Socket' : {
63
- send : function ( message , socket ) {
63
+ send : function ( message , socket , options ) {
64
64
if ( ! socket . _handle )
65
65
return ;
66
66
@@ -90,7 +90,7 @@ const handleConversion = {
90
90
return handle ;
91
91
} ,
92
92
93
- postSend : function ( handle ) {
93
+ postSend : function ( handle , options ) {
94
94
// Close the Socket handle after sending it
95
95
if ( handle )
96
96
handle . close ( ) ;
@@ -117,7 +117,7 @@ const handleConversion = {
117
117
'dgram.Native' : {
118
118
simultaneousAccepts : false ,
119
119
120
- send : function ( message , handle ) {
120
+ send : function ( message , handle , options ) {
121
121
return handle ;
122
122
} ,
123
123
@@ -129,7 +129,7 @@ const handleConversion = {
129
129
'dgram.Socket' : {
130
130
simultaneousAccepts : false ,
131
131
132
- send : function ( message , socket ) {
132
+ send : function ( message , socket , options ) {
133
133
message . dgramType = socket . type ;
134
134
135
135
return socket . _handle ;
@@ -466,7 +466,7 @@ function setupChannel(target, channel) {
466
466
target . _handleQueue = null ;
467
467
468
468
queue . forEach ( function ( args ) {
469
- target . _send ( args . message , args . handle , false , args . callback ) ;
469
+ target . _send ( args . message , args . handle , args . options , args . callback ) ;
470
470
} ) ;
471
471
472
472
// Process a pending disconnect (if any).
@@ -498,13 +498,23 @@ function setupChannel(target, channel) {
498
498
} ) ;
499
499
} ) ;
500
500
501
- target . send = function ( message , handle , callback ) {
501
+ target . send = function ( message , handle , options , callback ) {
502
502
if ( typeof handle === 'function' ) {
503
503
callback = handle ;
504
504
handle = undefined ;
505
+ options = undefined ;
506
+ } else if ( typeof options === 'function' ) {
507
+ callback = options ;
508
+ options = undefined ;
509
+ } else if ( options !== undefined &&
510
+ ( options === null || typeof options !== 'object' ) ) {
511
+ throw new TypeError ( '"options" argument must be an object' ) ;
505
512
}
513
+
514
+ options = Object . assign ( { swallowErrors : false } , options ) ;
515
+
506
516
if ( this . connected ) {
507
- return this . _send ( message , handle , false , callback ) ;
517
+ return this . _send ( message , handle , options , callback ) ;
508
518
}
509
519
const ex = new Error ( 'channel closed' ) ;
510
520
if ( typeof callback === 'function' ) {
@@ -515,12 +525,17 @@ function setupChannel(target, channel) {
515
525
return false ;
516
526
} ;
517
527
518
- target . _send = function ( message , handle , swallowErrors , callback ) {
528
+ target . _send = function ( message , handle , options , callback ) {
519
529
assert ( this . connected || this . _channel ) ;
520
530
521
531
if ( message === undefined )
522
532
throw new TypeError ( 'message cannot be undefined' ) ;
523
533
534
+ // Support legacy function signature
535
+ if ( typeof options === 'boolean' ) {
536
+ options = { swallowErrors : options } ;
537
+ }
538
+
524
539
// package messages with a handle object
525
540
if ( handle ) {
526
541
// this message will be handled by an internalMessage event handler
@@ -549,6 +564,7 @@ function setupChannel(target, channel) {
549
564
this . _handleQueue . push ( {
550
565
callback : callback ,
551
566
handle : handle ,
567
+ options : options ,
552
568
message : message . msg ,
553
569
} ) ;
554
570
return this . _handleQueue . length === 1 ;
@@ -557,8 +573,10 @@ function setupChannel(target, channel) {
557
573
var obj = handleConversion [ message . type ] ;
558
574
559
575
// convert TCP object to native handle object
560
- handle =
561
- handleConversion [ message . type ] . send . call ( target , message , handle ) ;
576
+ handle = handleConversion [ message . type ] . send . call ( target ,
577
+ message ,
578
+ handle ,
579
+ options ) ;
562
580
563
581
// If handle was sent twice, or it is impossible to get native handle
564
582
// out of it - just send a text without the handle.
@@ -575,6 +593,7 @@ function setupChannel(target, channel) {
575
593
this . _handleQueue . push ( {
576
594
callback : callback ,
577
595
handle : null ,
596
+ options : options ,
578
597
message : message ,
579
598
} ) ;
580
599
return this . _handleQueue . length === 1 ;
@@ -593,7 +612,7 @@ function setupChannel(target, channel) {
593
612
if ( this . async === true )
594
613
control . unref ( ) ;
595
614
if ( obj && obj . postSend )
596
- obj . postSend ( handle ) ;
615
+ obj . postSend ( handle , options ) ;
597
616
if ( typeof callback === 'function' )
598
617
callback ( null ) ;
599
618
} ;
@@ -605,9 +624,9 @@ function setupChannel(target, channel) {
605
624
} else {
606
625
// Cleanup handle on error
607
626
if ( obj && obj . postSend )
608
- obj . postSend ( handle ) ;
627
+ obj . postSend ( handle , options ) ;
609
628
610
- if ( ! swallowErrors ) {
629
+ if ( ! options . swallowErrors ) {
611
630
const ex = errnoException ( err , 'write' ) ;
612
631
if ( typeof callback === 'function' ) {
613
632
process . nextTick ( callback , ex ) ;
0 commit comments