Class: UDPSocket

Inherits:
IPSocket show all
Defined in:
lib/resolv-replace.rb

Instance Method Summary collapse

Methods inherited from IPSocket

getaddress, original_resolv_getaddress

Instance Method Details

#bind(host, port) ⇒ Object

:startdoc:


31
32
33
34
# File 'lib/resolv-replace.rb', line 31

def bind(host, port)
  host = IPSocket.getaddress(host) if host != ""
  original_resolv_bind(host, port)
end

#connect(host, port) ⇒ Object

:startdoc:


39
40
41
# File 'lib/resolv-replace.rb', line 39

def connect(host, port)
  original_resolv_connect(IPSocket.getaddress(host), port)
end

#original_resolv_bindObject

:stopdoc:


29
# File 'lib/resolv-replace.rb', line 29

alias original_resolv_bind bind

#original_resolv_connectObject

:stopdoc:


37
# File 'lib/resolv-replace.rb', line 37

alias original_resolv_connect connect

#original_resolv_sendObject

:stopdoc:


44
# File 'lib/resolv-replace.rb', line 44

alias original_resolv_send send

#send(mesg, flags, *rest) ⇒ Object

:startdoc:


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/resolv-replace.rb', line 46

def send(mesg, flags, *rest)
  if rest.length == 2
    host, port = rest
    begin
      addrs = Resolv.getaddresses(host)
    rescue Resolv::ResolvError
      raise SocketError, "Hostname not known: #{host}"
    end
    addrs[0...-1].each {|addr|
      begin
        return original_resolv_send(mesg, flags, addr, port)
      rescue SystemCallError
      end
    }
    original_resolv_send(mesg, flags, addrs[-1], port)
  else
    original_resolv_send(mesg, flags, *rest)
  end
end