Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions lib/protocol/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,49 @@ Window.prototype.resume = function (block){
//Ignore invalid acks (duplicates included) only when the window doesn't
//rollover
if (!this._mayRollover &&
(block < this._start - 1 || block > this._end)) return;
(block < this._start || block > this._end)) return;

if (this._mayRollover &&
(block < this._start && block > this._end)) return;

this._writerTimer.reset ();

if (block !== this._end){
//Not all the blocks has been received in the server
if (block === this._start - 1){
//The whole window must be send again
this._writerTimer.start (this._restransmitterSendFn);
this._blocks.forEach (this._sendFn);
}else{
//Remove the blocks already received and shift the window
while (this._blocks[0].block !== block){
this._blocks.shift ();
}
this._blocks.shift ();
}
}else{

while ( ((this._blocks[0].block <= block) ||
(this._mayRollover && (this._blocks[0].block >= block))) &&
(this._blocks.length >1)){
this._blocks.shift ();
}
}else
{
this._blocks = [];
}

this._start = block + 1;
//Update the window
this._start = this._block + 1;
if (this._start === 65536){
this._start = this._rollover;
this._mayRollover = false;
}else{
this._mayRollover = true;
}
this._end = this._block + this._windowSize;
this._end = block + this._windowSize;
if (this._end > 65535){
this._end -= 65535 + this._rolloverFix;
this._end -= 65536 + this._rollover;
}else{
this._mayRollover = false;
}

this._pending = this._windowSize;
this._pending = this._windowSize - this._blocks.length;
var cb = this._cb;
this._cb = null;
cb ();
};
if (this._pending) {
this._cb = null;
cb ();
}
else {
this._writerTimer.start (this._restransmitterSendFn);
this._blocks.forEach (this._sendFn);

}
};