From 902a263f643ca1d71189158ed4208b0434a28679 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 26 Feb 2011 14:09:45 +0000 Subject: Hopefully fix divide by zero error on rate limiting stream. --- lib/common/RateLimitingStream.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/common/RateLimitingStream.cpp') 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; -- cgit v1.2.3