@@ -162,7 +162,7 @@ class Connection extends EventEmitter {
162162 this . queue = [ ] ;
163163
164164 // Internal state
165- this . connection = null ;
165+ this . socket = null ;
166166 this . writeStream = null ;
167167
168168 // Create hash method
@@ -175,14 +175,14 @@ class Connection extends EventEmitter {
175175 }
176176
177177 setSocketTimeout ( value ) {
178- if ( this . connection ) {
179- this . connection . setTimeout ( value ) ;
178+ if ( this . socket ) {
179+ this . socket . setTimeout ( value ) ;
180180 }
181181 }
182182
183183 resetSocketTimeout ( ) {
184- if ( this . connection ) {
185- this . connection . setTimeout ( this . socketTimeout ) ;
184+ if ( this . socket ) {
185+ this . socket . setTimeout ( this . socketTimeout ) ;
186186 }
187187 }
188188
@@ -237,11 +237,11 @@ class Connection extends EventEmitter {
237237 }
238238
239239 // clean up existing event handlers
240- this . connection . removeAllListeners ( 'error' ) ;
241- this . connection . removeAllListeners ( 'timeout' ) ;
242- this . connection . removeAllListeners ( 'close' ) ;
243- this . connection . removeAllListeners ( 'data' ) ;
244- this . connection = undefined ;
240+ this . socket . removeAllListeners ( 'error' ) ;
241+ this . socket . removeAllListeners ( 'timeout' ) ;
242+ this . socket . removeAllListeners ( 'close' ) ;
243+ this . socket . removeAllListeners ( 'data' ) ;
244+ this . socket = undefined ;
245245
246246 return doConnect ( this , 4 , _options , _errorHandler ) ;
247247 } ) ;
@@ -253,28 +253,30 @@ class Connection extends EventEmitter {
253253 * @return {boolean }
254254 */
255255 unref ( ) {
256- if ( this . connection == null ) {
257- this . once ( 'connect' , ( ) => this . connection . unref ( ) ) ;
256+ if ( this . socket == null ) {
257+ this . once ( 'connect' , ( ) => this . socket . unref ( ) ) ;
258258 return ;
259259 }
260260
261- this . connection . unref ( ) ;
261+ this . socket . unref ( ) ;
262262 }
263263
264264 /**
265265 * Destroy connection
266266 * @method
267267 */
268268 destroy ( ) {
269- // Set the connections
270- if ( connectionAccounting ) deleteConnection ( this . id ) ;
271- if ( this . connection ) {
269+ if ( connectionAccounting ) {
270+ deleteConnection ( this . id ) ;
271+ }
272+
273+ if ( this . socket ) {
272274 // Catch posssible exception thrown by node 0.10.x
273275 try {
274- this . connection . end ( ) ;
276+ this . socket . end ( ) ;
275277 } catch ( err ) { } // eslint-disable-line
276- // Destroy connection
277- this . connection . destroy ( ) ;
278+
279+ this . socket . destroy ( ) ;
278280 }
279281
280282 this . destroyed = true ;
@@ -297,16 +299,16 @@ class Connection extends EventEmitter {
297299 }
298300
299301 // Double check that the connection is not destroyed
300- if ( this . connection . destroyed === false ) {
302+ if ( this . socket . destroyed === false ) {
301303 // Write out the command
302304 if ( ! Array . isArray ( buffer ) ) {
303- this . connection . write ( buffer , 'binary' ) ;
305+ this . socket . write ( buffer , 'binary' ) ;
304306 return true ;
305307 }
306308
307309 // Iterate over all buffers and write them in order to the socket
308310 for ( let i = 0 ; i < buffer . length ; i ++ ) {
309- this . connection . write ( buffer [ i ] , 'binary' ) ;
311+ this . socket . write ( buffer [ i ] , 'binary' ) ;
310312 }
311313
312314 return true ;
@@ -341,7 +343,7 @@ class Connection extends EventEmitter {
341343 */
342344 isConnected ( ) {
343345 if ( this . destroyed ) return false ;
344- return ! this . connection . destroyed && this . connection . writable ;
346+ return ! this . socket . destroyed && this . socket . writable ;
345347 }
346348}
347349
@@ -682,7 +684,7 @@ function merge(options1, options2) {
682684
683685function makeSSLConnection ( self , _options ) {
684686 let sslOptions = {
685- socket : self . connection ,
687+ socket : self . socket ,
686688 rejectUnauthorized : self . rejectUnauthorized
687689 } ;
688690
@@ -761,16 +763,14 @@ function makeUnsecureConnection(self, family) {
761763 return connection ;
762764}
763765
764- function doConnect ( self , family , _options , _errorHandler ) {
765- self . connection = self . ssl
766- ? makeSSLConnection ( self , _options )
767- : makeUnsecureConnection ( self , family ) ;
766+ function doConnect ( conn , family , _options , _errorHandler ) {
767+ conn . socket = conn . ssl ? makeSSLConnection ( conn , _options ) : makeUnsecureConnection ( conn , family ) ;
768768
769769 // Add handlers for events
770- self . connection . once ( 'error' , _errorHandler ) ;
771- self . connection . once ( 'timeout' , timeoutHandler ( self ) ) ;
772- self . connection . once ( 'close' , closeHandler ( self ) ) ;
773- self . connection . on ( 'data' , dataHandler ( self ) ) ;
770+ conn . socket . once ( 'error' , _errorHandler ) ;
771+ conn . socket . once ( 'timeout' , timeoutHandler ( conn ) ) ;
772+ conn . socket . once ( 'close' , closeHandler ( conn ) ) ;
773+ conn . socket . on ( 'data' , dataHandler ( conn ) ) ;
774774}
775775
776776/**
0 commit comments