Class: XS::PollItems
- Inherits:
-
Object
- Object
- XS::PollItems
- Includes:
- Enumerable
- Defined in:
- lib/ffi-rxs/poll_items.rb
Instance Method Summary (collapse)
- - (Object) <<(obj) (also: #push)
- - (Object) address
- - (Object) delete(sock)
- - (Object) delete_at(index)
- - (Object) each(&blk)
- - (Object) each_with_index(&blk)
- - (Boolean) empty?
- - (Object) get(index) (also: #[])
-
- (PollItems) initialize
constructor
A new instance of PollItems.
- - (Object) inspect
- - (Object) size
- - (Object) to_s
Constructor Details
- (PollItems) initialize
A new instance of PollItems
7 8 9 10 11 |
# File 'lib/ffi-rxs/poll_items.rb', line 7 def initialize @element_size = LibXS::PollItem.size @store = nil @items = [] end |
Instance Method Details
- (Object) <<(obj) Also known as: push
35 36 37 38 |
# File 'lib/ffi-rxs/poll_items.rb', line 35 def <<(obj) @dirty = true @items << obj end |
- (Object) address
17 18 19 20 |
# File 'lib/ffi-rxs/poll_items.rb', line 17 def address clean @store end |
- (Object) delete(sock)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ffi-rxs/poll_items.rb', line 41 def delete sock address = sock.socket.address found = false each_with_index do |item, index| if address == item[:socket].address @items.delete_at index found = true @dirty = true clean break end end # these semantics are different from the usual Array#delete; returns a # boolean instead of the actual item or nil found end |
- (Object) delete_at(index)
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ffi-rxs/poll_items.rb', line 60 def delete_at index value = nil unless @items.empty? value = @items.delete_at index @dirty = true clean end value end |
- (Object) each(&blk)
71 72 73 74 75 76 77 78 79 |
# File 'lib/ffi-rxs/poll_items.rb', line 71 def each &blk clean index = 0 until index >= @items.size do struct = get index yield struct index += 1 end end |
- (Object) each_with_index(&blk)
81 82 83 84 85 86 87 88 89 |
# File 'lib/ffi-rxs/poll_items.rb', line 81 def each_with_index &blk clean index = 0 until index >= @items.size do struct = get index yield struct, index index += 1 end end |
- (Boolean) empty?
15 |
# File 'lib/ffi-rxs/poll_items.rb', line 15 def empty?; @items.empty?; end |
- (Object) get(index) Also known as: []
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ffi-rxs/poll_items.rb', line 22 def get index unless @items.empty? || index.nil? clean # pointer arithmetic in ruby pointer = @store + (@element_size * index) # cast the memory to a PollItem LibXS::PollItem.new pointer end end |
- (Object) inspect
91 92 93 94 95 96 |
# File 'lib/ffi-rxs/poll_items.rb', line 91 def inspect clean str = "" each { |item| str << "ptr [#{item[:socket]}], events [#{item[:events]}], revents [#{item[:revents]}], " } str.chop.chop end |
- (Object) size
13 |
# File 'lib/ffi-rxs/poll_items.rb', line 13 def size; @items.size; end |
- (Object) to_s
98 |
# File 'lib/ffi-rxs/poll_items.rb', line 98 def to_s(); inspect; end |