Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jamie Pinkham
2010-11-04 16:59:31 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1edeeac26032d51b9542b0497b43e522096dfcd2
1edeeac2
1 parent
4ea1a615
modified blocks, got rid of retain cycle
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
26 deletions
Classes/ASIHTTPRequest.h
Classes/ASIHTTPRequest.m
iPhone Sample/QueueViewController.m
iPhone Sample/SynchronousViewController.m
iPhone Sample/UploadViewController.m
Classes/ASIHTTPRequest.h
View file @
1edeeac
...
...
@@ -66,11 +66,11 @@ extern NSString* const NetworkRequestErrorDomain;
extern
unsigned
long
const
ASIWWANBandwidthThrottleAmount
;
#if NS_BLOCKS_AVAILABLE
typedef
void
(
^
ASIHTTPRequestBlock
)(
ASIHTTPRequest
*
request
);
typedef
void
(
^
ASIHTTPRequestBlock
)();
//typedef BOOL (^ASIHTTPRequestAuthenticationBlock)(ASIHTTPRequest *request);
typedef
void
(
^
ASIHTTPRequestSizeBlock
)(
ASIHTTPRequest
*
request
,
long
long
size
);
typedef
void
(
^
ASIHTTPRequestProgressBlock
)(
ASIHTTPRequest
*
request
,
unsigned
long
long
size
,
unsigned
long
long
total
);
typedef
void
(
^
ASIHTTPRequestDataReceivedBlock
)(
ASIHTTPRequest
*
request
,
NSData
*
data
);
typedef
void
(
^
ASIHTTPRequestSizeBlock
)(
long
long
size
);
typedef
void
(
^
ASIHTTPRequestProgressBlock
)(
unsigned
long
long
size
,
unsigned
long
long
total
);
typedef
void
(
^
ASIHTTPRequestDataReceivedBlock
)(
NSData
*
data
);
#endif
@interface
ASIHTTPRequest
:
NSOperation
<
NSCopying
>
{
...
...
Classes/ASIHTTPRequest.m
View file @
1edeeac
...
...
@@ -1582,7 +1582,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if
(
bytesReceivedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
bytesReceivedBlock
(
b
lockCopy
,
b
ytesReadSoFar
,
blockCopy
->
contentLength
+
blockCopy
->
partialDownloadSize
);
bytesReceivedBlock
(
bytesReadSoFar
,
blockCopy
->
contentLength
+
blockCopy
->
partialDownloadSize
);
}
#endif
[
self
setLastBytesRead
:
bytesReadSoFar
];
...
...
@@ -1626,7 +1626,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if
(
bytesSentBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
bytesSentBlock
(
blockCopy
,
value
,
blockCopy
->
postLength
);
bytesSentBlock
(
value
,
blockCopy
->
postLength
);
}
#endif
}
...
...
@@ -1638,8 +1638,7 @@ static NSOperationQueue *sharedQueue = nil;
[
ASIHTTPRequest
performSelector
:
@selector
(
request
:
incrementDownloadSizeBy
:
)
onTarget
:&
downloadProgressDelegate
withObject
:
self
amount
:&
length
];
#if NS_BLOCKS_AVAILABLE
if
(
downloadSizeIncrementedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
downloadSizeIncrementedBlock
(
blockCopy
,
length
);
downloadSizeIncrementedBlock
(
length
);
}
#endif
}
...
...
@@ -1651,8 +1650,7 @@ static NSOperationQueue *sharedQueue = nil;
[
ASIHTTPRequest
performSelector
:
@selector
(
request
:
incrementUploadSizeBy
:
)
onTarget
:&
uploadProgressDelegate
withObject
:
self
amount
:&
length
];
#if NS_BLOCKS_AVAILABLE
if
(
uploadSizeIncrementedBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
uploadSizeIncrementedBlock
(
blockCopy
,
length
);
uploadSizeIncrementedBlock
(
length
);
}
#endif
}
...
...
@@ -1667,7 +1665,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if
(
bytesSentBlock
){
__block
ASIHTTPRequest
*
blockCopy
=
self
;
bytesSentBlock
(
blockCopy
,
progressToRemove
,
blockCopy
->
postLength
);
bytesSentBlock
(
progressToRemove
,
blockCopy
->
postLength
);
}
#endif
}
...
...
@@ -2870,8 +2868,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
if
(
dataReceivedBlock
){
NSData
*
data
=
[
NSData
dataWithBytes
:
buffer
length
:
bytesRead
];
__block
ASIHTTPRequest
*
blockCopy
=
self
;
dataReceivedBlock
(
blockCopy
,
data
);
dataReceivedBlock
(
data
);
}
#endif
...
...
iPhone Sample/QueueViewController.m
View file @
1edeeac
...
...
@@ -17,14 +17,12 @@
-
(
IBAction
)
fetchThreeImages
:(
id
)
sender
{
ASIHTTPRequestSizeBlock
sizeBlock
=
^
(
ASIHTTPRequest
*
request
,
long
long
size
){
NSDictionary
*
userInfo
=
[
request
userInfo
];
NSLog
(
@"request - %@ named = %@ download size incremented %lld"
,
request
,
[
userInfo
valueForKey
:
@"name"
],
size
);
ASIHTTPRequestSizeBlock
sizeBlock
=
^
(
long
long
size
){
NSLog
(
@"download size incremented %lld"
,
size
);
};
ASIHTTPRequestProgressBlock
bytesBlock
=
^
(
ASIHTTPRequest
*
request
,
unsigned
long
long
size
,
unsigned
long
long
total
){
NSDictionary
*
userInfo
=
[
request
userInfo
];
NSLog
(
@"request - %@ named - %@ downloaded bytes size %llu of total: %llu"
,
request
,
[
userInfo
valueForKey
:
@"name"
],
size
,
total
);
ASIHTTPRequestProgressBlock
bytesBlock
=
^
(
unsigned
long
long
size
,
unsigned
long
long
total
){
NSLog
(
@"downloaded bytes size %llu of total: %llu"
,
size
,
total
);
};
[
imageView1
setImage
:
nil
];
...
...
iPhone Sample/SynchronousViewController.m
View file @
1edeeac
...
...
@@ -34,15 +34,15 @@
NSLog
(
@"headers recieved"
);
}];
[
request
setBytesReceivedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
unsigned
long
long
length
,
unsigned
long
long
total
){
[
request
setBytesReceivedBlock
:
^
(
unsigned
long
long
length
,
unsigned
long
long
total
){
NSLog
(
@"bytes received:%llu of total: %llu"
,
length
,
total
);
}];
[
request
setDownloadSizeIncrementedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
long
long
length
){
[
request
setDownloadSizeIncrementedBlock
:
^
(
long
long
length
){
NSLog
(
@"download size incremented:%lld"
,
length
);
}];
[
request
setDataReceivedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
NSData
*
data
){
[
request
setDataReceivedBlock
:
^
(
NSData
*
data
){
[
recievedData
appendData
:
data
];
NSLog
(
@"data - %@"
,
recievedData
);
}];
...
...
iPhone Sample/UploadViewController.m
View file @
1edeeac
...
...
@@ -20,17 +20,17 @@
[
request
setPostValue
:
@"test"
forKey
:
@"value2"
];
[
request
setPostValue
:
@"test"
forKey
:
@"value3"
];
[
request
setTimeOutSeconds
:
20
];
[
request
setBytesSentBlock
:
^
(
ASIHTTPRequest
*
request
,
unsigned
long
long
length
,
unsigned
long
long
total
){
[
request
setBytesSentBlock
:
^
(
unsigned
long
long
length
,
unsigned
long
long
total
){
NSLog
(
@"sent %llu bytes of %llu total"
,
length
,
total
);
}];
[
request
setUploadSizeIncrementedBlock
:
^
(
ASIHTTPRequest
*
request
,
long
long
length
){
[
request
setUploadSizeIncrementedBlock
:
^
(
long
long
length
){
NSLog
(
@"upload size incremented = %lld"
,
length
);
}];
/*
[request setUploadProgressDelegate:progressIndicator];
[
request
setUploadProgressDelegate
:
progressIndicator
];
[
request
setDelegate
:
self
];
[
request
setDidFailSelector
:
@selector
(
uploadFailed
:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
*/
[
request
setDidFinishSelector
:
@selector
(
uploadFinished
:)];
//Create a 256KB file
NSData
*
data
=
[[[
NSMutableData
alloc
]
initWithLength
:
256
*
1024
]
autorelease
];
...
...
Please
register
or
login
to post a comment