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
Ben Copsey
2010-11-10 13:27:34 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
341fb517c0793ba66191a1c2974faf289aba50ad
341fb517
1 parent
6a248605
Release blocks on main thread (hopefully closes gh-91)
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
12 deletions
Classes/ASIHTTPRequest.m
Classes/Tests/BlocksTests.m
iPhone.xcodeproj/project.pbxproj
Classes/ASIHTTPRequest.m
View file @
341fb51
...
...
@@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"
// Automatically set on build
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-13
1 2010-11-07
"
;
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-13
2 2010-11-10
"
;
NSString
*
const
NetworkRequestErrorDomain
=
@"ASIHTTPRequestErrorDomain"
;
...
...
@@ -178,6 +178,7 @@ static NSOperationQueue *sharedQueue = nil;
#if NS_BLOCKS_AVAILABLE
-
(
void
)
performBlockOnMainThread
:(
ASIBasicBlock
)
block
;
-
(
void
)
releaseBlocksOnMainThread
;
#endif
@property
(
assign
)
BOOL
complete
;
...
...
@@ -362,21 +363,59 @@ static NSOperationQueue *sharedQueue = nil;
[
dataDecompressor
release
];
#if NS_BLOCKS_AVAILABLE
[
completionBlock
release
];
[
failureBlock
release
];
[
startedBlock
release
];
[
headersReceivedBlock
release
];
[
bytesReceivedBlock
release
];
[
bytesSentBlock
release
];
[
downloadSizeIncrementedBlock
release
];
[
uploadSizeIncrementedBlock
release
];
[
dataReceivedBlock
release
];
[
proxyAuthenticationNeededBlock
release
];
[
authenticationNeededBlock
release
];
[
self
releaseBlocksOnMainThread
];
#endif
[
super
dealloc
];
}
#if NS_BLOCKS_AVAILABLE
-
(
void
)
releaseBlocksOnMainThread
{
NSMutableArray
*
blocks
=
[
NSMutableArray
array
];
if
(
completionBlock
)
{
[
blocks
addObject
:
completionBlock
];
}
if
(
failureBlock
)
{
[
blocks
addObject
:
failureBlock
];
}
if
(
startedBlock
)
{
[
blocks
addObject
:
startedBlock
];
}
if
(
headersReceivedBlock
)
{
[
blocks
addObject
:
headersReceivedBlock
];
}
if
(
bytesReceivedBlock
)
{
[
blocks
addObject
:
bytesReceivedBlock
];
}
if
(
bytesSentBlock
)
{
[
blocks
addObject
:
bytesSentBlock
];
}
if
(
downloadSizeIncrementedBlock
)
{
[
blocks
addObject
:
downloadSizeIncrementedBlock
];
}
if
(
uploadSizeIncrementedBlock
)
{
[
blocks
addObject
:
uploadSizeIncrementedBlock
];
}
if
(
dataReceivedBlock
)
{
[
blocks
addObject
:
dataReceivedBlock
];
}
if
(
proxyAuthenticationNeededBlock
)
{
[
blocks
addObject
:
proxyAuthenticationNeededBlock
];
}
if
(
authenticationNeededBlock
)
{
[
blocks
addObject
:
authenticationNeededBlock
];
}
[[
self
class
]
performSelectorOnMainThread
:
@selector
(
releaseBlocks
:)
withObject
:
blocks
waitUntilDone
:
[
NSThread
isMainThread
]];
}
// Always called on main thread
+
(
void
)
releaseBlocks
:
(
NSArray
*
)
blocks
{
// Blocks will be released when this method exits
}
#endif
#pragma mark setup request
-
(
void
)
addRequestHeader
:
(
NSString
*
)
header
value
:
(
NSString
*
)
value
...
...
Classes/Tests/BlocksTests.m
View file @
341fb51
...
...
@@ -17,6 +17,18 @@
-
(
BOOL
)
shouldRunOnMainThread
{
return
YES
;
}
#if NS_BLOCKS_AVAILABLE
#if TARGET_OS_IPHONE
// It isn't safe to allow the view to deallocate on a thread other than the main thread / web thread, so this test is designed to cause a crash semi-reliably
-
(
void
)
testBlockMainThreadSafety
{
NSURL
*
url
=
[
NSURL
URLWithString
:
@"http://allseeing-i.com"
];
UIWebView
*
webView
=
[[[
UIWebView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
200
,
200
)]
autorelease
];
ASIHTTPRequest
*
request
=
[
ASIHTTPRequest
requestWithURL
:
url
];
[
request
setCompletionBlock
:
^
(
ASIHTTPRequest
*
request
)
{[
webView
loadHTMLString
:[
request
responseString
]
baseURL
:
url
];
}];
[
request
startAsynchronous
];
}
#endif
-
(
void
)
testBlocks
{
NSData
*
dataToSend
=
[
@"This is my post body"
dataUsingEncoding
:
NSUTF8StringEncoding
];
...
...
iPhone.xcodeproj/project.pbxproj
View file @
341fb51
This diff was suppressed by a .gitattributes entry.
Please
register
or
login
to post a comment