Class: Fluent::SocketUtil::UdpHandler

Inherits:
Coolio::IO
  • Object
show all
Defined in:
lib/fluent/plugin/socket_util.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, log, body_size_limit, callback) ⇒ UdpHandler

Returns a new instance of UdpHandler.



35
36
37
38
39
40
41
# File 'lib/fluent/plugin/socket_util.rb', line 35

def initialize(io, log, body_size_limit, callback)
  super(io)
  @io = io
  @log = log
  @body_size_limit = body_size_limit
  @callback = callback
end

Instance Method Details

#on_readableObject



43
44
45
46
47
48
49
# File 'lib/fluent/plugin/socket_util.rb', line 43

def on_readable
  msg, addr = @io.recvfrom_nonblock(@body_size_limit)
  msg.chomp!
  @callback.call(msg, addr)
rescue => e
  @log.error "unexpected error", error: e, error_class: e.class
end