aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/FdInStream.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/rdr/FdInStream.cxx')
-rw-r--r--common/rdr/FdInStream.cxx53
1 files changed, 2 insertions, 51 deletions
diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx
index d2753388..27de92bb 100644
--- a/common/rdr/FdInStream.cxx
+++ b/common/rdr/FdInStream.cxx
@@ -51,14 +51,12 @@ enum { DEFAULT_BUF_SIZE = 8192 };
FdInStream::FdInStream(int fd_, int timeoutms_,
bool closeWhenDone_)
: fd(fd_), closeWhenDone(closeWhenDone_),
- timeoutms(timeoutms_), blockCallback(0),
- timing(false), timeWaitedIn100us(5), timedKbits(0)
+ timeoutms(timeoutms_), blockCallback(0)
{
}
FdInStream::FdInStream(int fd_, FdInStreamBlockCallback* blockCallback_)
- : fd(fd_), timeoutms(0), blockCallback(blockCallback_),
- timing(false), timeWaitedIn100us(5), timedKbits(0)
+ : fd(fd_), timeoutms(0), blockCallback(blockCallback_)
{
}
@@ -104,10 +102,6 @@ bool FdInStream::fillBuffer(size_t maxSize, bool wait)
size_t FdInStream::readWithTimeoutOrCallback(void* buf, size_t len, bool wait)
{
- struct timeval before, after;
- if (timing)
- gettimeofday(&before, 0);
-
int n;
while (true) {
do {
@@ -144,48 +138,5 @@ size_t FdInStream::readWithTimeoutOrCallback(void* buf, size_t len, bool wait)
if (n < 0) throw SystemException("read",errno);
if (n == 0) throw EndOfStream();
- if (timing) {
- gettimeofday(&after, 0);
- int newTimeWaited = ((after.tv_sec - before.tv_sec) * 10000 +
- (after.tv_usec - before.tv_usec) / 100);
- int newKbits = n * 8 / 1000;
-
- // limit rate to between 10kbit/s and 40Mbit/s
-
- if (newTimeWaited > newKbits*1000) newTimeWaited = newKbits*1000;
- if (newTimeWaited < newKbits/4) newTimeWaited = newKbits/4;
-
- timeWaitedIn100us += newTimeWaited;
- timedKbits += newKbits;
- }
-
return n;
}
-
-void FdInStream::startTiming()
-{
- timing = true;
-
- // Carry over up to 1s worth of previous rate for smoothing.
-
- if (timeWaitedIn100us > 10000) {
- timedKbits = timedKbits * 10000 / timeWaitedIn100us;
- timeWaitedIn100us = 10000;
- }
-}
-
-void FdInStream::stopTiming()
-{
- timing = false;
- if (timeWaitedIn100us < timedKbits/2)
- timeWaitedIn100us = timedKbits/2; // upper limit 20Mbit/s
-}
-
-unsigned int FdInStream::kbitsPerSecond()
-{
- // The following calculation will overflow 32-bit arithmetic if we have
- // received more than about 50Mbytes (400Mbits) since we started timing, so
- // it should be OK for a single RFB update.
-
- return timedKbits * 10000 / timeWaitedIn100us;
-}