Module: RightScale::RightPopen::StatusHandler

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

Instance Method Summary collapse

Instance Method Details

#drain_and_closeObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/right_popen/linux/popen3_async.rb', line 49

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) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/right_popen/linux/popen3_async.rb', line 35

def initialize(file_handle, target)
  # 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 = ""
end

#receive_data(data) ⇒ Object



45
46
47
# File 'lib/right_popen/linux/popen3_async.rb', line 45

def receive_data(data)
  @data << data
end

#unbindObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/right_popen/linux/popen3_async.rb', line 61

def unbind
  if @data.size > 0
    error_data = ::YAML.load(@data)
    status_fd_error = ::RightScale::RightPopen::ProcessError.new(
      "#{error_data['class']}: #{error_data['message']}")
    if error_data['backtrace']
      status_fd_error.set_backtrace(error_data['backtrace'])
    end
    if @target
      @target.async_exception_handler(status_fd_error) rescue nil
    end
  end
end