• 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
Not getting an NSStreamEventHasBytesAvailable message
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Not getting an NSStreamEventHasBytesAvailable message


  • Subject: Not getting an NSStreamEventHasBytesAvailable message
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 09 Feb 2017 14:27:03 -0800

I’m testing some macOS code that’s doing TCP socket I/O with NSStreams. Occasionally (about one in ten runs) it’ll get stuck: no deadlocks or blocked threads or anything, it’s just completely idle even though the peer is still trying to send data. (The peer also gets stuck because its socket’s write buffer fills up.)

It looks like what’s happening is that my delegate object isn’t getting an NSStreamEventHasBytesAvailable event from the stream, even though there’s data to read. I’ve added logging when this event is received, and also at the point where I actually read from the stream, so I can tell that every byte-available event is followed by a read. (I know that if the read call doesn’t happen, the stream won’t send another event.) I’ve also located the NSInputStream instance and checked its hasBytesAvailable property in the debugger — it’s YES.

I’m not sure how this can happen. My understanding is that when I receive the bytes-available event I should read bytes from the stream, and even if I don’t read all the available bytes, I’ll get another event. Correct? The code was reading a max of 4kb from the stream; as an experiment I raised this to 16kb and I can’t get the bug to occur again. But I may just have made it less likely.

—Jens

PS: This is on macOS 10.12.4 Beta 1 (16E144f).
 _______________________________________________
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


  • Follow-Ups:
    • Re: Not getting an NSStreamEventHasBytesAvailable message
      • From: ebach <email@hidden>
  • Prev by Date: Re: anyone have any work arounds for Error 57 : "Socket is not connected" since iOS 10
  • Next by Date: Re: Not getting an NSStreamEventHasBytesAvailable message
  • Previous by thread: Re: anyone have any work arounds for Error 57 : "Socket is not connected" since iOS 10
  • Next by thread: Re: Not getting an NSStreamEventHasBytesAvailable message
  • Index(es):
    • Date
    • Thread