From 8d6ab3eaf67f2ef6dbf160a551b2f8a1ff9f6683 Mon Sep 17 00:00:00 2001 From: John Kristian Date: Tue, 11 Jun 2024 15:47:05 -0700 Subject: [PATCH] Beautify the code. --- raw.js | 2 +- server.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/raw.js b/raw.js index ccd64b4..8aea960 100644 --- a/raw.js +++ b/raw.js @@ -104,7 +104,7 @@ class RawSocket extends Stream.Duplex { this.log.trace('< %j', packet); this.isReading = this.push(packet); } else { - this.log.debug('buffer overflow %s', guts.getFrameSummary(frame)); + this.log.debug('receive buffer overflow %s', guts.getFrameSummary(frame)); } } catch(err) { this.log.debug('onFrameFromAGW(%s)', guts.getFrameSummary(frame)); diff --git a/server.js b/server.js index 6c563a3..adb223e 100644 --- a/server.js +++ b/server.js @@ -335,7 +335,7 @@ class Throttle extends Stream.Writable { sender.on('notFull', function() { that.sendBuffer(); }); - this.on('close', function() {that._closed = true;}); + this.once('close', function() {that.isClosed = true;}); this.on('pipe', function(from) { that.log.trace('pipe from %s', from.constructor.name); }); @@ -434,7 +434,7 @@ class Throttle extends Stream.Writable { _destroy(err, callback) { this.log.debug('_destroy(%s, %s)', err || '', typeof callback); - if (!this._closed) this.emit('close'); + if (!this.isClosed) this.emit('close'); if (callback) callback(); } } // Throttle @@ -719,8 +719,8 @@ class Connection extends Stream.Duplex { this.remoteAddress = toAGW.theirCall; this._pushable = false; const that = this; - this.on('end', function() {that._ended = true;}); - this.on('close', function() {that._closed = true;}); + this.once('end', function() {that.isEnded = true;}); + this.once('close', function() {that.isClosed = true;}); this.on('pipe', function(from) { that.log.trace('pipe from %s', from.constructor.name); }); @@ -740,7 +740,7 @@ class Connection extends Stream.Duplex { this.destroy(); break; case 'D': // data - if (this._closed) { + if (this.isClosed) { this.emit('error', newError('received data after close ' + getDataSummary(frame.data))); } else if (!this._pushable) { @@ -776,8 +776,8 @@ class Connection extends Stream.Duplex { // The documentation seems to say this.destroy() should emit // 'end' and 'close', but I find that doesn't always happen. // This works reliably: - if (!this._ended) this.emit('end'); - if (!this._closed) this.emit('close'); + if (!this.isEnded) this.emit('end'); + if (!this.isClosed) this.emit('close'); if (callback) callback(err); }