Sha256: 37aa872d63a0fe31af9b82a13bd0a94ef8a29b5497f19c707796e040d7f8d979

Contents?: true

Size: 738 Bytes

Versions: 1

Compression:

Stored size: 738 Bytes

Contents

require 'SysVIPC'

class Localjob
  class Channel
    def shift
      raise "SysV adapter does not support multiple queues" if @queues.size > 1
      @queues.first.shift
    end
  end

  class SysvAdapter
    include SysVIPC

    def initialize(name)
      @filename = "/tmp/#{name}"
    end
    
    def mq
      unless @mq
        File.open(@filename, "w") { }
        key = ftok(@filename, 0)
  
        @mq = MessageQueue.new(key, IPC_CREAT | 0600)
      end
      
      @mq
    end

    def receive
      mq.receive(0, 8024)
    end

    def send(message)
      mq.send(1, message)
    end

    def size
      mq.ipc_stat.msg_qnum
    end

    def destroy
      File.delete(@filename)
      @mq.rm
      @mq = nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localjob-0.1.1 lib/localjob/sysv_adapter.rb