• 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
How to do cancellable HTTP request using CFNetwork APIs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How to do cancellable HTTP request using CFNetwork APIs
      • From: Jens Alfke <email@hidden>
    • Re: How to do cancellable HTTP request using CFNetwork APIs
      • From: Bill Garrison <email@hidden>
  • Prev by Date: Re: self = [super init], nil?
  • Next by Date: isKindOfClass:
  • Previous by thread: Re: NSImage and NSImageView questions
  • Next by thread: Re: How to do cancellable HTTP request using CFNetwork APIs
  • Index(es):
    • Date
    • Thread