diff options
author | Chris Wilson <chris+github@qwirx.com> | 2011-02-26 14:09:45 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2011-02-26 14:09:45 +0000 |
commit | 902a263f643ca1d71189158ed4208b0434a28679 (patch) | |
tree | c42bcbea2db97b522e1e97b6f0c2fb31d8537107 | |
parent | 71f716d4dfb3402d520ab958cc468605342feb0f (diff) |
Hopefully fix divide by zero error on rate limiting stream.
-rw-r--r-- | lib/common/RateLimitingStream.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/common/RateLimitingStream.cpp b/lib/common/RateLimitingStream.cpp index 67a97e6b..8876f146 100644 --- a/lib/common/RateLimitingStream.cpp +++ b/lib/common/RateLimitingStream.cpp @@ -63,6 +63,14 @@ int RateLimitingStream::Read(void *pBuffer, int NBytes, int Timeout) // How are we doing so far? (for logging only) box_time_t currentDuration = currentTime - mStartTime; + + // in case our timer is not very accurate, don't divide by zero on first pass + if(currentDuration == 0) + { + BOX_TRACE("Current rate not yet known, sending immediately"); + return bytesReadThisTime; + } + uint64_t effectiveRateSoFar = (mTotalBytesRead * MICRO_SEC_IN_SEC_LL) / currentDuration; |