Re: CFReadStreamRead blocking
Re: CFReadStreamRead blocking
- Subject: Re: CFReadStreamRead blocking
- From: Becky Willrich <email@hidden>
- Date: Wed, 29 May 2002 18:43:24 -0700
I am occasionally seeing (using Thread Viewer) the main runloop blocking on a read, even though I only ever invoke CFReadStreamRead after a kCFStreamEventHasBytesAvailable event has arrived. I even take the (redundant) step of checking via CFStreamEventHasBytesAvailable() before performing the read, but I still see main thread block from time to time.
I don't know of any problems like this; certainly what you're doing should work. How many bytes are you reading? On very fast connections with huge gobs of data coming through, the sheer time required to copy all the bytes out of the kernel can be enough to bog down the UI - you're not actually blocking, because you're not waiting on bytes from the network, but all the time is being spent as pure CPU.... It looks very similar to a block, because all the time is still spent inside read(), but if you look at the CPU usage in something like top, it won't be 0% (which would be the case if you were blocking). If this is the case, the easiest workaround (and maybe the easiest way to diagnose the problem) is to make sure to never read more than a few K before returning from the callback, even if there's more data waiting. All user events (and I think display update as well) gets priority from the run loop relative to socket data coming in, so if you return to the run loop, the display will update, etc., even if there are bytes waiting to be processed (which may not be a good thing, but the CPU is a limited resource....).
If that's not the case, I'm not sure what to tell you - you've found a bug. An interesting test would be to get the native socket out of the stream and perform a zero-second select() to see whether the kernel thinks there are bytes in the buffer. This would tell whether the bug is in the BSD socket layer (unlikely, but possible) or the CFReadStream layer.
Let us know,
REW
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.