class Fluent::SocketUtil::UdpHandler

Public Class Methods

new(io, log, body_size_limit, callback, resolve_hostname = false, remove_newline = true, receive_buffer_size = nil) click to toggle source
Calls superclass method
# File lib/fluent/plugin/socket_util.rb, line 35
def initialize(io, log, body_size_limit, callback, resolve_hostname = false, remove_newline = true, receive_buffer_size = nil)
  super(io)
  if io.is_a?(UDPSocket) && receive_buffer_size
    io.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, receive_buffer_size)
  end
  @io = io
  @io.do_not_reverse_lookup = !resolve_hostname
  @log = log
  @body_size_limit = body_size_limit
  @remove_newline = remove_newline
  @callback = callback
end

Public Instance Methods

on_readable() click to toggle source
# File lib/fluent/plugin/socket_util.rb, line 48
def on_readable
  msg, addr = @io.recvfrom_nonblock(@body_size_limit)
  msg.chomp! if @remove_newline
  @callback.call(msg, addr)
rescue => e
  @log.error "unexpected error", error: e, error_class: e.class
end