diff options
author | Peter Åstrand <astrand@cendio.se> | 2004-12-30 16:00:48 +0000 |
---|---|---|
committer | Peter Åstrand <astrand@cendio.se> | 2004-12-30 16:00:48 +0000 |
commit | 8e8b5e8a9d6536822e16052176d2b64bacb32c7f (patch) | |
tree | e385a3a9d9b3e0a7575323072820e91b5278cd89 /rdr | |
parent | f1f6b58e5db0e4bfc72b505032dd15ef0523f706 (diff) | |
download | tigervnc-8e8b5e8a9d6536822e16052176d2b64bacb32c7f.tar.gz tigervnc-8e8b5e8a9d6536822e16052176d2b64bacb32c7f.zip |
Improved patch for bandwidth estimation: Avoid reading only 1 or 2
bytes at a time.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@75 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'rdr')
-rw-r--r-- | rdr/FdInStream.cxx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/rdr/FdInStream.cxx b/rdr/FdInStream.cxx index 26e6d0df..38e12acf 100644 --- a/rdr/FdInStream.cxx +++ b/rdr/FdInStream.cxx @@ -36,6 +36,14 @@ #include <sys/time.h> #endif +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif + // XXX should use autoconf HAVE_SYS_SELECT_H #ifdef _AIX #include <sys/select.h> @@ -130,14 +138,15 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait) int bytes_to_read; while (end < start + itemSize) { - if (timing) { - bytes_to_read = start + bufSize - end; - } else { - // When not timing, we must be careful not to read extra data - // into the buffer. Otherwise, the line speed estimation might - // stay at zero for a long time: All reads during timing=1 can - // be satisfied without calling readWithTimeoutOrCallback. - bytes_to_read = start + itemSize*nItems - end; + bytes_to_read = start + bufSize - end; + if (!timing) { + // When not timing, we must be careful not to read too much + // extra data into the buffer. Otherwise, the line speed + // estimation might stay at zero for a long time: All reads + // during timing=1 can be satisfied without calling + // readWithTimeoutOrCallback. However, reading only 1 or 2 bytes + // bytes is ineffecient. + bytes_to_read = min(bytes_to_read, max(itemSize*nItems, 8)); } int n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait); if (n == 0) return 0; |