@@ -62,9 +62,9 @@ function isPipeName(s) {
62
62
return typeof s === 'string' && toNumber ( s ) === false ;
63
63
}
64
64
65
- exports . createServer = function ( options , connectionListener ) {
65
+ function createServer ( options , connectionListener ) {
66
66
return new Server ( options , connectionListener ) ;
67
- } ;
67
+ }
68
68
69
69
70
70
// Target API:
@@ -79,7 +79,7 @@ exports.createServer = function(options, connectionListener) {
79
79
// connect(port, [host], [cb])
80
80
// connect(path, [cb]);
81
81
//
82
- exports . connect = exports . createConnection = function ( ) {
82
+ function connect ( ) {
83
83
const args = new Array ( arguments . length ) ;
84
84
for ( var i = 0 ; i < arguments . length ; i ++ )
85
85
args [ i ] = arguments [ i ] ;
@@ -95,7 +95,7 @@ exports.connect = exports.createConnection = function() {
95
95
}
96
96
97
97
return Socket . prototype . connect . call ( socket , options , cb ) ;
98
- } ;
98
+ }
99
99
100
100
101
101
// Returns an array [options, cb], where options is an object,
@@ -135,7 +135,6 @@ function normalizeArgs(args) {
135
135
else
136
136
return [ options , cb ] ;
137
137
}
138
- exports . _normalizeArgs = normalizeArgs ;
139
138
140
139
141
140
// called when creating new Socket, or when re-using a closed Socket
@@ -333,9 +332,6 @@ function writeAfterFIN(chunk, encoding, cb) {
333
332
}
334
333
}
335
334
336
- exports . Socket = Socket ;
337
- exports . Stream = Socket ; // Legacy naming.
338
-
339
335
Socket . prototype . read = function ( n ) {
340
336
if ( n === 0 )
341
337
return stream . Readable . prototype . read . call ( this , n ) ;
@@ -850,7 +846,8 @@ function afterWrite(status, handle, req, err) {
850
846
}
851
847
852
848
853
- function connect ( self , address , port , addressType , localAddress , localPort ) {
849
+ function internalConnect (
850
+ self , address , port , addressType , localAddress , localPort ) {
854
851
// TODO return promise from Socket.prototype.connect which
855
852
// wraps _connectReq.
856
853
@@ -964,7 +961,7 @@ Socket.prototype.connect = function() {
964
961
this . writable = true ;
965
962
966
963
if ( pipe ) {
967
- connect ( this , options . path ) ;
964
+ internalConnect ( this , options . path ) ;
968
965
} else {
969
966
lookupAndConnect ( this , options ) ;
970
967
}
@@ -979,7 +976,7 @@ function lookupAndConnect(self, options) {
979
976
var localAddress = options . localAddress ;
980
977
var localPort = options . localPort ;
981
978
982
- if ( localAddress && ! exports . isIP ( localAddress ) )
979
+ if ( localAddress && ! cares . isIP ( localAddress ) )
983
980
throw new TypeError ( '"localAddress" option must be a valid IP: ' +
984
981
localAddress ) ;
985
982
@@ -996,11 +993,11 @@ function lookupAndConnect(self, options) {
996
993
port |= 0 ;
997
994
998
995
// If host is an IP, skip performing a lookup
999
- var addressType = exports . isIP ( host ) ;
996
+ var addressType = cares . isIP ( host ) ;
1000
997
if ( addressType ) {
1001
998
process . nextTick ( function ( ) {
1002
999
if ( self . connecting )
1003
- connect ( self , host , port , addressType , localAddress , localPort ) ;
1000
+ internalConnect ( self , host , port , addressType , localAddress , localPort ) ;
1004
1001
} ) ;
1005
1002
return ;
1006
1003
}
@@ -1040,12 +1037,12 @@ function lookupAndConnect(self, options) {
1040
1037
process . nextTick ( connectErrorNT , self , err ) ;
1041
1038
} else {
1042
1039
self . _unrefTimer ( ) ;
1043
- connect ( self ,
1044
- ip ,
1045
- port ,
1046
- addressType ,
1047
- localAddress ,
1048
- localPort ) ;
1040
+ internalConnect ( self ,
1041
+ ip ,
1042
+ port ,
1043
+ addressType ,
1044
+ localAddress ,
1045
+ localPort ) ;
1049
1046
}
1050
1047
} ) ;
1051
1048
}
@@ -1177,7 +1174,6 @@ function Server(options, connectionListener) {
1177
1174
this . pauseOnConnect = ! ! options . pauseOnConnect ;
1178
1175
}
1179
1176
util . inherits ( Server , EventEmitter ) ;
1180
- exports . Server = Server ;
1181
1177
1182
1178
1183
1179
function toNumber ( x ) { return ( x = Number ( x ) ) >= 0 ? x : false ; }
@@ -1244,7 +1240,6 @@ function createServerHandle(address, port, addressType, fd) {
1244
1240
1245
1241
return handle ;
1246
1242
}
1247
- exports . _createServerHandle = createServerHandle ;
1248
1243
1249
1244
1250
1245
Server . prototype . _listen2 = function ( address , port , addressType , backlog , fd ) {
@@ -1618,20 +1613,12 @@ Server.prototype.unref = function() {
1618
1613
return this ;
1619
1614
} ;
1620
1615
1621
-
1622
- exports . isIP = cares . isIP ;
1623
-
1624
-
1625
- exports . isIPv4 = cares . isIPv4 ;
1626
-
1627
-
1628
- exports . isIPv6 = cares . isIPv6 ;
1629
-
1616
+ var _setSimultaneousAccepts ;
1630
1617
1631
1618
if ( process . platform === 'win32' ) {
1632
1619
var simultaneousAccepts ;
1633
1620
1634
- exports . _setSimultaneousAccepts = function ( handle ) {
1621
+ _setSimultaneousAccepts = function ( handle ) {
1635
1622
if ( handle === undefined ) {
1636
1623
return ;
1637
1624
}
@@ -1647,5 +1634,20 @@ if (process.platform === 'win32') {
1647
1634
}
1648
1635
} ;
1649
1636
} else {
1650
- exports . _setSimultaneousAccepts = function ( handle ) { } ;
1637
+ _setSimultaneousAccepts = function ( handle ) { } ;
1651
1638
}
1639
+
1640
+ module . exports = {
1641
+ _createServerHandle : createServerHandle ,
1642
+ _normalizeArgs : normalizeArgs ,
1643
+ _setSimultaneousAccepts,
1644
+ connect,
1645
+ createConnection : connect ,
1646
+ createServer,
1647
+ isIP : cares . isIP ,
1648
+ isIPv4 : cares . isIPv4 ,
1649
+ isIPv6 : cares . isIPv6 ,
1650
+ Server,
1651
+ Socket,
1652
+ Stream : Socket , // Legacy naming
1653
+ } ;
0 commit comments