At 10:36 PM +0100 3/27/12, jonat...@mugginsoft.com wrote:
You probably already have this sorted but it occurred to me that when you receive NSStreamEventHasBytesAvailable you don't have to read the data there and then.

Quinn (DTS) gave Jens the following complete answer on macnetworkp...@lists.apple.com:

At 8:52 AM +0100 3/27/12, Quinn \"The Eskimo!\" wrote:
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

Seems this should be shared here as well.

HTH,

-Steve
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to