Fix crash when trying to write to socket

This commit is contained in:
Will Franzen 2014-12-31 12:26:59 -06:00
parent 52078273fe
commit 00241c4044

View file

@ -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) {