Class: ZMQ::PollItems

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/ffi-rzmq/poll_items.rb

Instance Method Summary collapse

Constructor Details

#initializePollItems

Returns a new instance of PollItems.



11
12
13
14
15
# File 'lib/ffi-rzmq/poll_items.rb', line 11

def initialize
  @pollables  = {}
  @item_size  = LibZMQ::PollItem.size
  @item_store = nil
end

Instance Method Details

#<<(poll_item) ⇒ Object Also known as: push



32
33
34
35
# File 'lib/ffi-rzmq/poll_items.rb', line 32

def <<(poll_item)
  @dirty = true
  @pollables[poll_item.pollable] = OpenStruct.new(:index => size, :data => poll_item)
end

#addressObject



17
18
19
20
# File 'lib/ffi-rzmq/poll_items.rb', line 17

def address
  clean
  @item_store
end

#delete(pollable) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ffi-rzmq/poll_items.rb', line 38

def delete pollable
  if @pollables.delete(pollable)
    @dirty = true
    clean
    true
  else
    false
  end
end

#each(&blk) ⇒ Object



48
49
50
51
52
53
# File 'lib/ffi-rzmq/poll_items.rb', line 48

def each &blk
  clean
  @pollables.each_key do |pollable|
    yield get(pollable)
  end
end

#get(pollable) ⇒ Object Also known as: []



22
23
24
25
26
27
28
29
# File 'lib/ffi-rzmq/poll_items.rb', line 22

def get pollable
  return unless entry = @pollables[pollable]
  clean
  pointer = @item_store + (@item_size * entry.index)
  item = ZMQ::PollItem.from_pointer(pointer)
  item.pollable = pollable
  item
end

#inspectObject



55
56
57
58
59
60
# File 'lib/ffi-rzmq/poll_items.rb', line 55

def inspect
  clean
  str = ""
  each { |item| str << "ptr [#{item[:socket]}], events [#{item[:events]}], revents [#{item[:revents]}], " }
  str.chop.chop
end

#to_sObject



62
# File 'lib/ffi-rzmq/poll_items.rb', line 62

def to_s; inspect; end