@@ -41,9 +41,9 @@ function isPipeName(s) {
41
41
return typeof s === 'string' && toNumber ( s ) === false ;
42
42
}
43
43
44
- exports . createServer = function ( options , connectionListener ) {
44
+ function createServer ( options , connectionListener ) {
45
45
return new Server ( options , connectionListener ) ;
46
- } ;
46
+ }
47
47
48
48
49
49
// Target API:
@@ -58,7 +58,7 @@ exports.createServer = function(options, connectionListener) {
58
58
// connect(port, [host], [cb])
59
59
// connect(path, [cb]);
60
60
//
61
- exports . connect = exports . createConnection = function ( ) {
61
+ function connect ( ) {
62
62
const args = new Array ( arguments . length ) ;
63
63
for ( var i = 0 ; i < arguments . length ; i ++ )
64
64
args [ i ] = arguments [ i ] ;
@@ -74,7 +74,7 @@ exports.connect = exports.createConnection = function() {
74
74
}
75
75
76
76
return Socket . prototype . connect . call ( socket , options , cb ) ;
77
- } ;
77
+ }
78
78
79
79
80
80
// Returns an array [options, cb], where options is an object,
@@ -114,7 +114,6 @@ function normalizeArgs(args) {
114
114
else
115
115
return [ options , cb ] ;
116
116
}
117
- exports . _normalizeArgs = normalizeArgs ;
118
117
119
118
120
119
// called when creating new Socket, or when re-using a closed Socket
@@ -312,9 +311,6 @@ function writeAfterFIN(chunk, encoding, cb) {
312
311
}
313
312
}
314
313
315
- exports . Socket = Socket ;
316
- exports . Stream = Socket ; // Legacy naming.
317
-
318
314
Socket . prototype . read = function ( n ) {
319
315
if ( n === 0 )
320
316
return stream . Readable . prototype . read . call ( this , n ) ;
@@ -829,7 +825,8 @@ function afterWrite(status, handle, req, err) {
829
825
}
830
826
831
827
832
- function connect ( self , address , port , addressType , localAddress , localPort ) {
828
+ function internalConnect (
829
+ self , address , port , addressType , localAddress , localPort ) {
833
830
// TODO return promise from Socket.prototype.connect which
834
831
// wraps _connectReq.
835
832
@@ -943,7 +940,7 @@ Socket.prototype.connect = function() {
943
940
this . writable = true ;
944
941
945
942
if ( pipe ) {
946
- connect ( this , options . path ) ;
943
+ internalConnect ( this , options . path ) ;
947
944
} else {
948
945
lookupAndConnect ( this , options ) ;
949
946
}
@@ -958,7 +955,7 @@ function lookupAndConnect(self, options) {
958
955
var localAddress = options . localAddress ;
959
956
var localPort = options . localPort ;
960
957
961
- if ( localAddress && ! exports . isIP ( localAddress ) )
958
+ if ( localAddress && ! cares . isIP ( localAddress ) )
962
959
throw new TypeError ( '"localAddress" option must be a valid IP: ' +
963
960
localAddress ) ;
964
961
@@ -975,11 +972,11 @@ function lookupAndConnect(self, options) {
975
972
port |= 0 ;
976
973
977
974
// If host is an IP, skip performing a lookup
978
- var addressType = exports . isIP ( host ) ;
975
+ var addressType = cares . isIP ( host ) ;
979
976
if ( addressType ) {
980
977
process . nextTick ( function ( ) {
981
978
if ( self . connecting )
982
- connect ( self , host , port , addressType , localAddress , localPort ) ;
979
+ internalConnect ( self , host , port , addressType , localAddress , localPort ) ;
983
980
} ) ;
984
981
return ;
985
982
}
@@ -1019,12 +1016,12 @@ function lookupAndConnect(self, options) {
1019
1016
process . nextTick ( connectErrorNT , self , err ) ;
1020
1017
} else {
1021
1018
self . _unrefTimer ( ) ;
1022
- connect ( self ,
1023
- ip ,
1024
- port ,
1025
- addressType ,
1026
- localAddress ,
1027
- localPort ) ;
1019
+ internalConnect ( self ,
1020
+ ip ,
1021
+ port ,
1022
+ addressType ,
1023
+ localAddress ,
1024
+ localPort ) ;
1028
1025
}
1029
1026
} ) ;
1030
1027
}
@@ -1155,7 +1152,6 @@ function Server(options, connectionListener) {
1155
1152
this . pauseOnConnect = ! ! options . pauseOnConnect ;
1156
1153
}
1157
1154
util . inherits ( Server , EventEmitter ) ;
1158
- exports . Server = Server ;
1159
1155
1160
1156
1161
1157
function toNumber ( x ) { return ( x = Number ( x ) ) >= 0 ? x : false ; }
@@ -1222,7 +1218,6 @@ function createServerHandle(address, port, addressType, fd) {
1222
1218
1223
1219
return handle ;
1224
1220
}
1225
- exports . _createServerHandle = createServerHandle ;
1226
1221
1227
1222
1228
1223
Server . prototype . _listen2 = function ( address , port , addressType , backlog , fd ) {
@@ -1595,20 +1590,12 @@ Server.prototype.unref = function() {
1595
1590
return this ;
1596
1591
} ;
1597
1592
1598
-
1599
- exports . isIP = cares . isIP ;
1600
-
1601
-
1602
- exports . isIPv4 = cares . isIPv4 ;
1603
-
1604
-
1605
- exports . isIPv6 = cares . isIPv6 ;
1606
-
1593
+ var _setSimultaneousAccepts ;
1607
1594
1608
1595
if ( process . platform === 'win32' ) {
1609
1596
var simultaneousAccepts ;
1610
1597
1611
- exports . _setSimultaneousAccepts = function ( handle ) {
1598
+ _setSimultaneousAccepts = function ( handle ) {
1612
1599
if ( handle === undefined ) {
1613
1600
return ;
1614
1601
}
@@ -1624,5 +1611,20 @@ if (process.platform === 'win32') {
1624
1611
}
1625
1612
} ;
1626
1613
} else {
1627
- exports . _setSimultaneousAccepts = function ( handle ) { } ;
1614
+ _setSimultaneousAccepts = function ( handle ) { } ;
1628
1615
}
1616
+
1617
+ module . exports = {
1618
+ _createServerHandle : createServerHandle ,
1619
+ _normalizeArgs : normalizeArgs ,
1620
+ _setSimultaneousAccepts,
1621
+ connect,
1622
+ createConnection : connect ,
1623
+ createServer,
1624
+ isIP : cares . isIP ,
1625
+ isIPv4 : cares . isIPv4 ,
1626
+ isIPv6 : cares . isIPv6 ,
1627
+ Server,
1628
+ Socket,
1629
+ Stream : Socket , // Legacy naming
1630
+ } ;
0 commit comments