Module: RightScale::PipeHandler

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

Instance Method Summary collapse

Instance Method Details

#drain_and_closeObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/right_popen/linux/right_popen.rb', line 90

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



76
77
78
79
80
81
82
83
84
# File 'lib/right_popen/linux/right_popen.rb', line 76

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
  @handler = handler
end

#receive_data(data) ⇒ Object



86
87
88
# File 'lib/right_popen/linux/right_popen.rb', line 86

def receive_data(data)
  @target.method(@handler).call(data) if @handler
end