Commit 21034f29 authored by Yoann Pigné's avatar Yoann Pigné

dynamically resize the reception bufffer

parent 8867b8ca
...@@ -326,6 +326,17 @@ ...@@ -326,6 +326,17 @@
var nbytes = 0; var nbytes = 0;
// Number of bytes this.read. // Number of bytes this.read.
nbytes = encodedMsg.length; nbytes = encodedMsg.length;
if(nbytes > this.buffer.byteLength){
if(this.debug){
console.log("resizing buffer size to "+(2*nbytes+this.pos)+" bytes");
}
var newb = new ArrayBuffer(2*nbytes+this.pos);
for(var i=0; i< this.pos; i++){
newb[i]=this.buffer[i];
}
delete this.buffer;
this.buffer=newb;
}
var encodedArray = new Uint8Array(this.buffer, this.pos, nbytes); var encodedArray = new Uint8Array(this.buffer, this.pos, nbytes);
for (var i = 0; i < nbytes; i++) { for (var i = 0; i < nbytes; i++) {
encodedArray[i] = encodedMsg.charCodeAt(i); encodedArray[i] = encodedMsg.charCodeAt(i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment