This had better fix the readstream leak for good, I don't think I could bear to look at this again.
Showing
2 changed files
with
19 additions
and
17 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-38 2010-01-29"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-39 2010-02-02"; |
25 | 25 | ||
26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
27 | 27 | ||
@@ -247,7 +247,6 @@ static BOOL isiPhoneOS2; | @@ -247,7 +247,6 @@ static BOOL isiPhoneOS2; | ||
247 | 247 | ||
248 | - (void)dealloc | 248 | - (void)dealloc |
249 | { | 249 | { |
250 | - [readStream release]; | ||
251 | [statusTimer invalidate]; | 250 | [statusTimer invalidate]; |
252 | [statusTimer release]; | 251 | [statusTimer release]; |
253 | [self setAuthenticationNeeded:ASINoAuthenticationNeededYet]; | 252 | [self setAuthenticationNeeded:ASINoAuthenticationNeededYet]; |
@@ -939,6 +938,7 @@ static BOOL isiPhoneOS2; | @@ -939,6 +938,7 @@ static BOOL isiPhoneOS2; | ||
939 | 938 | ||
940 | if ([[self connectionInfo] objectForKey:@"stream"]) { | 939 | if ([[self connectionInfo] objectForKey:@"stream"]) { |
941 | oldStream = [[[self connectionInfo] objectForKey:@"stream"] retain]; | 940 | oldStream = [[[self connectionInfo] objectForKey:@"stream"] retain]; |
941 | + | ||
942 | } | 942 | } |
943 | 943 | ||
944 | // No free connection was found in the pool matching the server/scheme/port we're connecting to, we'll need to create a new one | 944 | // No free connection was found in the pool matching the server/scheme/port we're connecting to, we'll need to create a new one |
@@ -949,12 +949,12 @@ static BOOL isiPhoneOS2; | @@ -949,12 +949,12 @@ static BOOL isiPhoneOS2; | ||
949 | [[self connectionInfo] setObject:[[self url] host] forKey:@"host"]; | 949 | [[self connectionInfo] setObject:[[self url] host] forKey:@"host"]; |
950 | [[self connectionInfo] setObject:[NSNumber numberWithInt:[[[self url] port] intValue]] forKey:@"port"]; | 950 | [[self connectionInfo] setObject:[NSNumber numberWithInt:[[[self url] port] intValue]] forKey:@"port"]; |
951 | [[self connectionInfo] setObject:[[self url] scheme] forKey:@"scheme"]; | 951 | [[self connectionInfo] setObject:[[self url] scheme] forKey:@"scheme"]; |
952 | - [[self connectionInfo] setObject:[self readStream] forKey:@"stream"]; | ||
953 | [persistentConnectionsPool addObject:[self connectionInfo]]; | 952 | [persistentConnectionsPool addObject:[self connectionInfo]]; |
954 | } | 953 | } |
955 | 954 | ||
956 | nextRequestID++; | 955 | nextRequestID++; |
957 | - [[self connectionInfo] setObject:[NSNumber numberWithInt:nextRequestID] forKey:@"request"]; | 956 | + [[self connectionInfo] setObject:[NSNumber numberWithInt:nextRequestID] forKey:@"request"]; |
957 | + [[self connectionInfo] setObject:[self readStream] forKey:@"stream"]; | ||
958 | CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); | 958 | CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue); |
959 | 959 | ||
960 | #if DEBUG_PERSISTENT_CONNECTIONS | 960 | #if DEBUG_PERSISTENT_CONNECTIONS |
@@ -978,24 +978,24 @@ static BOOL isiPhoneOS2; | @@ -978,24 +978,24 @@ static BOOL isiPhoneOS2; | ||
978 | 978 | ||
979 | BOOL streamSuccessfullyOpened = NO; | 979 | BOOL streamSuccessfullyOpened = NO; |
980 | 980 | ||
981 | + | ||
982 | + // Start the HTTP connection | ||
983 | + CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; | ||
984 | + if (CFReadStreamSetClient((CFReadStreamRef)[self readStream], kNetworkEvents, ReadStreamClientCallBack, &ctxt)) { | ||
985 | + if (CFReadStreamOpen((CFReadStreamRef)[self readStream])) { | ||
986 | + streamSuccessfullyOpened = YES; | ||
987 | + } | ||
988 | + } | ||
989 | + | ||
981 | // Here, we'll close the stream that was previously using this connection, if there was one | 990 | // Here, we'll close the stream that was previously using this connection, if there was one |
982 | // We've kept it open until now (when we've just opened a new stream) so that the new stream can make use of the old connection | 991 | // We've kept it open until now (when we've just opened a new stream) so that the new stream can make use of the old connection |
983 | // http://lists.apple.com/archives/Macnetworkprog/2006/Mar/msg00119.html | 992 | // http://lists.apple.com/archives/Macnetworkprog/2006/Mar/msg00119.html |
984 | if (oldStream) { | 993 | if (oldStream) { |
985 | - CFReadStreamSetClient((CFReadStreamRef)oldStream, kCFStreamEventNone, NULL, NULL); | ||
986 | - CFReadStreamUnscheduleFromRunLoop((CFReadStreamRef)oldStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | ||
987 | CFReadStreamClose((CFReadStreamRef)oldStream); | 994 | CFReadStreamClose((CFReadStreamRef)oldStream); |
988 | [oldStream release]; | 995 | [oldStream release]; |
989 | oldStream = nil; | 996 | oldStream = nil; |
990 | } | 997 | } |
991 | 998 | ||
992 | - // Start the HTTP connection | ||
993 | - CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; | ||
994 | - if (CFReadStreamSetClient((CFReadStreamRef)[self readStream], kNetworkEvents, ReadStreamClientCallBack, &ctxt)) { | ||
995 | - if (CFReadStreamOpen((CFReadStreamRef)[self readStream])) { | ||
996 | - streamSuccessfullyOpened = YES; | ||
997 | - } | ||
998 | - } | ||
999 | 999 | ||
1000 | if (!streamSuccessfullyOpened) { | 1000 | if (!streamSuccessfullyOpened) { |
1001 | [self setCanUsePersistentConnection:NO]; | 1001 | [self setCanUsePersistentConnection:NO]; |
@@ -2587,6 +2587,7 @@ static BOOL isiPhoneOS2; | @@ -2587,6 +2587,7 @@ static BOOL isiPhoneOS2; | ||
2587 | } | 2587 | } |
2588 | 2588 | ||
2589 | 2589 | ||
2590 | + | ||
2590 | - (void)handleStreamError | 2591 | - (void)handleStreamError |
2591 | { | 2592 | { |
2592 | NSError *underlyingError = [(NSError *)CFReadStreamCopyError((CFReadStreamRef)[self readStream]) autorelease]; | 2593 | NSError *underlyingError = [(NSError *)CFReadStreamCopyError((CFReadStreamRef)[self readStream]) autorelease]; |
@@ -2614,18 +2615,21 @@ static BOOL isiPhoneOS2; | @@ -2614,18 +2615,21 @@ static BOOL isiPhoneOS2; | ||
2614 | 2615 | ||
2615 | #pragma mark managing the read stream | 2616 | #pragma mark managing the read stream |
2616 | 2617 | ||
2618 | + | ||
2619 | + | ||
2617 | - (void)destroyReadStream | 2620 | - (void)destroyReadStream |
2618 | { | 2621 | { |
2619 | if ([self readStream]) { | 2622 | if ([self readStream]) { |
2620 | CFReadStreamSetClient((CFReadStreamRef)[self readStream], kCFStreamEventNone, NULL, NULL); | 2623 | CFReadStreamSetClient((CFReadStreamRef)[self readStream], kCFStreamEventNone, NULL, NULL); |
2621 | - | ||
2622 | [connectionsLock lock]; | 2624 | [connectionsLock lock]; |
2623 | 2625 | ||
2624 | if (![self canUsePersistentConnection]) { | 2626 | if (![self canUsePersistentConnection]) { |
2625 | CFReadStreamUnscheduleFromRunLoop((CFReadStreamRef)[self readStream], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | 2627 | CFReadStreamUnscheduleFromRunLoop((CFReadStreamRef)[self readStream], CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); |
2626 | CFReadStreamClose((CFReadStreamRef)[self readStream]); | 2628 | CFReadStreamClose((CFReadStreamRef)[self readStream]); |
2627 | [self setReadStreamIsScheduled:NO]; | 2629 | [self setReadStreamIsScheduled:NO]; |
2630 | + | ||
2628 | } | 2631 | } |
2632 | + | ||
2629 | [self setReadStream:nil]; | 2633 | [self setReadStream:nil]; |
2630 | [connectionsLock unlock]; | 2634 | [connectionsLock unlock]; |
2631 | } | 2635 | } |
@@ -2661,8 +2665,6 @@ static BOOL isiPhoneOS2; | @@ -2661,8 +2665,6 @@ static BOOL isiPhoneOS2; | ||
2661 | #endif | 2665 | #endif |
2662 | NSInputStream *stream = [existingConnection objectForKey:@"stream"]; | 2666 | NSInputStream *stream = [existingConnection objectForKey:@"stream"]; |
2663 | if (stream) { | 2667 | if (stream) { |
2664 | - CFReadStreamSetClient((CFReadStreamRef)stream, kCFStreamEventNone, NULL, NULL); | ||
2665 | - CFReadStreamUnscheduleFromRunLoop((CFReadStreamRef)stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | ||
2666 | CFReadStreamClose((CFReadStreamRef)stream); | 2668 | CFReadStreamClose((CFReadStreamRef)stream); |
2667 | } | 2669 | } |
2668 | [persistentConnectionsPool removeObject:existingConnection]; | 2670 | [persistentConnectionsPool removeObject:existingConnection]; |
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | 13 | ||
14 | // When set to 1 ASIHTTPRequests will print information about what a request is doing | 14 | // When set to 1 ASIHTTPRequests will print information about what a request is doing |
15 | #ifndef DEBUG_REQUEST_STATUS | 15 | #ifndef DEBUG_REQUEST_STATUS |
16 | - #define DEBUG_REQUEST_STATUS 1 | 16 | + #define DEBUG_REQUEST_STATUS 0 |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | // When set to 1, ASIFormDataRequests will print information about the request body to the console | 19 | // When set to 1, ASIFormDataRequests will print information about the request body to the console |
-
Please register or login to post a comment