• 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: "Quinn \"The Eskimo!\"" <email@hidden>
  • Date: Tue, 27 Mar 2012 08:52:51 +0100

On 26 Mar 2012, at 21:28, Jens Alfke wrote:

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

If you don't call -read:maxLength:, the stream won't send you another NSStreamEventHasBytesAvailable event.  So you can handle this case by:

on NSStreamEventHasBytesAvailable
  if we're still processing a buffer
    set a flag indicating that data is available
  else
    read and start processing a buffer
  end if
end

on bufferProcessingDone
  if we ignored a NSStreamEventHasBytesAvailable event
    read and start processing a buffer
  end if
end

Obviously the buffer processing will need to be async (either via an NSOperation or GCD), and you should organise to call -bufferProcessingDone back on the main thread.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
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: How to throttle rate of NSInputStream?
  • Next by Date: Re: ip level NKE - how to trace the process that generates traffic?
  • Previous by thread: How to throttle rate of NSInputStream?
  • Next by thread: Pipelining and CFHTTPStream
  • Index(es):
    • Date
    • Thread