diff options
Diffstat (limited to 'common/rdr')
-rw-r--r-- | common/rdr/BufferedInStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/BufferedInStream.h | 4 | ||||
-rw-r--r-- | common/rdr/BufferedOutStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/BufferedOutStream.h | 5 | ||||
-rw-r--r-- | common/rdr/Exception.h | 4 | ||||
-rw-r--r-- | common/rdr/FdInStream.cxx | 88 | ||||
-rw-r--r-- | common/rdr/FdInStream.h | 17 | ||||
-rw-r--r-- | common/rdr/FdOutStream.cxx | 59 | ||||
-rw-r--r-- | common/rdr/FdOutStream.h | 10 | ||||
-rw-r--r-- | common/rdr/FileInStream.cxx | 2 | ||||
-rw-r--r-- | common/rdr/FileInStream.h | 2 | ||||
-rw-r--r-- | common/rdr/HexInStream.cxx | 2 | ||||
-rw-r--r-- | common/rdr/InStream.h | 137 | ||||
-rw-r--r-- | common/rdr/MemInStream.h | 8 | ||||
-rw-r--r-- | common/rdr/OutStream.h | 14 | ||||
-rw-r--r-- | common/rdr/RandomStream.cxx | 2 | ||||
-rw-r--r-- | common/rdr/RandomStream.h | 2 | ||||
-rw-r--r-- | common/rdr/TLSInStream.cxx | 13 | ||||
-rw-r--r-- | common/rdr/TLSInStream.h | 4 | ||||
-rw-r--r-- | common/rdr/ZlibInStream.cxx | 8 | ||||
-rw-r--r-- | common/rdr/ZlibInStream.h | 2 |
21 files changed, 193 insertions, 198 deletions
diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 14b73563..5a2694b4 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -47,7 +47,7 @@ size_t BufferedInStream::pos() return offset + ptr - start; } -bool BufferedInStream::overrun(size_t needed, bool wait) +bool BufferedInStream::overrun(size_t needed) { struct timeval now; @@ -112,7 +112,7 @@ bool BufferedInStream::overrun(size_t needed, bool wait) } while (avail() < needed) { - if (!fillBuffer(start + bufSize - end, wait)) + if (!fillBuffer(start + bufSize - end)) return false; } diff --git a/common/rdr/BufferedInStream.h b/common/rdr/BufferedInStream.h index 24b5a23c..84405255 100644 --- a/common/rdr/BufferedInStream.h +++ b/common/rdr/BufferedInStream.h @@ -38,9 +38,9 @@ namespace rdr { virtual size_t pos(); private: - virtual bool fillBuffer(size_t maxSize, bool wait) = 0; + virtual bool fillBuffer(size_t maxSize) = 0; - virtual bool overrun(size_t needed, bool wait); + virtual bool overrun(size_t needed); private: size_t bufSize; diff --git a/common/rdr/BufferedOutStream.cxx b/common/rdr/BufferedOutStream.cxx index 930b80b9..c8f6ce9c 100644 --- a/common/rdr/BufferedOutStream.cxx +++ b/common/rdr/BufferedOutStream.cxx @@ -60,7 +60,7 @@ void BufferedOutStream::flush() len = (ptr - sentUpTo); - if (!flushBuffer(false)) + if (!flushBuffer()) break; offset += len - (ptr - sentUpTo); @@ -148,4 +148,6 @@ void BufferedOutStream::overrun(size_t needed) gettimeofday(&lastSizeCheck, NULL); peakUsage = totalNeeded; + + return; } diff --git a/common/rdr/BufferedOutStream.h b/common/rdr/BufferedOutStream.h index dd64a136..b01d1fee 100644 --- a/common/rdr/BufferedOutStream.h +++ b/common/rdr/BufferedOutStream.h @@ -45,10 +45,9 @@ namespace rdr { private: // flushBuffer() requests that the stream be flushed. Returns true if it is // able to progress the output (which might still not mean any bytes - // actually moved) and can be called again. If wait is true then it will - // block until all data has been written. + // actually moved) and can be called again. - virtual bool flushBuffer(bool wait) = 0; + virtual bool flushBuffer() = 0; virtual void overrun(size_t needed); diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index eb3c8a9d..e5bff80d 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -47,10 +47,6 @@ namespace rdr { GAIException(const char* s, int err_); }; - struct TimedOut : public Exception { - TimedOut() : Exception("Timed out") {} - }; - struct EndOfStream : public Exception { EndOfStream() : Exception("End of stream") {} }; diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx index 27de92bb..ecc34ecd 100644 --- a/common/rdr/FdInStream.cxx +++ b/common/rdr/FdInStream.cxx @@ -46,17 +46,8 @@ using namespace rdr; -enum { DEFAULT_BUF_SIZE = 8192 }; - -FdInStream::FdInStream(int fd_, int timeoutms_, - bool closeWhenDone_) - : fd(fd_), closeWhenDone(closeWhenDone_), - timeoutms(timeoutms_), blockCallback(0) -{ -} - -FdInStream::FdInStream(int fd_, FdInStreamBlockCallback* blockCallback_) - : fd(fd_), timeoutms(0), blockCallback(blockCallback_) +FdInStream::FdInStream(int fd_, bool closeWhenDone_) + : fd(fd_), closeWhenDone(closeWhenDone_) { } @@ -66,20 +57,9 @@ FdInStream::~FdInStream() } -void FdInStream::setTimeout(int timeoutms_) { - timeoutms = timeoutms_; -} - -void FdInStream::setBlockCallback(FdInStreamBlockCallback* blockCallback_) -{ - blockCallback = blockCallback_; - timeoutms = 0; -} - - -bool FdInStream::fillBuffer(size_t maxSize, bool wait) +bool FdInStream::fillBuffer(size_t maxSize) { - size_t n = readWithTimeoutOrCallback((U8*)end, maxSize, wait); + size_t n = readFd((U8*)end, maxSize); if (n == 0) return false; end += n; @@ -88,55 +68,43 @@ bool FdInStream::fillBuffer(size_t maxSize, bool wait) } // -// readWithTimeoutOrCallback() reads up to the given length in bytes from the -// file descriptor into a buffer. If the wait argument is false, then zero is -// returned if no bytes can be read without blocking. Otherwise if a -// blockCallback is set, it will be called (repeatedly) instead of blocking. -// If alternatively there is a timeout set and that timeout expires, it throws -// a TimedOut exception. Otherwise it returns the number of bytes read. It +// readFd() reads up to the given length in bytes from the +// file descriptor into a buffer. Zero is +// returned if no bytes can be read. Otherwise it returns the number of bytes read. It // never attempts to recv() unless select() indicates that the fd is readable - // this means it can be used on an fd which has been set non-blocking. It also // has to cope with the annoying possibility of both select() and recv() // returning EINTR. // -size_t FdInStream::readWithTimeoutOrCallback(void* buf, size_t len, bool wait) +size_t FdInStream::readFd(void* buf, size_t len) { int n; - while (true) { - do { - fd_set fds; - struct timeval tv; - struct timeval* tvp = &tv; - - if (!wait) { - tv.tv_sec = tv.tv_usec = 0; - } else if (timeoutms != -1) { - tv.tv_sec = timeoutms / 1000; - tv.tv_usec = (timeoutms % 1000) * 1000; - } else { - tvp = 0; - } - - FD_ZERO(&fds); - FD_SET(fd, &fds); - n = select(fd+1, &fds, 0, 0, tvp); - } while (n < 0 && errno == EINTR); - - if (n > 0) break; - if (n < 0) throw SystemException("select",errno); - if (!wait) return 0; - if (!blockCallback) throw TimedOut(); - - blockCallback->blockCallback(); - } + do { + fd_set fds; + struct timeval tv; + + tv.tv_sec = tv.tv_usec = 0; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + n = select(fd+1, &fds, 0, 0, &tv); + } while (n < 0 && errno == EINTR); + + if (n < 0) + throw SystemException("select",errno); + + if (n == 0) + return 0; do { n = ::recv(fd, (char*)buf, len, 0); } while (n < 0 && errno == EINTR); - if (n < 0) throw SystemException("read",errno); - if (n == 0) throw EndOfStream(); + if (n < 0) + throw SystemException("read",errno); + if (n == 0) + throw EndOfStream(); return n; } diff --git a/common/rdr/FdInStream.h b/common/rdr/FdInStream.h index 0203389b..f732ceaa 100644 --- a/common/rdr/FdInStream.h +++ b/common/rdr/FdInStream.h @@ -27,33 +27,22 @@ namespace rdr { - class FdInStreamBlockCallback { - public: - virtual void blockCallback() = 0; - virtual ~FdInStreamBlockCallback() {} - }; - class FdInStream : public BufferedInStream { public: - FdInStream(int fd, int timeoutms=-1, bool closeWhenDone_=false); - FdInStream(int fd, FdInStreamBlockCallback* blockCallback); + FdInStream(int fd, bool closeWhenDone_=false); virtual ~FdInStream(); - void setTimeout(int timeoutms); - void setBlockCallback(FdInStreamBlockCallback* blockCallback); int getFd() { return fd; } private: - virtual bool fillBuffer(size_t maxSize, bool wait); + virtual bool fillBuffer(size_t maxSize); - size_t readWithTimeoutOrCallback(void* buf, size_t len, bool wait=true); + size_t readFd(void* buf, size_t len); int fd; bool closeWhenDone; - int timeoutms; - FdInStreamBlockCallback* blockCallback; size_t offset; U8* start; diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 3405838d..b52fc85d 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -49,27 +49,14 @@ using namespace rdr; -FdOutStream::FdOutStream(int fd_, bool blocking_, int timeoutms_) - : fd(fd_), blocking(blocking_), timeoutms(timeoutms_) +FdOutStream::FdOutStream(int fd_) + : fd(fd_) { gettimeofday(&lastWrite, NULL); } FdOutStream::~FdOutStream() { - try { - while (sentUpTo != ptr) - flushBuffer(true); - } catch (Exception&) { - } -} - -void FdOutStream::setTimeout(int timeoutms_) { - timeoutms = timeoutms_; -} - -void FdOutStream::setBlocking(bool blocking_) { - blocking = blocking_; } unsigned FdOutStream::getIdleTime() @@ -87,20 +74,11 @@ void FdOutStream::cork(bool enable) #endif } -bool FdOutStream::flushBuffer(bool wait) +bool FdOutStream::flushBuffer() { - size_t n = writeWithTimeout((const void*) sentUpTo, - ptr - sentUpTo, - (blocking || wait)? timeoutms : 0); - - // Timeout? - if (n == 0) { - // If non-blocking then we're done here - if (!blocking && !wait) - return false; - - throw TimedOut(); - } + size_t n = writeFd((const void*) sentUpTo, ptr - sentUpTo); + if (n == 0) + return false; sentUpTo += n; @@ -108,34 +86,27 @@ bool FdOutStream::flushBuffer(bool wait) } // -// writeWithTimeout() writes up to the given length in bytes from the given -// buffer to the file descriptor. If there is a timeout set and that timeout -// expires, it throws a TimedOut exception. Otherwise it returns the number of -// bytes written. It never attempts to send() unless select() indicates that -// the fd is writable - this means it can be used on an fd which has been set -// non-blocking. It also has to cope with the annoying possibility of both -// select() and send() returning EINTR. +// writeFd() writes up to the given length in bytes from the given +// buffer to the file descriptor. It returns the number of bytes written. It +// never attempts to send() unless select() indicates that the fd is writable +// - this means it can be used on an fd which has been set non-blocking. It +// also has to cope with the annoying possibility of both select() and send() +// returning EINTR. // -size_t FdOutStream::writeWithTimeout(const void* data, size_t length, int timeoutms) +size_t FdOutStream::writeFd(const void* data, size_t length) { int n; do { fd_set fds; struct timeval tv; - struct timeval* tvp = &tv; - if (timeoutms != -1) { - tv.tv_sec = timeoutms / 1000; - tv.tv_usec = (timeoutms % 1000) * 1000; - } else { - tvp = NULL; - } + tv.tv_sec = tv.tv_usec = 0; FD_ZERO(&fds); FD_SET(fd, &fds); - n = select(fd+1, 0, &fds, 0, tvp); + n = select(fd+1, 0, &fds, 0, &tv); } while (n < 0 && errno == EINTR); if (n < 0) diff --git a/common/rdr/FdOutStream.h b/common/rdr/FdOutStream.h index b1fb74c0..80804da4 100644 --- a/common/rdr/FdOutStream.h +++ b/common/rdr/FdOutStream.h @@ -34,11 +34,9 @@ namespace rdr { public: - FdOutStream(int fd, bool blocking=true, int timeoutms=-1); + FdOutStream(int fd); virtual ~FdOutStream(); - void setTimeout(int timeoutms); - void setBlocking(bool blocking); int getFd() { return fd; } unsigned getIdleTime(); @@ -46,11 +44,9 @@ namespace rdr { virtual void cork(bool enable); private: - virtual bool flushBuffer(bool wait); - size_t writeWithTimeout(const void* data, size_t length, int timeoutms); + virtual bool flushBuffer(); + size_t writeFd(const void* data, size_t length); int fd; - bool blocking; - int timeoutms; struct timeval lastWrite; }; diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx index 66dfe766..9975fde6 100644 --- a/common/rdr/FileInStream.cxx +++ b/common/rdr/FileInStream.cxx @@ -39,7 +39,7 @@ FileInStream::~FileInStream(void) { } } -bool FileInStream::fillBuffer(size_t maxSize, bool wait) +bool FileInStream::fillBuffer(size_t maxSize) { size_t n = fread((U8 *)end, 1, maxSize, file); if (n == 0) { diff --git a/common/rdr/FileInStream.h b/common/rdr/FileInStream.h index 268f5375..619397f0 100644 --- a/common/rdr/FileInStream.h +++ b/common/rdr/FileInStream.h @@ -34,7 +34,7 @@ namespace rdr { ~FileInStream(void); private: - virtual bool fillBuffer(size_t maxSize, bool wait); + virtual bool fillBuffer(size_t maxSize); private: FILE *file; diff --git a/common/rdr/HexInStream.cxx b/common/rdr/HexInStream.cxx index 322432c0..66bbf174 100644 --- a/common/rdr/HexInStream.cxx +++ b/common/rdr/HexInStream.cxx @@ -73,7 +73,7 @@ decodeError: bool HexInStream::fillBuffer(size_t maxSize, bool wait) { - if (!in_stream.check(2, wait)) + if (!in_stream.hasData(2)) return false; size_t length = min(in_stream.avail()/2, maxSize); diff --git a/common/rdr/InStream.h b/common/rdr/InStream.h index 5d873011..60ea4997 100644 --- a/common/rdr/InStream.h +++ b/common/rdr/InStream.h @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2014-2020 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,10 @@ #include <rdr/Exception.h> #include <string.h> // for memcpy +// Check that callers are using InStream properly, +// useful when writing new protocol handling +#undef RFB_INSTREAM_CHECK + namespace rdr { class InStream { @@ -39,29 +44,79 @@ namespace rdr { // avail() returns the number of bytes that are currenctly directly // available from the stream. - inline size_t avail() - { + inline size_t avail() { +#ifdef RFB_INSTREAM_CHECK + checkedBytes = end - ptr; +#endif + return end - ptr; } - // check() ensures there is buffer data for at least needed bytes. Returns - // true once the data is available. If wait is false, then instead of - // blocking to wait for the bytes, false is returned if the bytes are not - // immediately available. + // hasData() ensures there is at least "length" bytes of buffer data, + // possibly trying to fetch more data if there isn't enough right away + + inline bool hasData(size_t length) { +#ifdef RFB_INSTREAM_CHECK + checkedBytes = 0; +#endif + + if (length > (size_t)(end - ptr)) { + if (restorePoint != NULL) { + bool ret; + size_t restoreDiff; + + restoreDiff = ptr - restorePoint; + ptr = restorePoint; + + ret = overrun(length + restoreDiff); - inline size_t check(size_t needed, bool wait=true) - { - if (needed > avail()) - return overrun(needed, wait); + restorePoint = ptr; + ptr += restoreDiff; + + if (!ret) + return false; + } else { + if (!overrun(length)) + return false; + } + } + +#ifdef RFB_INSTREAM_CHECK + checkedBytes = length; +#endif return true; } - // checkNoWait() tries to make sure that the given number of bytes can - // be read without blocking. It returns true if this is the case, false - // otherwise. The length must be "small" (less than the buffer size). + inline bool hasDataOrRestore(size_t length) { + if (hasData(length)) + return true; + gotoRestorePoint(); + return false; + } - inline bool checkNoWait(size_t length) { return check(length, false); } + inline void setRestorePoint() { +#ifdef RFB_INSTREAM_CHECK + if (restorePoint != NULL) + throw Exception("Nested use of input stream restore point"); +#endif + restorePoint = ptr; + } + inline void clearRestorePoint() { +#ifdef RFB_INSTREAM_CHECK + if (restorePoint == NULL) + throw Exception("Incorrect clearing of input stream restore point"); +#endif + restorePoint = NULL; + } + inline void gotoRestorePoint() { +#ifdef RFB_INSTREAM_CHECK + if (restorePoint == NULL) + throw Exception("Incorrect activation of input stream restore point"); +#endif + ptr = restorePoint; + clearRestorePoint(); + } // readU/SN() methods read unsigned and signed N-bit integers. @@ -76,24 +131,19 @@ namespace rdr { inline S16 readS16() { return (S16)readU16(); } inline S32 readS32() { return (S32)readU32(); } + // skip() ignores a number of bytes on the stream + inline void skip(size_t bytes) { - while (bytes > 0) { - size_t n = check(1, bytes); - ptr += n; - bytes -= n; - } + check(bytes); + ptr += bytes; } // readBytes() reads an exact number of bytes. void readBytes(void* data, size_t length) { - while (length > 0) { - size_t n = check(1, length); - memcpy(data, ptr, n); - ptr += n; - data = (U8*)data + n; - length -= n; - } + check(length); + memcpy(data, ptr, length); + ptr += length; } // readOpaqueN() reads a quantity without byte-swapping. @@ -113,24 +163,45 @@ namespace rdr { // to the buffer. This is useful for a stream which is a wrapper around an // some other stream API. - inline const U8* getptr(size_t length) { check(length); return ptr; } + inline const U8* getptr(size_t length) { check(length); +#ifdef RFB_INSTREAM_CHECK + checkedBytes += length; +#endif + return ptr; } inline void setptr(size_t length) { if (length > avail()) throw Exception("Input stream overflow"); skip(length); } private: + const U8* restorePoint; +#ifdef RFB_INSTREAM_CHECK + size_t checkedBytes; +#endif + + inline void check(size_t bytes) { +#ifdef RFB_INSTREAM_CHECK + if (bytes > checkedBytes) + throw Exception("Input stream used without underrun check"); + checkedBytes -= bytes; +#endif + if (bytes > (size_t)(end - ptr)) + throw Exception("InStream buffer underrun"); + } + // overrun() is implemented by a derived class to cope with buffer overrun. - // It ensures there are at least needed bytes of buffer data. Returns true - // once the data is available. If wait is false, then instead of blocking - // to wait for the bytes, false is returned if the bytes are not - // immediately available. + // It tries to ensure there are at least needed bytes of buffer data. + // Returns true if it managed to satisfy the request, or false otherwise. - virtual bool overrun(size_t needed, bool wait=true) = 0; + virtual bool overrun(size_t needed) = 0; protected: - InStream() {} + InStream() : restorePoint(NULL) +#ifdef RFB_INSTREAM_CHECK + ,checkedBytes(0) +#endif + {} const U8* ptr; const U8* end; }; diff --git a/common/rdr/MemInStream.h b/common/rdr/MemInStream.h index 83740dd9..a5196594 100644 --- a/common/rdr/MemInStream.h +++ b/common/rdr/MemInStream.h @@ -41,6 +41,12 @@ namespace rdr { { ptr = start; end = start + len; + +#ifdef RFB_INSTREAM_CHECK + // MemInStream cannot add more data, so callers are assumed to already + // new the total size + avail(); +#endif } virtual ~MemInStream() { @@ -53,7 +59,7 @@ namespace rdr { private: - bool overrun(size_t needed, bool wait) { throw EndOfStream(); } + bool overrun(size_t needed) { throw EndOfStream(); } const U8* start; bool deleteWhenDone; }; diff --git a/common/rdr/OutStream.h b/common/rdr/OutStream.h index f432520f..61d5100b 100644 --- a/common/rdr/OutStream.h +++ b/common/rdr/OutStream.h @@ -49,14 +49,6 @@ namespace rdr { return end - ptr; } - // check() ensures there is buffer space for at least needed bytes. - - inline void check(size_t needed) - { - if (needed > avail()) - overrun(needed); - } - // writeU/SN() methods write unsigned and signed N-bit integers. inline void writeU8( U8 u) { check(1); *ptr++ = u; } @@ -136,6 +128,12 @@ namespace rdr { private: + inline void check(size_t length) + { + if (length > avail()) + overrun(length); + } + // overrun() is implemented by a derived class to cope with buffer overrun. // It ensures there are at least needed bytes of buffer space. diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx index 6333be3f..e2da0957 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -79,7 +79,7 @@ RandomStream::~RandomStream() { #endif } -bool RandomStream::fillBuffer(size_t maxSize, bool wait) { +bool RandomStream::fillBuffer(size_t maxSize) { #ifdef RFB_HAVE_WINCRYPT if (provider) { if (!CryptGenRandom(provider, maxSize, (U8*)end)) diff --git a/common/rdr/RandomStream.h b/common/rdr/RandomStream.h index 08ae0ff6..58986433 100644 --- a/common/rdr/RandomStream.h +++ b/common/rdr/RandomStream.h @@ -40,7 +40,7 @@ namespace rdr { virtual ~RandomStream(); private: - virtual bool fillBuffer(size_t maxSize, bool wait); + virtual bool fillBuffer(size_t maxSize); private: static unsigned int seed; diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index ba20e752..2339956d 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -39,7 +39,7 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) InStream *in = self->in; try { - if (!in->check(1, false)) { + if (!in->hasData(1)) { gnutls_transport_set_errno(self->session, EAGAIN); return -1; } @@ -74,23 +74,22 @@ TLSInStream::~TLSInStream() gnutls_transport_set_pull_function(session, NULL); } -bool TLSInStream::fillBuffer(size_t maxSize, bool wait) +bool TLSInStream::fillBuffer(size_t maxSize) { - size_t n = readTLS((U8*) end, maxSize, wait); - if (!wait && n == 0) + size_t n = readTLS((U8*) end, maxSize); + if (n == 0) return false; end += n; return true; } -size_t TLSInStream::readTLS(U8* buf, size_t len, bool wait) +size_t TLSInStream::readTLS(U8* buf, size_t len) { int n; if (gnutls_record_check_pending(session) == 0) { - n = in->check(1, wait); - if (n == 0) + if (!in->hasData(1)) return 0; } diff --git a/common/rdr/TLSInStream.h b/common/rdr/TLSInStream.h index 9779c68e..df5ebb48 100644 --- a/common/rdr/TLSInStream.h +++ b/common/rdr/TLSInStream.h @@ -37,8 +37,8 @@ namespace rdr { virtual ~TLSInStream(); private: - virtual bool fillBuffer(size_t maxSize, bool wait); - size_t readTLS(U8* buf, size_t len, bool wait); + virtual bool fillBuffer(size_t maxSize); + size_t readTLS(U8* buf, size_t len); static ssize_t pull(gnutls_transport_ptr_t str, void* data, size_t size); gnutls_session_t session; diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx index 26977228..0cacc21f 100644 --- a/common/rdr/ZlibInStream.cxx +++ b/common/rdr/ZlibInStream.cxx @@ -45,7 +45,7 @@ void ZlibInStream::setUnderlying(InStream* is, size_t bytesIn_) void ZlibInStream::flushUnderlying() { while (bytesIn > 0) { - if (!check(1)) + if (!hasData(1)) throw Exception("ZlibInStream: failed to flush remaining stream data"); skip(avail()); } @@ -85,7 +85,7 @@ void ZlibInStream::deinit() zs = NULL; } -bool ZlibInStream::fillBuffer(size_t maxSize, bool wait) +bool ZlibInStream::fillBuffer(size_t maxSize) { if (!underlying) throw Exception("ZlibInStream overrun: no underlying stream"); @@ -93,8 +93,8 @@ bool ZlibInStream::fillBuffer(size_t maxSize, bool wait) zs->next_out = (U8*)end; zs->avail_out = maxSize; - size_t n = underlying->check(1, wait); - if (n == 0) return false; + if (!underlying->hasData(1)) + return false; size_t length = underlying->avail(); if (length > bytesIn) length = bytesIn; diff --git a/common/rdr/ZlibInStream.h b/common/rdr/ZlibInStream.h index 1597b54a..302c99d8 100644 --- a/common/rdr/ZlibInStream.h +++ b/common/rdr/ZlibInStream.h @@ -44,7 +44,7 @@ namespace rdr { void init(); void deinit(); - virtual bool fillBuffer(size_t maxSize, bool wait); + virtual bool fillBuffer(size_t maxSize); private: InStream* underlying; |