Class: Fluent::Compat::SocketUtil::UdpHandler

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UdpHandler.



37
38
39
40
41
42
43
# File 'lib/fluent/compat/socket_util.rb', line 37

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



45
46
47
48
49
50
51
# File 'lib/fluent/compat/socket_util.rb', line 45

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
end