From 00241c4044f5fde1ae20e7302bfd9a723c0f201e Mon Sep 17 00:00:00 2001 From: Will Franzen Date: Wed, 31 Dec 2014 12:26:59 -0600 Subject: [PATCH] Fix crash when trying to write to socket --- lib/client.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index c9f20dd..c4a9171 100644 --- a/lib/client.js +++ b/lib/client.js @@ -155,13 +155,15 @@ Client.prototype.write = function(packetId, params) { packetId = packetId[1]; } + var that = this; + // TODO: Which comes first, encryption or compression? var finishWriting = function(buffer) { debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")"); debug(params); var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; - this.socket.write(out); + that.socket.write(out); return true; } @@ -179,9 +181,11 @@ Client.prototype.writeRaw = function(buffer, shouldEncrypt) { shouldEncrypt = true; } + var that = this; + var finishWriting = function(buffer) { var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; - this.socket.write(out); + that.socket.write(out); }; if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {