Skip to content

Commit

Permalink
Merge pull request #39 from okkez/use-nonblocking-write
Browse files Browse the repository at this point in the history
Use nonblocking write
  • Loading branch information
repeatedly authored Jan 25, 2019
2 parents b64c3f8 + 93903e8 commit 4c929ef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/fluent/logger/fluent_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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 @@ -229,6 +232,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 #{connection_string}: #{$!}")
Expand All @@ -246,7 +252,7 @@ def send_data(data)
unless connect?
connect!
end
@con.write data
@con.write_nonblock data
#while true
# puts "sending #{data.length} bytes"
# if data.length > 32*1024
Expand Down Expand Up @@ -298,6 +304,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 4c929ef

Please sign in to comment.