Sha256: 4df724116a43d743c99cd04e5089124e0b989402cfd234fd070c3f3e4b8435a5

Contents?: true

Size: 833 Bytes

Versions: 16

Compression:

Stored size: 833 Bytes

Contents

require 'eventmachine'

module RemoteSyslog
  class UdpEndpoint
    attr_reader :logger

    def initialize(address, port, options = {})
      @address = address
      @port    = port.to_i
      @socket  = EventMachine.open_datagram_socket('0.0.0.0', 0)
      @logger  = options[:logger] || Logger.new(STDERR)

      # Try to resolve the address
      resolve_address

      # Every 60 seconds we'll see if the address has changed
      EventMachine.add_periodic_timer(60) do
        resolve_address
      end
    end

    def resolve_address
      request = EventMachine::DnsResolver.resolve(@address)
      request.callback do |addrs|
        @cached_ip = addrs.first
      end
    end

    def address
      @cached_ip || @address
    end

    def write(value)
      @socket.send_datagram(value, address, @port)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
remote_syslog-1.6.15 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.14 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.13 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.12 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.11 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.10 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.9 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.8 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.7.2 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.7.1 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.7 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.7.pre1 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.6.1 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.6 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.6.rc2 lib/remote_syslog/udp_endpoint.rb
remote_syslog-1.6.6.rc1 lib/remote_syslog/udp_endpoint.rb