Class: NexusSW::LXD::Transport::Mixins::Rest::StdinStub

Inherits:
Object
  • Object
show all
Defined in:
lib/nexussw/lxd/transport/mixins/rest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ StdinStub

return self as an IO (un)like object



31
32
33
# File 'lib/nexussw/lxd/transport/mixins/rest.rb', line 31

def initialize(driver)
  @driver = driver
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



34
35
36
# File 'lib/nexussw/lxd/transport/mixins/rest.rb', line 34

def driver
  @driver
end

Class Method Details

.pipe(driver) ⇒ Object

return a real IO object for parity with Local Transport



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nexussw/lxd/transport/mixins/rest.rb', line 37

def self.pipe(driver)
  NIO::WebSocket::Reactor.start
  reader, writer = IO.pipe
  NIO::WebSocket::Reactor.queue_task do
    iomon = NIO::WebSocket::Reactor.selector.register(reader, :r)
    iomon.value = proc do
      data = read(iomon)
      driver.binary data if data
    end
  end
  writer
end

.read(monitor) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/nexussw/lxd/transport/mixins/rest.rb', line 54

def self.read(monitor)
  monitor.io.read_nonblock(16384)
rescue IO::WaitReadable # rubocop:disable Lint/ShadowedException
  nil
rescue Errno::ECONNRESET, EOFError, IOError
  monitor.close
  nil
end

Instance Method Details

#write(data) ⇒ Object



50
51
52
# File 'lib/nexussw/lxd/transport/mixins/rest.rb', line 50

def write(data)
  driver.binary data
end