Permalink
Browse files

Refactor to fix lots of bugs, especially locking issues

  • Loading branch information...
1 parent 90cd6b9 commit 31fe833ef84718d973c08b136e13a5a87e7a155a @pokeb committed Nov 11, 2008
Showing with 193 additions and 148 deletions.
  1. +5 −0 ASIFormDataRequest.m
  2. +16 −12 ASIHTTPRequest.h
  3. +128 −111 ASIHTTPRequest.m
  4. +4 −2 ASIHTTPRequestTests.m
  5. +12 −9 ASINetworkQueue.h
  6. +28 −12 ASINetworkQueue.m
  7. +0 −2 ASINetworkQueueTests.m
View
@@ -50,6 +50,11 @@ - (void)setFile:(NSString *)filePath forKey:(NSString *)key
- (void)buildPostBody
{
+ if (!postData && ! fileData) {
+ [super buildPostBody];
+ return;
+ }
+
NSMutableData *body = [[[NSMutableData alloc] init] autorelease];
// Set your own boundary string only if really obsessive. We don't bother to check if post data contains the boundary, since it's pretty unlikely that it does.
View
@@ -10,6 +10,7 @@
// Portions are based on the ImageClient example from Apple:
// See: http://developer.apple.com/samplecode/ImageClient/listing37.html
+#import <Cocoa/Cocoa.h>
@interface ASIHTTPRequest : NSOperation {
@@ -93,25 +94,28 @@
int responseStatusCode;
//Size of the response
- unsigned int contentLength;
+ unsigned long long contentLength;
//Size of the POST payload
- unsigned int postLength;
+ unsigned long long postLength;
//The total amount of downloaded data
- unsigned int totalBytesRead;
+ unsigned long long totalBytesRead;
//Last amount of data read (used for incrementing progress)
- unsigned int lastBytesRead;
+ unsigned long long lastBytesRead;
//Last amount of data sent (used for incrementing progress)
- unsigned int lastBytesSent;
+ unsigned long long lastBytesSent;
//Realm for authentication when credentials are required
NSString *authenticationRealm;
//This lock will block the request until the delegate supplies authentication info
NSConditionLock *authenticationLock;
+ //This lock prevents the operation from being cancelled at an inopportune moment
+ NSLock *cancelledLock;
+
//Called on the delegate when the request completes successfully
SEL didFinishSelector;
@@ -128,7 +132,7 @@
NSAutoreleasePool *pool;
// Will be YES when a HEAD request will handle the content-length before this request starts
- BOOL useCachedContentLength;
+ BOOL shouldResetProgressIndicators;
// Used by HEAD requests when showAccurateProgress is YES to preset the content-length for this request
ASIHTTPRequest *mainRequest;
@@ -177,9 +181,9 @@
// Called on main thread to update progress delegates
- (void)updateProgressIndicators;
-- (void)resetUploadProgress:(NSNumber *)max;
+- (void)resetUploadProgress:(unsigned long long)value;
- (void)updateUploadProgress;
-- (void)resetDownloadProgress:(NSNumber *)max;
+- (void)resetDownloadProgress:(unsigned long long)value;
- (void)updateDownloadProgress;
// Called when authorisation is needed, as we only find out we don't have permission to something when the upload is complete
@@ -279,10 +283,10 @@
@property (assign) NSTimeInterval timeOutSeconds;
@property (retain) NSString *requestMethod;
@property (retain,setter=setPostBody:) NSData *postBody;
-@property (assign) unsigned int contentLength;
-@property (assign) unsigned int postLength;
-@property (assign) BOOL useCachedContentLength;
+@property (assign) unsigned long long contentLength;
+@property (assign) unsigned long long postLength;
+@property (assign) BOOL shouldResetProgressIndicators;
@property (retain) ASIHTTPRequest *mainRequest;
@property (assign) BOOL showAccurateProgress;
-@property (assign,readonly) unsigned int totalBytesRead;
+@property (assign,readonly) unsigned long long totalBytesRead;
@end
Oops, something went wrong.

0 comments on commit 31fe833

Please sign in to comment.