Permalink
Browse files

cleaned up send buffer

  • Loading branch information...
1 parent 8e912a2 commit 563dac191c61ca5656f4e64e24d661a88ec5b432 @einaros einaros committed Dec 13, 2011
Showing with 3 additions and 7 deletions.
  1. +3 −7 lib/Sender.js
View
@@ -35,6 +35,7 @@ var writeUInt32BE = !isNodeV4
function Sender (socket, config) {
this._sendCacheSize = (config && config.SendBufferCacheSize) ? config.SendBufferCacheSize : 65536;
+ this._sendCache = new Buffer(this._sendCacheSize);
this._socket = socket;
this.firstFragment = true;
}
@@ -125,11 +126,6 @@ Sender.prototype.send = function(data, options, cb) {
if (typeof cb == 'function') cb(e);
else this.emit('error', e);
}
- finally {
- if (this._sendCache && this._sendCache.length > this._sendCacheSize) {
- this._sendCache = null;
- }
- }
}
/**
@@ -154,8 +150,8 @@ Sender.prototype.frameData = function(opcode, data, finalFragment, maskData) {
dataOffset += 2;
secondByte = 126;
}
- var outputBuffer = (this._sendCache && this._sendCache.length >= dataLength + dataOffset)
- ? this._sendCache : (this._sendCache = new Buffer(dataLength + dataOffset));
+ var outputBuffer = (this._sendCache && dataLength + dataOffset <= this._sendCacheSize)
+ ? this._sendCache : new Buffer(dataLength + dataOffset);
if (finalFragment) opcode = opcode | 0x80;
outputBuffer[0] = opcode;
switch (secondByte) {

0 comments on commit 563dac1

Please sign in to comment.