0

Do two writes to the NSOutputStream result in two NSStreamEventHasBytesAvailable (where I handle the data read) in stream:handleEvent:?

Boon
  • 40,656
  • 60
  • 209
  • 315

1 Answers1

0

Have you checked out the "Stream Programming Guide" on output streams? https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Streams/Articles/WritingOutputStreams.html

On output streams, the sequence is:

  1. alloc/init
  2. set delegate
  3. schedule in run loop
  4. open
  5. wait for NSStreamEventOpenCompleted
  6. wait for NSStreamEventHasSpaceAvailable

When NSStreamEventHasSpaceAvailable is received (this will only be received once in response to each write operation), you have the option of performing a write. If you perform a write, you then need to wait to receive NSStreamEventHasSpaceAvailable before writing again. When performing a write, you must also confirm that everything that you attempted to write was actually written. It may be necessary to handle partial writes if the write attempt only partially completes.

xyzzycoder
  • 1,831
  • 13
  • 19
  • Of course I did. I think you didn't understand the question. I want to know how many NSStreamEventHasBytesAvailable from the other end of the pipe (where you perform read) can result from two separate write to the stream. – Boon Mar 05 '13 at 19:52
  • The question is not very clear. You're asking about an output stream, not an input stream. Yes, you should be prepared for the getting multiple NSStreamEventHasBytesAvailable messages on the input stream. – xyzzycoder Mar 05 '13 at 20:29
  • Sorry, usually you read bytes in NSStreamEventHasBytesAvailable, it's implied and yes I should make it clear. – Boon Mar 05 '13 at 21:01