Skip to content

Commit

Permalink
Add :wait_writeable option
Browse files Browse the repository at this point in the history
When detect EAGAIN or EWOULDBLOCK,

`:wait_writeable` is true: store the data in buffer and try to write
next time.

`:wait_writeable` is false: Raise IO::EAGAINWaitWritable
  • Loading branch information
okkez committed Dec 24, 2015
1 parent 2d96a59 commit 93903e8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/fluent/logger/fluent_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def initialize(tag_prefix = nil, *args)
end
end

@wait_writeable = true
@wait_writeable = options[:wait_writeable] if options.key?(:wait_writeable)

@last_error = {}

begin
Expand Down Expand Up @@ -168,6 +171,9 @@ def write(msg)
@pending = nil
true
rescue => e
unless wait_writeable?(e)
raise e
end
set_last_error(e)
if @pending.bytesize > @limit
@logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
Expand Down Expand Up @@ -237,6 +243,14 @@ def set_last_error(e)
# TODO: Check non GVL env
@last_error[Thread.current.object_id] = e
end

def wait_writeable?(e)
if e.instance_of?(IO::EAGAINWaitWritable)
@wait_writeable
else
true
end
end
end
end
end

0 comments on commit 93903e8

Please sign in to comment.