@ -119,7 +119,7 @@ const BYTES_READ = Symbol('bytesRead');
function Socket ( options ) {
function Socket ( options ) {
if ( ! ( this instanceof Socket ) ) return new Socket ( options ) ;
if ( ! ( this instanceof Socket ) ) return new Socket ( options ) ;
this . _ connecting = false ;
this . connecting = false ;
this . _ hadError = false ;
this . _ hadError = false ;
this . _ handle = null ;
this . _ handle = null ;
this . _ parent = null ;
this . _ parent = null ;
@ -202,7 +202,7 @@ Socket.prototype._unrefTimer = function unrefTimer() {
// so that only the writable side will be cleaned up.
// so that only the writable side will be cleaned up.
function onSocketFinish ( ) {
function onSocketFinish ( ) {
// If still connecting - defer handling 'finish' until 'connect' will happen
// If still connecting - defer handling 'finish' until 'connect' will happen
if ( this . _ connecting ) {
if ( this . connecting ) {
debug ( 'osF: not yet connected' ) ;
debug ( 'osF: not yet connected' ) ;
return this . once ( 'connect' , onSocketFinish ) ;
return this . once ( 'connect' , onSocketFinish ) ;
}
}
@ -367,9 +367,16 @@ Socket.prototype.address = function() {
} ;
} ;
Object . defineProperty ( Socket . prototype , '_connecting' , {
get : function ( ) {
return this . connecting ;
}
} ) ;
Object . defineProperty ( Socket . prototype , 'readyState' , {
Object . defineProperty ( Socket . prototype , 'readyState' , {
get : function ( ) {
get : function ( ) {
if ( this . _ connecting ) {
if ( this . connecting ) {
return 'opening' ;
return 'opening' ;
} else if ( this . readable && this . writable ) {
} else if ( this . readable && this . writable ) {
return 'open' ;
return 'open' ;
@ -397,7 +404,7 @@ Object.defineProperty(Socket.prototype, 'bufferSize', {
Socket . prototype . _ read = function ( n ) {
Socket . prototype . _ read = function ( n ) {
debug ( '_read' ) ;
debug ( '_read' ) ;
if ( this . _ connecting || ! this . _ handle ) {
if ( this . connecting || ! this . _ handle ) {
debug ( '_read wait for connection' ) ;
debug ( '_read wait for connection' ) ;
this . once ( 'connect' , ( ) => this . _ read ( n ) ) ;
this . once ( 'connect' , ( ) => this . _ read ( n ) ) ;
} else if ( ! this . _ handle . reading ) {
} else if ( ! this . _ handle . reading ) {
@ -430,7 +437,7 @@ function maybeDestroy(socket) {
if ( ! socket . readable &&
if ( ! socket . readable &&
! socket . writable &&
! socket . writable &&
! socket . destroyed &&
! socket . destroyed &&
! socket . _ connecting &&
! socket . connecting &&
! socket . _ writableState . length ) {
! socket . _ writableState . length ) {
socket . destroy ( ) ;
socket . destroy ( ) ;
}
}
@ -465,7 +472,7 @@ Socket.prototype._destroy = function(exception, cb) {
return ;
return ;
}
}
this . _ connecting = false ;
this . connecting = false ;
this . readable = this . writable = false ;
this . readable = this . writable = false ;
@ -648,7 +655,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
// If we are still connecting, then buffer this for later.
// If we are still connecting, then buffer this for later.
// The Writable logic will buffer up any more writes while
// The Writable logic will buffer up any more writes while
// waiting for this one to be done.
// waiting for this one to be done.
if ( this . _ connecting ) {
if ( this . connecting ) {
this . _ pendingData = data ;
this . _ pendingData = data ;
this . _ pendingEncoding = encoding ;
this . _ pendingEncoding = encoding ;
this . once ( 'connect' , function ( ) {
this . once ( 'connect' , function ( ) {
@ -803,7 +810,7 @@ function connect(self, address, port, addressType, localAddress, localPort) {
// TODO return promise from Socket.prototype.connect which
// TODO return promise from Socket.prototype.connect which
// wraps _connectReq.
// wraps _connectReq.
assert . ok ( self . _ connecting ) ;
assert . ok ( self . connecting ) ;
var err ;
var err ;
@ -913,7 +920,7 @@ Socket.prototype.connect = function(options, cb) {
this . _ unrefTimer ( ) ;
this . _ unrefTimer ( ) ;
this . _ connecting = true ;
this . connecting = true ;
this . writable = true ;
this . writable = true ;
if ( pipe ) {
if ( pipe ) {
@ -952,7 +959,7 @@ function lookupAndConnect(self, options) {
var addressType = exports . isIP ( host ) ;
var addressType = exports . isIP ( host ) ;
if ( addressType ) {
if ( addressType ) {
process . nextTick ( function ( ) {
process . nextTick ( function ( ) {
if ( self . _ connecting )
if ( self . connecting )
connect ( self , host , port , addressType , localAddress , localPort ) ;
connect ( self , host , port , addressType , localAddress , localPort ) ;
} ) ;
} ) ;
return ;
return ;
@ -980,7 +987,7 @@ function lookupAndConnect(self, options) {
// It's possible we were destroyed while looking this up.
// It's possible we were destroyed while looking this up.
// XXX it would be great if we could cancel the promise returned by
// XXX it would be great if we could cancel the promise returned by
// the look up.
// the look up.
if ( ! self . _ connecting ) return ;
if ( ! self . connecting ) return ;
if ( err ) {
if ( err ) {
// net.createConnection() creates a net.Socket object and
// net.createConnection() creates a net.Socket object and
@ -1048,8 +1055,8 @@ function afterConnect(status, handle, req, readable, writable) {
debug ( 'afterConnect' ) ;
debug ( 'afterConnect' ) ;
assert . ok ( self . _ connecting ) ;
assert . ok ( self . connecting ) ;
self . _ connecting = false ;
self . connecting = false ;
self . _ sockname = null ;
self . _ sockname = null ;
if ( status == 0 ) {
if ( status == 0 ) {
@ -1065,7 +1072,7 @@ function afterConnect(status, handle, req, readable, writable) {
self . read ( 0 ) ;
self . read ( 0 ) ;
} else {
} else {
self . _ connecting = false ;
self . connecting = false ;
var details ;
var details ;
if ( req . localAddress && req . localPort ) {
if ( req . localAddress && req . localPort ) {
details = req . localAddress + ':' + req . localPort ;
details = req . localAddress + ':' + req . localPort ;