@@ -56,15 +56,19 @@ var Connection = function(config) {
56
56
self . _emitMessage = true ;
57
57
}
58
58
} ) ;
59
+
60
+ this . _connected = false ;
59
61
} ;
60
62
61
63
util . inherits ( Connection , EventEmitter ) ;
62
64
63
65
Connection . prototype . connect = function ( port , host ) {
64
-
65
- if ( this . stream . readyState === 'closed' ) {
66
+ // Old info regarding readyState https://github.com/nodejs/node-v0.x-archive/issues/1752
67
+ // this previously checked for this.stream.readyState === 'open'
68
+ // however when upgrading to node 14 - LTS readyState was always open
69
+ // which prevented code that connected from being called
70
+ if ( port && host ) {
66
71
this . stream . connect ( port , host ) ;
67
- } else if ( this . stream . readyState == 'open' ) {
68
72
this . emit ( 'connect' ) ;
69
73
}
70
74
@@ -90,6 +94,7 @@ Connection.prototype.connect = function(port, host) {
90
94
// NOTE: node-0.10 emits both 'end' and 'close'
91
95
// for streams closed by the peer, while
92
96
// node-0.8 only emits 'close'
97
+ this . _connected = false ;
93
98
self . emit ( 'end' ) ;
94
99
} ) ;
95
100
@@ -332,11 +337,13 @@ Connection.prototype.end = function() {
332
337
//0x58 = 'X'
333
338
this . writer . add ( emptyBuffer ) ;
334
339
this . _ending = true ;
340
+ this . _connected = false ;
335
341
this . _send ( 0x58 ) ;
336
342
} ;
337
343
338
344
Connection . prototype . close = function ( msg , more ) {
339
345
this . writer . addCString ( msg . type + ( msg . name || '' ) ) ;
346
+ this . _connected = false ;
340
347
this . _send ( 0x43 , more ) ;
341
348
} ;
342
349
0 commit comments