• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to do cancellable HTTP request using CFNetwork APIs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to do cancellable HTTP request using CFNetwork APIs


  • Subject: Re: How to do cancellable HTTP request using CFNetwork APIs
  • From: Bill Garrison <email@hidden>
  • Date: Sun, 9 May 2010 19:05:29 -0400

On May 8, 2010, at 3:18 PM, Kenny Leung wrote:

> Hi All.
>
> I'm using CFNetwork APIs to create a cancellable web operation using the synchronous, non-blocking APIs like so:

[snip]

> 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?

Kenny,

If you're using an NSOperation subclass, I think you can override -cancel to do something like this:

// Assuming inStream is an ivar point to the read stream.

- (void) cancel {
	[super cancel];

	// Shutdown the HTTP stream
	CFReadStreamSetClient( inStream, kCFStreamEventNone, NULL, NULL );
	CFReadStreamUnscheduleFromRunLoop( inStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
	CFReadStreamClose( inStream);
	CFRelease( inStream ); inStream = NULL;

	//... other bookkeeping stuff
}

This should work to cancel the stream during the request upload.

Bill_______________________________________________

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

References: 
 >How to do cancellable HTTP request using CFNetwork APIs (From: Kenny Leung <email@hidden>)

  • Prev by Date: Re: NSImage and NSImageView questions
  • Next by Date: Re: How to do cancellable HTTP request using CFNetwork APIs
  • Previous by thread: How to do cancellable HTTP request using CFNetwork APIs
  • Next by thread: Re: How to do cancellable HTTP request using CFNetwork APIs
  • Index(es):
    • Date
    • Thread