3737
3838const { Buffer } = require ( 'buffer' ) ;
3939const TTYWrap = process . binding ( 'tty_wrap' ) ;
40- const { TCP } = process . binding ( 'tcp_wrap' ) ;
41- const { Pipe } = process . binding ( 'pipe_wrap' ) ;
40+ const { TCP , constants : TCPConstants } = process . binding ( 'tcp_wrap' ) ;
41+ const { Pipe, constants : PipeConstants } = process . binding ( 'pipe_wrap' ) ;
4242const { TCPConnectWrap } = process . binding ( 'tcp_wrap' ) ;
4343const { PipeConnectWrap } = process . binding ( 'pipe_wrap' ) ;
4444const { ShutdownWrap, WriteWrap } = process . binding ( 'stream_wrap' ) ;
@@ -57,10 +57,20 @@ const exceptionWithHostPort = util._exceptionWithHostPort;
5757
5858function noop ( ) { }
5959
60- function createHandle ( fd ) {
60+ function createHandle ( fd , is_server ) {
6161const type = TTYWrap . guessHandleType ( fd ) ;
62- if ( type === 'PIPE' ) return new Pipe ( ) ;
63- if ( type === 'TCP' ) return new TCP ( ) ;
62+ if ( type === 'PIPE' ) {
63+ return new Pipe (
64+ is_server ? PipeConstants . SERVER : PipeConstants . SOCKET
65+ ) ;
66+ }
67+
68+ if ( type === 'TCP' ) {
69+ return new TCP (
70+ is_server ? TCPConstants . SERVER : TCPConstants . SOCKET
71+ ) ;
72+ }
73+
6474throw new errors . TypeError ( 'ERR_INVALID_FD_TYPE' , type ) ;
6575}
6676
@@ -200,7 +210,7 @@ function Socket(options){
200210this . _handle = options . handle ; // private
201211this [ async_id_symbol ] = getNewAsyncId ( this . _handle ) ;
202212} else if ( options . fd !== undefined ) {
203- this . _handle = createHandle ( options . fd ) ;
213+ this . _handle = createHandle ( options . fd , false ) ;
204214this . _handle . open ( options . fd ) ;
205215this [ async_id_symbol ] = this . _handle . getAsyncId ( ) ;
206216// options.fd can be string (since it is user-defined),
@@ -1009,7 +1019,9 @@ Socket.prototype.connect = function(...args){
10091019debug ( 'pipe' , pipe , path ) ;
10101020
10111021if ( ! this . _handle ) {
1012- this . _handle = pipe ? new Pipe ( ) : new TCP ( ) ;
1022+ this . _handle = pipe ?
1023+ new Pipe ( PipeConstants . SOCKET ) :
1024+ new TCP ( TCPConstants . SOCKET ) ;
10131025initSocketHandle ( this ) ;
10141026}
10151027
@@ -1269,7 +1281,7 @@ function createServerHandle(address, port, addressType, fd){
12691281var isTCP = false ;
12701282if ( typeof fd === 'number' && fd >= 0 ) {
12711283try {
1272- handle = createHandle ( fd ) ;
1284+ handle = createHandle ( fd , true ) ;
12731285} catch ( e ) {
12741286// Not a fd we can listen on. This will trigger an error.
12751287debug ( 'listen invalid fd=%d:' , fd , e . message ) ;
@@ -1280,15 +1292,15 @@ function createServerHandle(address, port, addressType, fd){
12801292handle . writable = true ;
12811293assert ( ! address && ! port ) ;
12821294} else if ( port === - 1 && addressType === - 1 ) {
1283- handle = new Pipe ( ) ;
1295+ handle = new Pipe ( PipeConstants . SERVER ) ;
12841296if ( process . platform === 'win32' ) {
12851297var instances = parseInt ( process . env . NODE_PENDING_PIPE_INSTANCES ) ;
12861298if ( ! isNaN ( instances ) ) {
12871299handle . setPendingInstances ( instances ) ;
12881300}
12891301}
12901302} else {
1291- handle = new TCP ( ) ;
1303+ handle = new TCP ( TCPConstants . SERVER ) ;
12921304isTCP = true ;
12931305}
12941306
0 commit comments