Class: LibvirtAsync::Handle
- Inherits:
-
Object
- Object
- LibvirtAsync::Handle
- Includes:
- WithDbg
- Defined in:
- lib/libvirt_async/handle.rb
Defined Under Namespace
Classes: Monitor
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#fd ⇒ Object
readonly
Returns the value of attribute fd.
-
#handle_id ⇒ Object
readonly
Returns the value of attribute handle_id.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#opaque ⇒ Object
readonly
Returns the value of attribute opaque.
Instance Method Summary collapse
-
#initialize(handle_id, fd, events, opaque) ⇒ Handle
constructor
A new instance of Handle.
- #inspect ⇒ Object
- #register ⇒ Object
- #to_s ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(handle_id, fd, events, opaque) ⇒ Handle
Returns a new instance of Handle.
32 33 34 35 36 37 38 39 40 |
# File 'lib/libvirt_async/handle.rb', line 32 def initialize(handle_id, fd, events, opaque) dbg { "#{self.class}#initialize handle_id=#{handle_id}, fd=#{fd}, events=#{events}" } @handle_id = handle_id @fd = fd @events = events @opaque = opaque @monitor = nil end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
30 31 32 |
# File 'lib/libvirt_async/handle.rb', line 30 def events @events end |
#fd ⇒ Object (readonly)
Returns the value of attribute fd.
29 30 31 |
# File 'lib/libvirt_async/handle.rb', line 29 def fd @fd end |
#handle_id ⇒ Object (readonly)
Returns the value of attribute handle_id.
29 30 31 |
# File 'lib/libvirt_async/handle.rb', line 29 def handle_id @handle_id end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
29 30 31 |
# File 'lib/libvirt_async/handle.rb', line 29 def monitor @monitor end |
#opaque ⇒ Object (readonly)
Returns the value of attribute opaque.
29 30 31 |
# File 'lib/libvirt_async/handle.rb', line 29 def opaque @opaque end |
Instance Method Details
#inspect ⇒ Object
109 110 111 |
# File 'lib/libvirt_async/handle.rb', line 109 def inspect to_s end |
#register ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/libvirt_async/handle.rb', line 42 def register dbg { "#{self.class}#register handle_id=#{handle_id}, fd=#{fd}" } if (events & Libvirt::EVENT_HANDLE_ERROR) != 0 dbg { "#{self.class}#register skip EVENT_HANDLE_ERROR handle_id=#{handle_id}, fd=#{fd}" } end if (events & Libvirt::EVENT_HANDLE_HANGUP) != 0 dbg { "#{self.class}#register skip EVENT_HANDLE_HANGUP handle_id=#{handle_id}, fd=#{fd}" } end interest = events_to_interest(events) dbg { "#{self.class}#register parse handle_id=#{handle_id}, fd=#{fd}, events=#{events}, interest=#{interest}" } if interest.nil? dbg { "#{self.class}#register no interest handle_id=#{handle_id}, fd=#{fd}" } return end task = Util.create_task do dbg { "#{self.class}#register_handle Async start handle_id=#{handle_id}, fd=#{fd}" } io_mode = interest_to_io_mode(interest) io = IO.new(fd, io_mode, autoclose: false) @monitor = Monitor.new(io) while @monitor.readiness == nil cancelled = wait_io(interest) if cancelled dbg { "#{self.class}#register_handle async cancel handle_id=#{handle_id}, fd=#{fd}" } break end dbg { "#{self.class}#register_handle async resumes readiness=#{@monitor.readiness}, handle_id=#{handle_id}, fd=#{fd}" } events = readiness_to_events(@monitor.readiness) unless events.nil? dispatch(events) break end dbg { "#{self.class}#register_handle async not ready readiness=#{@monitor.readiness}, handle_id=#{handle_id}, fd=#{fd}" } end end dbg { "#{self.class}#register_handle invokes fiber=0x#{task.fiber.object_id.to_s(16)} handle_id=#{handle_id}, fd=#{fd}" } task.run dbg { "#{self.class}#register_handle ends handle_id=#{handle_id}, fd=#{fd}" } end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/libvirt_async/handle.rb', line 105 def to_s "#<#{self.class}:0x#{object_id.to_s(16)} handle_id=#{handle_id} fd=#{fd} events=#{events} monitor=#{monitor}>" end |
#unregister ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/libvirt_async/handle.rb', line 93 def unregister dbg { "#{self.class}#unregister handle_id=#{handle_id}, fd=#{fd}" } if @monitor.nil? dbg { "#{self.class}#unregister already unregistered handle_id=#{handle_id}, fd=#{fd}" } return end @monitor.close @monitor = nil end |