2

I can't seem to find the answer to this anywhere, but does read:maxLength: on NSInputStream block until data is available or there is an error, or do I need to poll on hasBytesAvailable before attempting to read?

jscs
  • 63,694
  • 13
  • 151
  • 195
Patrick McDaniel
  • 1,073
  • 4
  • 11
  • 28

1 Answers1

3

Yes, read:maxLength: blocks until after at least one byte is available, or if an error occurred or if the stream reached EOS. It will also block until after the stream is opened.

Whether you want to poll or if you are fine with blocking or if you want to implement the stream delegates is up to you. It is recommended to use the stream delegates.

CouchDeveloper
  • 18,174
  • 3
  • 45
  • 67
  • For me, it blocks indefinitely when used on a tcp stream. Specifically, after making sure all stream ops like open, close etc are done on main thread, I still see the thread that did read being blocked forever, even after issuing stream close and setting to nil. – xaphod Jan 24 '15 at 19:25