Set clear stream client when unscheduling the readstream, and set it again when scheduling
Showing
1 changed file
with
9 additions
and
21 deletions
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | #import "ASIDataCompressor.h" | 24 | #import "ASIDataCompressor.h" |
| 25 | 25 | ||
| 26 | // Automatically set on build | 26 | // Automatically set on build |
| 27 | -NSString *ASIHTTPRequestVersion = @"v1.7-132 2010-11-10"; | 27 | +NSString *ASIHTTPRequestVersion = @"v1.7-133 2010-11-10"; |
| 28 | 28 | ||
| 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 30 | 30 | ||
| @@ -3355,33 +3355,15 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3355,33 +3355,15 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3355 | 3355 | ||
| 3356 | #pragma mark managing the read stream | 3356 | #pragma mark managing the read stream |
| 3357 | 3357 | ||
| 3358 | - | ||
| 3359 | - | ||
| 3360 | - (void)destroyReadStream | 3358 | - (void)destroyReadStream |
| 3361 | { | 3359 | { |
| 3362 | if ([self readStream]) { | 3360 | if ([self readStream]) { |
| 3363 | - CFReadStreamSetClient((CFReadStreamRef)[self readStream], kCFStreamEventNone, NULL, NULL); | 3361 | + [self unscheduleReadStream]; |
| 3364 | - [connectionsLock lock]; | ||
| 3365 | - | ||
| 3366 | - if ([self readStreamIsScheduled]) { | ||
| 3367 | - runningRequestCount--; | ||
| 3368 | - if (shouldUpdateNetworkActivityIndicator && runningRequestCount == 0) { | ||
| 3369 | - // This call will wait half a second before turning off the indicator | ||
| 3370 | - // This can prevent flicker when you have a single request finish and then immediately start another request | ||
| 3371 | - // We run this on the main thread because we have no guarantee this thread will have a runloop in 0.5 seconds time | ||
| 3372 | - // We don't bother the cancel this call if we start a new request, because we'll check if requests are running before we hide it | ||
| 3373 | - [[self class] performSelectorOnMainThread:@selector(hideNetworkActivityIndicatorAfterDelay) withObject:nil waitUntilDone:[NSThread isMainThread]]; | ||
| 3374 | - } | ||
| 3375 | - } | ||
| 3376 | - | ||
| 3377 | - [self setReadStreamIsScheduled:NO]; | ||
| 3378 | - | ||
| 3379 | if (![self connectionCanBeReused]) { | 3362 | if (![self connectionCanBeReused]) { |
| 3380 | [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; | 3363 | [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; |
| 3381 | [[self readStream] close]; | 3364 | [[self readStream] close]; |
| 3382 | } | 3365 | } |
| 3383 | [self setReadStream:nil]; | 3366 | [self setReadStream:nil]; |
| 3384 | - [connectionsLock unlock]; | ||
| 3385 | } | 3367 | } |
| 3386 | } | 3368 | } |
| 3387 | 3369 | ||
| @@ -3398,6 +3380,8 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3398,6 +3380,8 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3398 | 3380 | ||
| 3399 | // Reset the timeout | 3381 | // Reset the timeout |
| 3400 | [self setLastActivityTime:[NSDate date]]; | 3382 | [self setLastActivityTime:[NSDate date]]; |
| 3383 | + CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; | ||
| 3384 | + CFReadStreamSetClient((CFReadStreamRef)[self readStream], kNetworkEvents, ReadStreamClientCallBack, &ctxt); | ||
| 3401 | [[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; | 3385 | [[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; |
| 3402 | [self setReadStreamIsScheduled:YES]; | 3386 | [self setReadStreamIsScheduled:YES]; |
| 3403 | } | 3387 | } |
| @@ -3411,11 +3395,15 @@ static NSOperationQueue *sharedQueue = nil; | @@ -3411,11 +3395,15 @@ static NSOperationQueue *sharedQueue = nil; | ||
| 3411 | [connectionsLock lock]; | 3395 | [connectionsLock lock]; |
| 3412 | runningRequestCount--; | 3396 | runningRequestCount--; |
| 3413 | if (shouldUpdateNetworkActivityIndicator && runningRequestCount == 0) { | 3397 | if (shouldUpdateNetworkActivityIndicator && runningRequestCount == 0) { |
| 3414 | - // See comment in destroyReadStream for more info | 3398 | + // This call will wait half a second before turning off the indicator |
| 3399 | + // This can prevent flicker when you have a single request finish and then immediately start another request | ||
| 3400 | + // We run this on the main thread because we have no guarantee this thread will have a runloop in 0.5 seconds time | ||
| 3401 | + // We don't bother the cancel this call if we start a new request, because we'll check if requests are running before we hide it | ||
| 3415 | [[self class] performSelectorOnMainThread:@selector(hideNetworkActivityIndicatorAfterDelay) withObject:nil waitUntilDone:[NSThread isMainThread]]; | 3402 | [[self class] performSelectorOnMainThread:@selector(hideNetworkActivityIndicatorAfterDelay) withObject:nil waitUntilDone:[NSThread isMainThread]]; |
| 3416 | } | 3403 | } |
| 3417 | [connectionsLock unlock]; | 3404 | [connectionsLock unlock]; |
| 3418 | 3405 | ||
| 3406 | + CFReadStreamSetClient((CFReadStreamRef)[self readStream], kCFStreamEventNone, NULL, NULL); | ||
| 3419 | [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; | 3407 | [[self readStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]]; |
| 3420 | [self setReadStreamIsScheduled:NO]; | 3408 | [self setReadStreamIsScheduled:NO]; |
| 3421 | } | 3409 | } |
-
Please register or login to post a comment