Showing
1 changed file
with
7 additions
and
3 deletions
| @@ -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]; |
| @@ -3026,11 +3027,14 @@ static BOOL isiPhoneOS2; | @@ -3026,11 +3027,14 @@ static BOOL isiPhoneOS2; | ||
| 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) { |
| 3031 | 3033 | ||
| 3032 | - // Yes, put this request to sleep until a second is up | 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) |
| 3033 | - [NSThread sleepUntilDate:bandwidthMeasurementDate]; | 3035 | + double extraSleepyTime = (-bytesRemaining/(maxBandwidthPerSecond*1.0)); |
| 3036 | + | ||
| 3037 | + [NSThread sleepUntilDate:[bandwidthMeasurementDate dateByAddingTimeInterval:extraSleepyTime]]; | ||
| 3034 | [self recordBandwidthUsage]; | 3038 | [self recordBandwidthUsage]; |
| 3035 | } | 3039 | } |
| 3036 | } | 3040 | } |
-
Please register or login to post a comment