class Fluent::SocketUtil::TcpHandler
Constants
- PEERADDR_FAILED
Public Class Methods
new(io, log, delimiter, callback)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/socket_util.rb, line 37 def initialize(io, log, delimiter, callback) super(io) if io.is_a?(TCPSocket) @addr = (io.peeraddr rescue PEERADDR_FAILED) opt = [1, @timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; } io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt) end @delimiter = delimiter @callback = callback @log = log @log.trace { "accepted fluent socket object_id=#{self.object_id}" } @buffer = "".force_encoding('ASCII-8BIT') end
Public Instance Methods
on_close()
click to toggle source
# File lib/fluent/plugin/socket_util.rb, line 70 def on_close @log.trace { "closed fluent socket object_id=#{self.object_id}" } end
on_connect()
click to toggle source
# File lib/fluent/plugin/socket_util.rb, line 52 def on_connect end
on_read(data)
click to toggle source
# File lib/fluent/plugin/socket_util.rb, line 55 def on_read(data) @buffer << data pos = 0 while i = @buffer.index(@delimiter, pos) msg = @buffer[pos...i] @callback.call(msg, @addr) pos = i + @delimiter.length end @buffer.slice!(0, pos) if pos > 0 rescue => e @log.error "unexpected error", :error => e, :error_class => e.class close end