Re: Not getting an NSStreamEventHasBytesAvailable message
Re: Not getting an NSStreamEventHasBytesAvailable message
- Subject: Re: Not getting an NSStreamEventHasBytesAvailable message
- From: ebach <email@hidden>
- Date: Thu, 09 Feb 2017 21:30:08 -0700
I’m pretty sure you only get another NSStreamEventHasBytesAvailable event once you have processed all the data from the last event.
Eli
(resent to list, accidentally only replied to Jens)
> On Feb 9, 2017, at 3:27 PM, Jens Alfke <email@hidden> wrote:
>
> 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