@@ -33,8 +33,8 @@ const uv = process.binding('uv');
33
33
34
34
const { Buffer } = require ( 'buffer' ) ;
35
35
const TTYWrap = process . binding ( 'tty_wrap' ) ;
36
- const { TCP } = process . binding ( 'tcp_wrap' ) ;
37
- const { Pipe } = process . binding ( 'pipe_wrap' ) ;
36
+ const { TCP , constants : TCPConstants } = process . binding ( 'tcp_wrap' ) ;
37
+ const { Pipe, constants : PipeConstants } = process . binding ( 'pipe_wrap' ) ;
38
38
const { TCPConnectWrap } = process . binding ( 'tcp_wrap' ) ;
39
39
const { PipeConnectWrap } = process . binding ( 'pipe_wrap' ) ;
40
40
const { ShutdownWrap, WriteWrap } = process . binding ( 'stream_wrap' ) ;
@@ -53,10 +53,20 @@ const exceptionWithHostPort = util._exceptionWithHostPort;
53
53
54
54
function noop ( ) { }
55
55
56
- function createHandle ( fd ) {
57
- var type = TTYWrap . guessHandleType ( fd ) ;
58
- if ( type === 'PIPE' ) return new Pipe ( ) ;
59
- if ( type === 'TCP' ) return new TCP ( ) ;
56
+ function createHandle ( fd , is_server ) {
57
+ const type = TTYWrap . guessHandleType ( fd ) ;
58
+ if ( type === 'PIPE' ) {
59
+ return new Pipe (
60
+ is_server ? PipeConstants . SERVER : PipeConstants . SOCKET
61
+ ) ;
62
+ }
63
+
64
+ if ( type === 'TCP' ) {
65
+ return new TCP (
66
+ is_server ? TCPConstants . SERVER : TCPConstants . SOCKET
67
+ ) ;
68
+ }
69
+
60
70
throw new TypeError ( 'Unsupported fd type: ' + type ) ;
61
71
}
62
72
@@ -196,7 +206,7 @@ function Socket(options) {
196
206
this . _handle = options . handle ; // private
197
207
this [ async_id_symbol ] = getNewAsyncId ( this . _handle ) ;
198
208
} else if ( options . fd !== undefined ) {
199
- this . _handle = createHandle ( options . fd ) ;
209
+ this . _handle = createHandle ( options . fd , false ) ;
200
210
this . _handle . open ( options . fd ) ;
201
211
this [ async_id_symbol ] = this . _handle . getAsyncId ( ) ;
202
212
// options.fd can be string (since it is user-defined),
@@ -1003,7 +1013,9 @@ Socket.prototype.connect = function(...args) {
1003
1013
debug ( 'pipe' , pipe , path ) ;
1004
1014
1005
1015
if ( ! this . _handle ) {
1006
- this . _handle = pipe ? new Pipe ( ) : new TCP ( ) ;
1016
+ this . _handle = pipe ?
1017
+ new Pipe ( PipeConstants . SOCKET ) :
1018
+ new TCP ( TCPConstants . SOCKET ) ;
1007
1019
initSocketHandle ( this ) ;
1008
1020
}
1009
1021
@@ -1253,7 +1265,7 @@ function createServerHandle(address, port, addressType, fd) {
1253
1265
var isTCP = false ;
1254
1266
if ( typeof fd === 'number' && fd >= 0 ) {
1255
1267
try {
1256
- handle = createHandle ( fd ) ;
1268
+ handle = createHandle ( fd , true ) ;
1257
1269
} catch ( e ) {
1258
1270
// Not a fd we can listen on. This will trigger an error.
1259
1271
debug ( 'listen invalid fd=%d:' , fd , e . message ) ;
@@ -1264,15 +1276,15 @@ function createServerHandle(address, port, addressType, fd) {
1264
1276
handle . writable = true ;
1265
1277
assert ( ! address && ! port ) ;
1266
1278
} else if ( port === - 1 && addressType === - 1 ) {
1267
- handle = new Pipe ( ) ;
1279
+ handle = new Pipe ( PipeConstants . SERVER ) ;
1268
1280
if ( process . platform === 'win32' ) {
1269
1281
var instances = parseInt ( process . env . NODE_PENDING_PIPE_INSTANCES ) ;
1270
1282
if ( ! isNaN ( instances ) ) {
1271
1283
handle . setPendingInstances ( instances ) ;
1272
1284
}
1273
1285
}
1274
1286
} else {
1275
- handle = new TCP ( ) ;
1287
+ handle = new TCP ( TCPConstants . SERVER ) ;
1276
1288
isTCP = true ;
1277
1289
}
1278
1290
0 commit comments