ruby_posix_mq.git  about / heads / tags
POSIX message queues for Ruby
blob 5e660ecdc305ec56952be80d34eb379619943fe1 809 bytes (raw)
$ git show v0.2.0:lib/posix_mq.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
# -*- encoding: binary -*-
class POSIX_MQ

  # version of POSIX_MQ, currently 0.1.0
  VERSION = '0.2.0'

  # An analogous Struct to "struct mq_attr" in C.
  # This may be used in arguments for POSIX_MQ.new and
  # POSIX_MQ#attr=.  POSIX_MQ#attr returns an instance
  # of this class.
  #
  # See the mq_getattr(3) manpage for more information on the values.
  Attr = Struct.new(:flags, :maxmsg, :msgsize, :curmsgs)

  class << self

    # Opens a POSIX message queue and performs operations on the
    # given block, closing the message queue at exit.
    # All all arguments are passed to POSIX_MQ.new.
    def open(*args)
      mq = new(*args)
      block_given? or return mq
      begin
        yield mq
      ensure
        mq.close unless mq.closed?
      end
    end

  end

end

require 'posix_mq_ext'

git clone https://yhbt.net/ruby_posix_mq.git