Parent

Class/Module Index [+]

Quicksearch

Fluent::TailInput::TailWatcher::IOHandler

Attributes

io[R]

Public Class Methods

new(io, pe, &receive_lines) click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 288
def initialize(io, pe, &receive_lines)
  $log.info "following tail of #{io.path}"
  @io = io
  @pe = pe
  @receive_lines = receive_lines
  @buffer = ''.force_encoding('ASCII-8BIT')
  @iobuf = ''.force_encoding('ASCII-8BIT')
end

Public Instance Methods

close() click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 336
def close
  @io.close unless @io.closed?
end
on_notify() click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 299
def on_notify
  begin
    lines = []
    read_more = false

    begin
      while true
        if @buffer.empty?
          @io.read_nonblock(2048, @buffer)
        else
          @buffer << @io.read_nonblock(2048, @iobuf)
        end
        while line = @buffer.slice!(/.*?\n/)
          lines << line
        end
        if lines.size >= MAX_LINES_AT_ONCE
          # not to use too much memory in case the file is very large
          read_more = true
          break
        end
      end
    rescue EOFError
    end

    unless lines.empty?
      @receive_lines.call(lines)
      @pe.update_pos(@io.pos - @buffer.bytesize)
    end

  end while read_more

rescue
  $log.error $!.to_s
  $log.error_backtrace
  close
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.