class FFWD::UDP::Bind
Constants
- DEFAULT_REBIND_TIMEOUT
- DEFAULT_RECEIVE_BUFFER_SIZE
Attributes
config[R]
log[R]
reporter_meta[R]
Public Class Methods
new(core, log, host, port, connection, config)
click to toggle source
# File lib/ffwd/protocol/udp/bind.rb, line 45 def initialize core, log, host, port, connection, config @log = log @peer = "#{host}:#{port}" @reporter_meta = {:component => connection.plugin_type, :listen => @peer} rebind_timeout = config[:rebind_timeout] @socket = nil info = "udp://#{@peer}" r = FFWD.retry :timeout => rebind_timeout do |a| @socket = EM.open_datagram_socket host, port, connection, self, core, config if size = config[:receive_buffer_size] log.debug "Setting receive buffer size to #{size}" @socket.set_sock_opt Socket::SOL_SOCKET, Socket::SO_RCVBUF, size end log.info "Bind on #{info} (attempt #{a})" log.info " config: #{config.inspect}" end r.error do |a, t, e| log.warning "Bind on #{info} failed, retry ##{a} in #{t}s: #{e}" if @socket @socket.close @socket = nil end end r.depend_on core core.stopping do if @socket @socket.unbind @socket = nil end log.info "Unbound #{info}" end end
prepare(opts)
click to toggle source
# File lib/ffwd/protocol/udp/bind.rb, line 29 def self.prepare opts opts[:rebind_timeout] ||= DEFAULT_REBIND_TIMEOUT opts[:receive_buffer_size] ||= DEFAULT_RECEIVE_BUFFER_SIZE opts end