Permalink
Browse files

Add lock around progress updates and cancel to iphone attempting to a…

…ccess zombie data
  • Loading branch information...
pokeb committed Nov 8, 2008
1 parent 18e78cc commit c3974a440e643fcf276f8c81969c852e77d543d7
Showing with 27 additions and 5 deletions.
  1. +3 −0 ASIHTTPRequest.h
  2. +17 −0 ASIHTTPRequest.m
  3. +7 −5 iphone-xibs/Synchronous.xib
View
@@ -112,6 +112,9 @@
//This lock will block the request until the delegate supplies authentication info
NSConditionLock *authenticationLock;
+ //This lock prevents the operation from being cancelled while it is trying to update the progress, and vice versa
+ NSLock *progressLock;
+
//Called on the delegate when the request completes successfully
SEL didFinishSelector;
View
@@ -85,6 +85,7 @@ - (void)dealloc
[domain release];
[authenticationRealm release];
[url release];
+ [progressLock release];
[authenticationLock release];
[lastActivityTime release];
[responseCookies release];
@@ -118,6 +119,13 @@ - (BOOL)isFinished
return complete;
}
+- (void)cancel
+{
+ [progressLock lock];
+ [super cancel];
+ [progressLock unlock];
+}
+
- (int)totalBytesRead
{
return totalBytesRead;
@@ -206,6 +214,9 @@ - (void)main
- (void)loadRequest
{
CFRunLoopAddCommonMode(CFRunLoopGetCurrent(),ASIHTTPRequestRunMode);
+
+ [progressLock release];
+ progressLock = [[NSLock alloc] init];
[authenticationLock release];
authenticationLock = [[NSConditionLock alloc] initWithCondition:1];
@@ -321,8 +332,14 @@ - (void)cancelLoad
- (void)updateProgressIndicators
{
+ [progressLock lock];
+ if ([self isCancelled]) {
+ [progressLock unlock];
+ return;
+ }
[self updateUploadProgress];
[self updateDownloadProgress];
+ [progressLock unlock];
}
@@ -30,15 +30,17 @@
<object class="IBUILabel" id="602749642">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{20, 20}, {280, 105}}</string>
+ <string key="NSFrame">{{20, 20}, {280, 144}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIGZldGNoaW5nIGEgd2ViIHBhZ2Ugc3luY2hyb25vdXNseSwgdGhlIEhUTUwgc291
cmNlIHdpbGwgYXBwZWFyIGluIHRoZSBib3ggYmVsb3cgd2hlbiB0aGUgZG93bmxvYWQgaXMgY29tcGxl
-dGUuICBJbiByZWFsIHdvcmxkIHNpdHVhdGlvbnMsIHlvdSdkIGJlIG1vcmUgbGlrZWx5IHRvIHJ1biB0
-aGlzIGluIGEgdGhyZWFkLg</string>
+dGUuICBUaGUgaW50ZXJmYWNlIHdpbGwgbG9jayB1cCB3aGVuIHlvdSBwcmVzcyB0aGlzIGJ1dHRvbiB1
+bnRpbCB0aGUgb3BlcmF0aW9uIHRpbWVzIG91dCBvciBzdWNjZWVkcy4gSW4gcmVhbCB3b3JsZCBzaXR1
+YXRpb25zLCB5b3UnZCBiZSBtb3JlIGxpa2VseSB0byB1c2Ugc3luY2hyb25vdXMgcmVxdWVzdHMgaW4g
+YSB0aHJlYWQuA</string>
<object class="NSFont" key="IBUIFont" id="467718481">
<string key="NSName">Helvetica</string>
<double key="NSSize">1.400000e+01</double>
@@ -56,7 +58,7 @@ aGlzIGluIGEgdGhyZWFkLg</string>
<object class="IBUIButton" id="963091686">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{20, 133}, {72, 37}}</string>
+ <string key="NSFrame">{{20, 172}, {72, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -84,7 +86,7 @@ aGlzIGluIGEgdGhyZWFkLg</string>
<object class="IBUITextView" id="251778509">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{20, 184}, {280, 187}}</string>
+ <string key="NSFrame">{{20, 217}, {280, 154}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>

0 comments on commit c3974a4

Please sign in to comment.