Add getters/setter to websock

This commit is contained in:
Juanjo Diaz
2018-12-08 17:31:20 +02:00
parent 18439b0680
commit 8a189a6291
7 changed files with 72 additions and 84 deletions

View File

@@ -32,8 +32,8 @@ export default class HextileDecoder {
return false;
}
let rQ = sock.get_rQ();
let rQi = sock.get_rQi();
let rQ = sock.rQ;
let rQi = sock.rQi;
let subencoding = rQ[rQi]; // Peek
if (subencoding > 30) { // Raw
@@ -129,7 +129,6 @@ export default class HextileDecoder {
}
display.finishTile();
}
sock.set_rQi(rQi);
this._lastsubencoding = subencoding;
this._tiles--;
}

View File

@@ -28,9 +28,9 @@ export default class RawDecoder {
const cur_y = y + (height - this._lines);
const curr_height = Math.min(this._lines,
Math.floor(sock.rQlen() / bytesPerLine));
let data = sock.get_rQ();
let index = sock.get_rQi();
Math.floor(sock.rQlen / bytesPerLine));
let data = sock.rQ;
let index = sock.rQi;
// Convert data if needed
if (depth == 8) {

View File

@@ -78,8 +78,8 @@ export default class TightDecoder {
return false;
}
const rQi = sock.get_rQi();
const rQ = sock.rQwhole();
const rQi = sock.rQi;
const rQ = sock.rQ;
display.fillRect(x, y, width, height,
[rQ[rQi + 2], rQ[rQi + 1], rQ[rQi]], false);

View File

@@ -681,7 +681,7 @@ export default class RFB extends EventTargetMixin {
}
_handle_message() {
if (this._sock.rQlen() === 0) {
if (this._sock.rQlen === 0) {
Log.Warn("handle_message called on an empty receive queue");
return;
}
@@ -698,7 +698,7 @@ export default class RFB extends EventTargetMixin {
if (!this._normal_msg()) {
break;
}
if (this._sock.rQlen() === 0) {
if (this._sock.rQlen === 0) {
break;
}
}
@@ -779,7 +779,7 @@ export default class RFB extends EventTargetMixin {
// Message Handlers
_negotiate_protocol_version() {
if (this._sock.rQlen() < 12) {
if (this._sock.rQlen < 12) {
return this._fail("Received incomplete protocol version.");
}
@@ -1360,7 +1360,7 @@ export default class RFB extends EventTargetMixin {
_handle_xvp_msg() {
if (this._sock.rQwait("XVP version and message", 3, 1)) { return false; }
this._sock.rQskip8(); // Padding
this._sock.rQskipBytes(1); // Padding
const xvp_ver = this._sock.rQshift8();
const xvp_msg = this._sock.rQshift8();
@@ -1442,7 +1442,7 @@ export default class RFB extends EventTargetMixin {
_onFlush() {
this._flushing = false;
// Resume processing
if (this._sock.rQlen() > 0) {
if (this._sock.rQlen > 0) {
this._handle_message();
}
}
@@ -1450,7 +1450,7 @@ export default class RFB extends EventTargetMixin {
_framebufferUpdate() {
if (this._FBU.rects === 0) {
if (this._sock.rQwait("FBU header", 3, 1)) { return false; }
this._sock.rQskip8(); // Padding
this._sock.rQskipBytes(1); // Padding
this._FBU.rects = this._sock.rQshift16();
// Make sure the previous frame is fully rendered first

View File

@@ -45,24 +45,24 @@ export default class Websock {
}
// Getters and Setters
get_sQ() {
get sQ() {
return this._sQ;
}
get_rQ() {
get rQ() {
return this._rQ;
}
get_rQi() {
get rQi() {
return this._rQi;
}
set_rQi(val) {
set rQi(val) {
this._rQi = val;
}
// Receive Queue
rQlen() {
get rQlen() {
return this._rQlen - this._rQi;
}
@@ -70,17 +70,15 @@ export default class Websock {
return this._rQ[this._rQi];
}
rQskipBytes(bytes) {
this._rQi += bytes;
}
rQshift8() {
return this._rQ[this._rQi++];
}
rQskip8() {
this._rQi++;
}
rQskipBytes(num) {
this._rQi += num;
}
// TODO(directxman12): test performance with these vs a DataView
rQshift16() {
@@ -96,7 +94,7 @@ export default class Websock {
}
rQshiftStr(len) {
if (typeof(len) === 'undefined') { len = this.rQlen(); }
if (typeof(len) === 'undefined') { len = this.rQlen; }
let str = "";
// Handle large arrays in steps to avoid long strings on the stack
for (let i = 0; i < len; i += 4096) {
@@ -107,36 +105,27 @@ export default class Websock {
}
rQshiftBytes(len) {
if (typeof(len) === 'undefined') { len = this.rQlen(); }
if (typeof(len) === 'undefined') { len = this.rQlen; }
this._rQi += len;
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
}
rQshiftTo(target, len) {
if (len === undefined) { len = this.rQlen(); }
if (len === undefined) { len = this.rQlen; }
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
this._rQi += len;
}
rQwhole() {
return new Uint8Array(this._rQ.buffer, 0, this._rQlen);
}
rQslice(start, end) {
if (end) {
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start);
} else {
return new Uint8Array(this._rQ.buffer, this._rQi + start, this._rQlen - this._rQi - start);
}
rQslice(start, end = this.rQlen) {
return new Uint8Array(this._rQ.buffer, this._rQi + start, end - start);
}
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
// to be available in the receive queue. Return true if we need to
// wait (and possibly print a debug message), otherwise false.
rQwait(msg, num, goback) {
const rQlen = this._rQlen - this._rQi; // Skip rQlen() function call
if (rQlen < num) {
if (this.rQlen < num) {
if (goback) {
if (this._rQi < goback) {
throw new Error("rQwait cannot backup " + goback + " bytes");
@@ -235,21 +224,21 @@ export default class Websock {
}
_expand_compact_rQ(min_fit) {
const resizeNeeded = min_fit || this._rQlen - this._rQi > this._rQbufferSize / 2;
const resizeNeeded = min_fit || this.rQlen > this._rQbufferSize / 2;
if (resizeNeeded) {
if (!min_fit) {
// just double the size if we need to do compaction
this._rQbufferSize *= 2;
} else {
// otherwise, make sure we satisy rQlen - rQi + min_fit < rQbufferSize / 8
this._rQbufferSize = (this._rQlen - this._rQi + min_fit) * 8;
this._rQbufferSize = (this.rQlen + min_fit) * 8;
}
}
// we don't want to grow unboundedly
if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
this._rQbufferSize = MAX_RQ_GROW_SIZE;
if (this._rQbufferSize - this._rQlen - this._rQi < min_fit) {
if (this._rQbufferSize - this.rQlen < min_fit) {
throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
}
}
@@ -283,7 +272,7 @@ export default class Websock {
_recv_message(e) {
this._decode_message(e.data);
if (this.rQlen() > 0) {
if (this.rQlen > 0) {
this._eventHandlers.message();
// Compact the receive queue
if (this._rQlen == this._rQi) {