Class: MsgQ::EventMsg

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/rbtrace/msgq.rb

Constant Summary collapse

BUF_SIZE =
RBTrace::BUF_SIZE
IPC_NOWAIT =
004000

Class Method Summary collapse

Class Method Details

.recv_cmd(q, block = true) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbtrace/msgq.rb', line 24

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) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rbtrace/msgq.rb', line 15

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