v0.8.0pre
tag69be1297f927f6f0985a1cfb1f4b681b9cf0d5ec
object 330846614470a64f34b671852ce4bf0f789aeb62
authorEric Wong <normalperson@yhbt.net>
Sun, 27 Feb 2011 11:13:02 +0000 (27 11:13 +0000)
posix_mq 0.8.0pre - kinder, gentler and less exceptional

This adds trysend, tryreceive, and tryshift interfaces to avoid
exceptions on common EAGAIN errors for non-blocking users.  EAGAIN
during non-blocking messages is common when there are multiple
readers/writer threads/processes working on the same queue.

trysend is like send, except it returns true for success and false for
EAGAIN.  send (still) returns nil, which I now consider a mistake but
won't change until post-1.0...

tryreceive and tryshift are like receive and shift respectively,
but they return nil for EAGAIN and the same return values
for their non-shift variants.

None of these methods call mq_setattr() beforehand to set the
non-blocking flag, it assumes the user set it once before they were ever
called and never changes it.  Checking/setting the non-blocking flag
every time is needless overhead and still subject to race conditions if
multiple processes/queues keep flipping flag on the same queue
descriptor.

These interfaces are not yet final, feedback is appreciated
at ruby.posix.mq@librelist.org.