aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb/zrleDecode.h
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-05-14 18:49:39 +0200
committerPierre Ossman <ossman@cendio.se>2020-05-21 12:59:02 +0200
commitad0f0618fa2ca13d7b916f22eccc5ba3201482cb (patch)
tree55b84c52f8ab0e7ebe672458471e4577afddc1b9 /common/rfb/zrleDecode.h
parentc0dac220de0186a879f1f71966a2848000f69a48 (diff)
downloadtigervnc-ad0f0618fa2ca13d7b916f22eccc5ba3201482cb.tar.gz
tigervnc-ad0f0618fa2ca13d7b916f22eccc5ba3201482cb.zip
Change streams to be asynchronous
Major restructuring of how streams work. Neither input nor output streams are now blocking. This avoids stalling the rest of the client or server when a peer is slow or unresponsive. Note that this puts an extra burden on users of streams to make sure they are allowed to do their work once the underlying transports are ready (e.g. monitoring fds).
Diffstat (limited to 'common/rfb/zrleDecode.h')
-rw-r--r--common/rfb/zrleDecode.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/common/rfb/zrleDecode.h b/common/rfb/zrleDecode.h
index f4325385..998e51ed 100644
--- a/common/rfb/zrleDecode.h
+++ b/common/rfb/zrleDecode.h
@@ -22,11 +22,6 @@
// This file is #included after having set the following macro:
// BPP - 8, 16 or 32
-#include <stdio.h>
-#include <rdr/InStream.h>
-#include <rdr/ZlibInStream.h>
-#include <rfb/Exception.h>
-
namespace rfb {
// CONCAT2E concatenates its arguments, expanding them if they are macros
@@ -63,11 +58,17 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
t.br.x = __rfbmin(r.br.x, t.tl.x + 64);
+ zlibHasData(zis, 1);
int mode = zis->readU8();
bool rle = mode & 128;
int palSize = mode & 127;
PIXEL_T palette[128];
+#ifdef CPIXEL
+ zlibHasData(zis, 3 * palSize);
+#else
+ zlibHasData(zis, BPP/8 * palSize);
+#endif
for (int i = 0; i < palSize; i++) {
palette[i] = READ_PIXEL(zis);
}
@@ -84,10 +85,12 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
// raw
#ifdef CPIXEL
+ zlibHasData(zis, 3 * t.area());
for (PIXEL_T* ptr = buf; ptr < buf+t.area(); ptr++) {
*ptr = READ_PIXEL(zis);
}
#else
+ zlibHasData(zis, BPP/8 * t.area());
zis->readBytes(buf, t.area() * (BPP / 8));
#endif
@@ -106,6 +109,7 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
while (ptr < eol) {
if (nbits == 0) {
+ zlibHasData(zis, 1);
byte = zis->readU8();
nbits = 8;
}
@@ -125,10 +129,16 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
PIXEL_T* ptr = buf;
PIXEL_T* end = ptr + t.area();
while (ptr < end) {
+#ifdef CPIXEL
+ zlibHasData(zis, 3);
+#else
+ zlibHasData(zis, BPP/8);
+#endif
PIXEL_T pix = READ_PIXEL(zis);
int len = 1;
int b;
do {
+ zlibHasData(zis, 1);
b = zis->readU8();
len += b;
} while (b == 255);
@@ -147,11 +157,13 @@ void ZRLE_DECODE (const Rect& r, rdr::InStream* is,
PIXEL_T* ptr = buf;
PIXEL_T* end = ptr + t.area();
while (ptr < end) {
+ zlibHasData(zis, 1);
int index = zis->readU8();
int len = 1;
if (index & 128) {
int b;
do {
+ zlibHasData(zis, 1);
b = zis->readU8();
len += b;
} while (b == 255);