[Xcb] [Patch] Fix busy-loop on BSD (was: Fallback to TCP if no protocol is specified and the UNIX connection fails)
josh at joshtriplett.org
Thu Mar 1 12:14:42 PST 2012
On Thu, Mar 01, 2012 at 08:50:19PM +0100, Uli Schlachter wrote:
> attached is a patch with a relatively verbose commit message. I tested this on
> one of my university's FreeBSD boxes (with quite a patches userland). I were
> able to reproduce the original problem and the patch made it go away.
> At first I wanted to do just what Josh suggested. However, read_block() could
> busy loop, too. This would happen if just the first part of an event or reply is
> received while the rest of it is stuck somewhere. While this should never occur
> in any real world scenarios, it still means that using MSG_WAITALL on a
> non-blocking socket is always wrong.
As far as I can tell, read_block will always wait until it reads the
requested amount of data. If recv returns with less than the requested
amount of data, read_block will wait for more data and call recv again.
Given that, how could MSG_WAITALL cause you to block in the kernel in
any situation where you wouldn't just loop in userspace?
- Josh Triplett
More information about the Xcb