Ben Copsey

Hopefully improved accuracy of Bandwidth throttling

@@ -2986,6 +2986,7 @@ static BOOL isiPhoneOS2; @@ -2986,6 +2986,7 @@ static BOOL isiPhoneOS2;
2986 interval++; 2986 interval++;
2987 } 2987 }
2988 } 2988 }
  2989 +
2989 //NSLog(@"Used: %qi",bandwidthUsedInLastSecond); 2990 //NSLog(@"Used: %qi",bandwidthUsedInLastSecond);
2990 [bandwidthUsageTracker addObject:[NSNumber numberWithUnsignedLong:bandwidthUsedInLastSecond]]; 2991 [bandwidthUsageTracker addObject:[NSNumber numberWithUnsignedLong:bandwidthUsedInLastSecond]];
2991 [bandwidthMeasurementDate release]; 2992 [bandwidthMeasurementDate release];
@@ -3025,12 +3026,15 @@ static BOOL isiPhoneOS2; @@ -3025,12 +3026,15 @@ static BOOL isiPhoneOS2;
3025 if (maxBandwidthPerSecond > 0) { 3026 if (maxBandwidthPerSecond > 0) {
3026 // How much data can we still send or receive this second? 3027 // How much data can we still send or receive this second?
3027 long long bytesRemaining = (long long)maxBandwidthPerSecond - (long long)bandwidthUsedInLastSecond; 3028 long long bytesRemaining = (long long)maxBandwidthPerSecond - (long long)bandwidthUsedInLastSecond;
3028 - 3029 +
  3030 +
3029 // Have we used up our allowance? 3031 // Have we used up our allowance?
3030 - if (bytesRemaining < 8) { 3032 + if (bytesRemaining < 0) {
  3033 +
  3034 + // Yes, put this request to sleep until a second is up, with extra added punishment sleeping time for being very naughty (we have used more bandwidth than we were allowed)
  3035 + double extraSleepyTime = (-bytesRemaining/(maxBandwidthPerSecond*1.0));
3031 3036
3032 - // Yes, put this request to sleep until a second is up 3037 + [NSThread sleepUntilDate:[bandwidthMeasurementDate dateByAddingTimeInterval:extraSleepyTime]];
3033 - [NSThread sleepUntilDate:bandwidthMeasurementDate];  
3034 [self recordBandwidthUsage]; 3038 [self recordBandwidthUsage];
3035 } 3039 }
3036 } 3040 }