Merge branch 'master' into integration
Conflicts: Classes/ASIHTTPRequest.m
Showing
1 changed file
with
23 additions
and
12 deletions
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
| 22 | 22 | ||
| 23 | // Automatically set on build | 23 | // Automatically set on build |
| 24 | -NSString *ASIHTTPRequestVersion = @"v1.5-32 2010-01-20"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-32 2010-01-27"; |
| 25 | 25 | ||
| 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 27 | 27 | ||
| @@ -132,6 +132,7 @@ static BOOL isiPhoneOS2; | @@ -132,6 +132,7 @@ static BOOL isiPhoneOS2; | ||
| 132 | 132 | ||
| 133 | - (void)markAsFinished; | 133 | - (void)markAsFinished; |
| 134 | - (void)performRedirect; | 134 | - (void)performRedirect; |
| 135 | +- (BOOL)shouldTimeOut; | ||
| 135 | 136 | ||
| 136 | #if TARGET_OS_IPHONE | 137 | #if TARGET_OS_IPHONE |
| 137 | + (void)registerForNetworkReachabilityNotifications; | 138 | + (void)registerForNetworkReachabilityNotifications; |
| @@ -1082,6 +1083,26 @@ static BOOL isiPhoneOS2; | @@ -1082,6 +1083,26 @@ static BOOL isiPhoneOS2; | ||
| 1082 | } | 1083 | } |
| 1083 | } | 1084 | } |
| 1084 | 1085 | ||
| 1086 | +- (BOOL)shouldTimeOut | ||
| 1087 | +{ | ||
| 1088 | + NSTimeInterval secondsSinceLastActivity = [[NSDate date] timeIntervalSinceDate:lastActivityTime]; | ||
| 1089 | + // See if we need to timeout | ||
| 1090 | + if ([self readStream] && [self readStreamIsScheduled] && lastActivityTime && timeOutSeconds > 0 && secondsSinceLastActivity > timeOutSeconds) { | ||
| 1091 | + | ||
| 1092 | + // We have no body, or we've sent more than the upload buffer size,so we can safely time out here | ||
| 1093 | + if (postLength == 0 || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) { | ||
| 1094 | + return YES; | ||
| 1095 | + | ||
| 1096 | + // ***Black magic warning*** | ||
| 1097 | + // We have a body, but we've taken longer than timeout seconds to upload the first small chunk of data | ||
| 1098 | + // Since there's no reliable way to track upload progress for the first 32KB (iPhone) or 128KB (Mac) with CFNetwork, we'll be slightly more forgiving on the timeout, as there's a strong chance our connection is just very slow. | ||
| 1099 | + } else if (secondsSinceLastActivity > timeOutSeconds*1.5) { | ||
| 1100 | + return YES; | ||
| 1101 | + } | ||
| 1102 | + } | ||
| 1103 | + return NO; | ||
| 1104 | +} | ||
| 1105 | + | ||
| 1085 | - (void)checkRequestStatus | 1106 | - (void)checkRequestStatus |
| 1086 | { | 1107 | { |
| 1087 | // We won't let the request cancel while we're updating progress / checking for a timeout | 1108 | // We won't let the request cancel while we're updating progress / checking for a timeout |
| @@ -1093,18 +1114,9 @@ static BOOL isiPhoneOS2; | @@ -1093,18 +1114,9 @@ static BOOL isiPhoneOS2; | ||
| 1093 | return; | 1114 | return; |
| 1094 | } | 1115 | } |
| 1095 | 1116 | ||
| 1096 | - NSDate *now = [NSDate date]; | ||
| 1097 | - | ||
| 1098 | [self performThrottling]; | 1117 | [self performThrottling]; |
| 1099 | 1118 | ||
| 1100 | - // See if we need to timeout | 1119 | + if ([self shouldTimeOut]) { |
| 1101 | - if ([self readStream] && [self readStreamIsScheduled] && lastActivityTime && timeOutSeconds > 0 && [now timeIntervalSinceDate:lastActivityTime] > timeOutSeconds) { | ||
| 1102 | - | ||
| 1103 | - // Prevent timeouts before 128KB* has been sent when the size of data to upload is greater than 128KB* (*32KB on iPhone 3.0 SDK) | ||
| 1104 | - // This is to workaround the fact that kCFStreamPropertyHTTPRequestBytesWrittenCount is the amount written to the buffer, not the amount actually sent | ||
| 1105 | - // This workaround prevents erroneous timeouts in low bandwidth situations (eg iPhone) | ||
| 1106 | - if (totalBytesSent || postLength <= uploadBufferSize || (uploadBufferSize > 0 && totalBytesSent > uploadBufferSize)) { | ||
| 1107 | - | ||
| 1108 | // Do we need to auto-retry this request? | 1120 | // Do we need to auto-retry this request? |
| 1109 | if ([self numberOfTimesToRetryOnTimeout] > [self retryCount]) { | 1121 | if ([self numberOfTimesToRetryOnTimeout] > [self retryCount]) { |
| 1110 | [self setRetryCount:[self retryCount]+1]; | 1122 | [self setRetryCount:[self retryCount]+1]; |
| @@ -1119,7 +1131,6 @@ static BOOL isiPhoneOS2; | @@ -1119,7 +1131,6 @@ static BOOL isiPhoneOS2; | ||
| 1119 | [[self cancelledLock] unlock]; | 1131 | [[self cancelledLock] unlock]; |
| 1120 | return; | 1132 | return; |
| 1121 | } | 1133 | } |
| 1122 | - } | ||
| 1123 | 1134 | ||
| 1124 | // readStream will be null if we aren't currently running (perhaps we're waiting for a delegate to supply credentials) | 1135 | // readStream will be null if we aren't currently running (perhaps we're waiting for a delegate to supply credentials) |
| 1125 | if ([self readStream]) { | 1136 | if ([self readStream]) { |
-
Please register or login to post a comment