Skip to content

Commit 309e0a6

Browse files
committed
Fix for node14
1 parent b0a2fe4 commit 309e0a6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/connection.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@ var Connection = function(config) {
5656
self._emitMessage = true;
5757
}
5858
});
59+
60+
this._connected = false;
5961
};
6062

6163
util.inherits(Connection, EventEmitter);
6264

6365
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) {
6671
this.stream.connect(port, host);
67-
} else if(this.stream.readyState == 'open') {
6872
this.emit('connect');
6973
}
7074

@@ -90,6 +94,7 @@ Connection.prototype.connect = function(port, host) {
9094
// NOTE: node-0.10 emits both 'end' and 'close'
9195
// for streams closed by the peer, while
9296
// node-0.8 only emits 'close'
97+
this._connected = false;
9398
self.emit('end');
9499
});
95100

@@ -332,11 +337,13 @@ Connection.prototype.end = function() {
332337
//0x58 = 'X'
333338
this.writer.add(emptyBuffer);
334339
this._ending = true;
340+
this._connected = false;
335341
this._send(0x58);
336342
};
337343

338344
Connection.prototype.close = function(msg, more) {
339345
this.writer.addCString(msg.type + (msg.name || ''));
346+
this._connected = false;
340347
this._send(0x43, more);
341348
};
342349

0 commit comments

Comments
 (0)