• 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 throttle rate of NSInputStream?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to throttle rate of NSInputStream?


  • Subject: Re: How to throttle rate of NSInputStream?
  • From: "email@hidden" <email@hidden>
  • Date: Tue, 27 Mar 2012 11:21:51 +0100

On 27 Mar 2012, at 00:13, Jens Alfke wrote:

>  (And there’s also the fact that CFNetwork must be buffering megabytes of data from the socket that my code hasn’t read yet.)
The network stack is there to deal with all this so I wouldn't fret about it.

>
> This seems to hinge on the way the stream calls my event handler. When I get the NSStreamEventHasBytesAvailable, I only read 8k bytes of data at a time, then return. What seems to happen is that, if that didn’t consume all of the available data, the stream will keep sending me the event in a tight loop without exiting back to the runloop in between.
>
> What can I do about this? Ideally I’d like the stream to hold off on reading more from the socket until my code finishes processing the buffer. As a second choice, I’d like it to at least return the runloop more often so my other tasks get time to run.
>
NSInputStream doesn't offer much in the way of flow control.
Dropping down to lower level APIs will naturally expose more of the network stack.

Unscheduling the stream from the run loop sounds like a good place to start.

Or perhaps this is one of those rare occasions where polling (i.e.: manually scheduling NSInputStream -hasBytesAvailable on the runloop) as opposed to calling scheduleInRunLoop:forMode might be worth a try.

Regards

Jonathan Mitchell
Mugginsoft LLP


_______________________________________________

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 throttle rate of NSInputStream? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Next by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Previous by thread: Re: How to throttle rate of NSInputStream?
  • Next by thread: Re: How to throttle rate of NSInputStream?
  • Index(es):
    • Date
    • Thread