Module: RightScale::RightPopen::PipeHandler

Defined in:
lib/right_popen/linux/popen3_async.rb

Instance Method Summary collapse

Instance Method Details

#drain_and_closeObject



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/right_popen/linux/popen3_async.rb', line 94

def drain_and_close
  begin
    while ready = IO.select([@handle], nil, nil, 0)
      break if @handle.eof?
      data = @handle.readpartial(4096)
      receive_data(data)
    end
  rescue Errno::EBADF, EOFError, IOError
  end
  close_connection
end

#initialize(file_handle, target, handler) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/right_popen/linux/popen3_async.rb', line 80

def initialize(file_handle, target, handler)
  # Voodoo to make sure that Ruby doesn't gc the file handle
  # (closing the stream) before we're done with it.  No, oddly
  # enough EventMachine is not good about holding on to this
  # itself.
  @handle = file_handle
  @target = target
  @data_handler = @target.method(handler)
end

#receive_data(data) ⇒ Object



90
91
92
# File 'lib/right_popen/linux/popen3_async.rb', line 90

def receive_data(data)
  @data_handler.call(data)
end