From ad0f0618fa2ca13d7b916f22eccc5ba3201482cb Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 14 May 2020 18:49:39 +0200 Subject: 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). --- common/rfb/zrleDecode.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'common/rfb/zrleDecode.h') 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 -#include -#include -#include - 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); -- cgit v1.2.3