class MsgQ::EventMsg

Constants

BUF_SIZE
IPC_NOWAIT

Public Class Methods

recv_cmd(q, block=true) click to toggle source
# File lib/rbtrace/msgq.rb, line 23
def self.recv_cmd(q, block=true)
  MsgQ.rb_enable_interrupt if RUBY_VERSION > '1.9' && RUBY_VERSION < '2.0'

  msg = EventMsg.new
  ret = MsgQ.msgrcv(q, msg, BUF_SIZE, 0, block ? 0 : IPC_NOWAIT)
  if ret == -1
    if !block and [Errno::EAGAIN, Errno::ENOMSG].include?(FFI::LastError.exception)
      return nil
    end

    FFI::LastError.raise
  end

  msg[:buf].to_ptr.read_string_length(BUF_SIZE)
ensure
  MsgQ.rb_disable_interrupt if RUBY_VERSION > '1.9' && RUBY_VERSION < '2.0'
end
send_cmd(q, str) click to toggle source
# File lib/rbtrace/msgq.rb, line 14
def self.send_cmd(q, str)
  msg = EventMsg.new
  msg[:mtype] = 1
  msg[:buf].to_ptr.put_string(0, str)

  ret = MsgQ.msgsnd(q, msg, BUF_SIZE, 0)
  FFI::LastError.raise if ret == -1
end