@@ -37,8 +37,8 @@ const {
37
37
38
38
const { Buffer } = require ( 'buffer' ) ;
39
39
const 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' ) ;
42
42
const { TCPConnectWrap } = process . binding ( 'tcp_wrap' ) ;
43
43
const { PipeConnectWrap } = process . binding ( 'pipe_wrap' ) ;
44
44
const { ShutdownWrap, WriteWrap } = process . binding ( 'stream_wrap' ) ;
@@ -57,10 +57,20 @@ const exceptionWithHostPort = util._exceptionWithHostPort;
57
57
58
58
function noop ( ) { }
59
59
60
- function createHandle ( fd ) {
60
+ function createHandle ( fd , is_server ) {
61
61
const 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
+
64
74
throw new errors . TypeError ( 'ERR_INVALID_FD_TYPE' , type ) ;
65
75
}
66
76
@@ -200,7 +210,7 @@ function Socket(options) {
200
210
this . _handle = options . handle ; // private
201
211
this [ async_id_symbol ] = getNewAsyncId ( this . _handle ) ;
202
212
} else if ( options . fd !== undefined ) {
203
- this . _handle = createHandle ( options . fd ) ;
213
+ this . _handle = createHandle ( options . fd , false ) ;
204
214
this . _handle . open ( options . fd ) ;
205
215
this [ async_id_symbol ] = this . _handle . getAsyncId ( ) ;
206
216
// options.fd can be string (since it is user-defined),
@@ -1009,7 +1019,9 @@ Socket.prototype.connect = function(...args) {
1009
1019
debug ( 'pipe' , pipe , path ) ;
1010
1020
1011
1021
if ( ! this . _handle ) {
1012
- this . _handle = pipe ? new Pipe ( ) : new TCP ( ) ;
1022
+ this . _handle = pipe ?
1023
+ new Pipe ( PipeConstants . SOCKET ) :
1024
+ new TCP ( TCPConstants . SOCKET ) ;
1013
1025
initSocketHandle ( this ) ;
1014
1026
}
1015
1027
@@ -1269,7 +1281,7 @@ function createServerHandle(address, port, addressType, fd) {
1269
1281
var isTCP = false ;
1270
1282
if ( typeof fd === 'number' && fd >= 0 ) {
1271
1283
try {
1272
- handle = createHandle ( fd ) ;
1284
+ handle = createHandle ( fd , true ) ;
1273
1285
} catch ( e ) {
1274
1286
// Not a fd we can listen on. This will trigger an error.
1275
1287
debug ( 'listen invalid fd=%d:' , fd , e . message ) ;
@@ -1280,15 +1292,15 @@ function createServerHandle(address, port, addressType, fd) {
1280
1292
handle . writable = true ;
1281
1293
assert ( ! address && ! port ) ;
1282
1294
} else if ( port === - 1 && addressType === - 1 ) {
1283
- handle = new Pipe ( ) ;
1295
+ handle = new Pipe ( PipeConstants . SERVER ) ;
1284
1296
if ( process . platform === 'win32' ) {
1285
1297
var instances = parseInt ( process . env . NODE_PENDING_PIPE_INSTANCES ) ;
1286
1298
if ( ! isNaN ( instances ) ) {
1287
1299
handle . setPendingInstances ( instances ) ;
1288
1300
}
1289
1301
}
1290
1302
} else {
1291
- handle = new TCP ( ) ;
1303
+ handle = new TCP ( TCPConstants . SERVER ) ;
1292
1304
isTCP = true ;
1293
1305
}
1294
1306
0 commit comments