@@ -35,7 +35,7 @@ const handleConversion = {
3535'net.Native' : {
3636simultaneousAccepts : true ,
3737
38- send : function ( message , handle ) {
38+ send : function ( message , handle , options ) {
3939return handle ;
4040} ,
4141
@@ -47,7 +47,7 @@ const handleConversion = {
4747'net.Server' : {
4848simultaneousAccepts : true ,
4949
50- send : function ( message , server ) {
50+ send : function ( message , server , options ) {
5151return server . _handle ;
5252} ,
5353
@@ -60,7 +60,7 @@ const handleConversion = {
6060} ,
6161
6262'net.Socket' : {
63- send : function ( message , socket ) {
63+ send : function ( message , socket , options ) {
6464if ( ! socket . _handle )
6565return ;
6666
@@ -90,7 +90,7 @@ const handleConversion = {
9090return handle ;
9191} ,
9292
93- postSend : function ( handle ) {
93+ postSend : function ( handle , options ) {
9494// Close the Socket handle after sending it
9595if ( handle )
9696handle . close ( ) ;
@@ -117,7 +117,7 @@ const handleConversion = {
117117'dgram.Native' : {
118118simultaneousAccepts : false ,
119119
120- send : function ( message , handle ) {
120+ send : function ( message , handle , options ) {
121121return handle ;
122122} ,
123123
@@ -129,7 +129,7 @@ const handleConversion = {
129129'dgram.Socket' : {
130130simultaneousAccepts : false ,
131131
132- send : function ( message , socket ) {
132+ send : function ( message , socket , options ) {
133133message . dgramType = socket . type ;
134134
135135return socket . _handle ;
@@ -466,7 +466,7 @@ function setupChannel(target, channel) {
466466target . _handleQueue = null ;
467467
468468queue . forEach ( function ( args ) {
469- target . _send ( args . message , args . handle , false , args . callback ) ;
469+ target . _send ( args . message , args . handle , args . options , args . callback ) ;
470470} ) ;
471471
472472// Process a pending disconnect (if any).
@@ -498,13 +498,23 @@ function setupChannel(target, channel) {
498498} ) ;
499499} ) ;
500500
501- target . send = function ( message , handle , callback ) {
501+ target . send = function ( message , handle , options , callback ) {
502502if ( typeof handle === 'function' ) {
503503callback = handle ;
504504handle = 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' ) ;
505512}
513+
514+ options = Object . assign ( { swallowErrors : false } , options ) ;
515+
506516if ( this . connected ) {
507- return this . _send ( message , handle , false , callback ) ;
517+ return this . _send ( message , handle , options , callback ) ;
508518}
509519const ex = new Error ( 'channel closed' ) ;
510520if ( typeof callback === 'function' ) {
@@ -515,12 +525,17 @@ function setupChannel(target, channel) {
515525return false ;
516526} ;
517527
518- target . _send = function ( message , handle , swallowErrors , callback ) {
528+ target . _send = function ( message , handle , options , callback ) {
519529assert ( this . connected || this . _channel ) ;
520530
521531if ( message === undefined )
522532throw new TypeError ( '"message" argument cannot be undefined' ) ;
523533
534+ // Support legacy function signature
535+ if ( typeof options === 'boolean' ) {
536+ options = { swallowErrors : options } ;
537+ }
538+
524539// package messages with a handle object
525540if ( handle ) {
526541// this message will be handled by an internalMessage event handler
@@ -549,6 +564,7 @@ function setupChannel(target, channel) {
549564this . _handleQueue . push ( {
550565callback : callback ,
551566handle : handle ,
567+ options : options ,
552568message : message . msg ,
553569} ) ;
554570return this . _handleQueue . length === 1 ;
@@ -557,8 +573,10 @@ function setupChannel(target, channel) {
557573var obj = handleConversion [ message . type ] ;
558574
559575// 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 ) ;
562580
563581// If handle was sent twice, or it is impossible to get native handle
564582// out of it - just send a text without the handle.
@@ -575,6 +593,7 @@ function setupChannel(target, channel) {
575593this . _handleQueue . push ( {
576594callback : callback ,
577595handle : null ,
596+ options : options ,
578597message : message ,
579598} ) ;
580599return this . _handleQueue . length === 1 ;
@@ -593,7 +612,7 @@ function setupChannel(target, channel) {
593612if ( this . async === true )
594613control . unref ( ) ;
595614if ( obj && obj . postSend )
596- obj . postSend ( handle ) ;
615+ obj . postSend ( handle , options ) ;
597616if ( typeof callback === 'function' )
598617callback ( null ) ;
599618} ;
@@ -605,9 +624,9 @@ function setupChannel(target, channel) {
605624} else {
606625// Cleanup handle on error
607626if ( obj && obj . postSend )
608- obj . postSend ( handle ) ;
627+ obj . postSend ( handle , options ) ;
609628
610- if ( ! swallowErrors ) {
629+ if ( ! options . swallowErrors ) {
611630const ex = errnoException ( err , 'write' ) ;
612631if ( typeof callback === 'function' ) {
613632process . nextTick ( callback , ex ) ;
0 commit comments