How to do cancellable HTTP request using CFNetwork APIs
How to do cancellable HTTP request using CFNetwork APIs
- Subject: How to do cancellable HTTP request using CFNetwork APIs
- From: Kenny Leung <email@hidden>
- Date: Sat, 8 May 2010 12:18:15 -0700
Hi All.
I'm using CFNetwork APIs to create a cancellable web operation using the synchronous, non-blocking APIs like so:
do {
bytesRead = 0;
if ( CFReadStreamHasBytesAvailable(inStream) ) {
bytesRead = CFReadStreamRead(inStream, buffer, sizeof(buffer));
if ( bytesRead > 0 ) {
[data appendBytes:buffer length:bytesRead];
} else if ( bytesRead < 0 ) {
error = (NSError *)CFReadStreamCopyError(inStream);
self.error = error;
[error release];
[self sendFailureCallback];
return;
}
} else {
[NSThread sleepForTimeInterval:0.1];
}
if ( bytesRead == 0 ) {
streamStatus = CFReadStreamGetStatus(inStream);
if ( streamStatus == kCFStreamStatusAtEnd ) {
break;
}
}
} while ( ![self isCancelled] );
This is fine once you've gotten to the point of pulling the response, but I would like the operation to also be cancellable if I'm pushing a lot of data in the request. There isn't a good example of this with the CFNetwork framework documentation. Does anyone have an example of doing the request-response where you're fully in control of cancelling the operation?
Thanks!
-Kenny
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden