1 # -*- encoding: binary -*-
4 # version of POSIX_MQ, currently 0.5.0
7 # An analogous Struct to "struct mq_attr" in C.
8 # This may be used in arguments for POSIX_MQ.new and
9 # POSIX_MQ#attr=. POSIX_MQ#attr returns an instance
12 # See the mq_getattr(3) manpage for more information on the values.
13 Attr = Struct.new(:flags, :maxmsg, :msgsize, :curmsgs)
17 # Opens a POSIX message queue and performs operations on the
18 # given block, closing the message queue at exit.
19 # All all arguments are passed to POSIX_MQ.new.
22 block_given? or return mq
26 mq.close unless mq.closed?
31 # Executes the given block upon reception of the next message in an
32 # empty queue. If the message queue is not empty, then this block
33 # will only be fired after the queue is emptied and repopulated with
36 # This block will only be executed upon the arrival of the
37 # first message and must be reset/reenabled for subsequent
38 # notifications. This block will execute in a separate Ruby
39 # Thread (and thus will safely have the GVL by default).
41 # This method is only supported on platforms that implement
42 # SIGEV_THREAD functionality in mq_notify(3). So far we only
43 # know of glibc + Linux supporting this. Please let us
44 # know if your platform can support this functionality and
45 # are willing to test for us <ruby.posix.mq@librelist.com>
48 raise ArgumentError, "arity of notify block must be 1"
50 self.notify_thread = Thread.new(r, w, self) do |r, w, mq|
53 r.read(1) or raise Errno::EINTR
54 rescue Errno::EINTR, Errno::EAGAIN
59 mq.notify_thread = nil
66 end if RUBY_PLATFORM =~ /linux/
68 # There's no point in ever duping a POSIX_MQ object.
69 # All send/receive operations are atomic and only one
70 # native thread may be notified at a time
75 # There's no point in ever cloning a POSIX_MQ object.
76 # All send/receive operations are atomic and only one
77 # native thread may be notified at a time
82 require 'posix_mq_ext'