initial commit
[ruby_posix_mq.git] / lib / posix_mq.rb
bloba2a85eeb517fa64f2d403f1f2562c111cbca48ed
1 # -*- encoding: binary -*-
2 class POSIX_MQ
4   # version of POSIX_MQ, currently 0.1.0
5   VERSION = '0.1.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
10   # of this class.
11   #
12   # See the mq_getattr(3) manpage for more information on the values.
13   Attr = Struct.new(:flags, :maxmsg, :msgsize, :curmsgs)
15   class << self
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.
20     def open(*args)
21       mq = new(*args)
22       block_given? or return mq
23       begin
24         yield mq
25       ensure
26         mq.close unless mq.closed?
27       end
28     end
30   end
32 end
34 require 'posix_mq_ext'