@ -785,34 +785,18 @@ function connect(self, address, port, addressType, localAddress, localPort) {
assert . ok ( self . _ connecting ) ;
var err ;
if ( localAddress || localPort ) {
if ( localAddress && ! exports . isIP ( localAddress ) )
err = new TypeError (
'localAddress should be a valid IP: ' + localAddress ) ;
if ( localPort && ! util . isNumber ( localPort ) )
err = new TypeError ( 'localPort should be a number: ' + localPort ) ;
if ( localAddress || localPort ) {
var bind ;
switch ( addressType ) {
case 4 :
if ( ! localAddress )
localAddress = '0.0.0.0' ;
bind = self . _ handle . bind ;
break ;
case 6 :
if ( ! localAddress )
localAddress = '::' ;
bind = self . _ handle . bind6 ;
break ;
default :
err = new TypeError ( 'Invalid addressType: ' + addressType ) ;
break ;
}
if ( err ) {
self . _ destroy ( err ) ;
if ( addressType === 4 ) {
localAddress = localAddress || '0.0.0.0' ;
bind = self . _ handle . bind ;
} else if ( addressType === 6 ) {
localAddress = localAddress || '::' ;
bind = self . _ handle . bind6 ;
} else {
self . _ destroy ( new TypeError ( 'Invalid addressType: ' + addressType ) ) ;
return ;
}
@ -832,15 +816,12 @@ function connect(self, address, port, addressType, localAddress, localPort) {
if ( addressType === 6 || addressType === 4 ) {
var req = new TCPConnectWrap ( ) ;
req . oncomplete = afterConnect ;
port = port | 0 ;
if ( port <= 0 || port > 65535 )
throw new RangeError ( 'Port should be > 0 and < 65536' ) ;
if ( addressType === 6 ) {
err = self . _ handle . connect6 ( req , address , port ) ;
} else if ( addressType === 4 ) {
if ( addressType === 4 )
err = self . _ handle . connect ( req , address , port ) ;
}
else
err = self . _ handle . connect6 ( req , address , port ) ;
} else {
var req = new PipeConnectWrap ( ) ;
req . oncomplete = afterConnect ;
@ -898,19 +879,26 @@ Socket.prototype.connect = function(options, cb) {
if ( pipe ) {
connect ( self , options . path ) ;
} else if ( ! options . host ) {
debug ( 'connect: missing host' ) ;
self . _ host = '127.0.0.1' ;
connect ( self , self . _ host , options . port , 4 ) ;
} else {
var dns = require ( 'dns' ) ;
var host = options . host ;
var host = options . host || 'localhost' ;
var port = options . port | 0 ;
var localAddress = options . localAddress ;
var localPort = options . localPort ;
var dnsopts = {
family : options . family ,
hints : 0
} ;
if ( localAddress && ! exports . isIP ( localAddress ) )
throw new TypeError ( 'localAddress must be a valid IP: ' + localAddress ) ;
if ( localPort && ! util . isNumber ( localPort ) )
throw new TypeError ( 'localPort should be a number: ' + localPort ) ;
if ( port <= 0 || port > 65535 )
throw new RangeError ( 'port should be > 0 and < 65536: ' + port ) ;
if ( dnsopts . family !== 4 && dnsopts . family !== 6 )
dnsopts . hints = dns . ADDRCONFIG | dns . V4MAPPED ;
@ -936,19 +924,12 @@ Socket.prototype.connect = function(options, cb) {
} ) ;
} else {
timers . _ unrefActive ( self ) ;
addressType = addressType || 4 ;
// node_net.cc handles null host names graciously but user land
// expects remoteAddress to have a meaningful value
ip = ip || ( addressType === 4 ? '127.0.0.1' : '0:0:0:0:0:0:0:1' ) ;
connect ( self ,
ip ,
options . port ,
port ,
addressType ,
options . localAddress ,
options . localPort ) ;
localAddress ,
localPort ) ;
}
} ) ;
}