Class: UDPSocket

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

Instance Method Summary collapse

Methods inherited from IPSocket

getaddress, original_resolver_getaddress

Instance Method Details

#bind(host, port) ⇒ Object

:startdoc:


33
34
35
36
# File 'lib/resolver_replace/replace.rb', line 33

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

#connect(host, port) ⇒ Object

:startdoc:


41
42
43
# File 'lib/resolver_replace/replace.rb', line 41

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

#original_resolver_bindObject

:stopdoc:


31
# File 'lib/resolver_replace/replace.rb', line 31

alias original_resolver_bind bind

#original_resolver_connectObject

:stopdoc:


39
# File 'lib/resolver_replace/replace.rb', line 39

alias original_resolver_connect connect

#original_resolver_sendObject

:stopdoc:


46
# File 'lib/resolver_replace/replace.rb', line 46

alias original_resolver_send send

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

:startdoc:


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/resolver_replace/replace.rb', line 48

def send(mesg, flags, *rest)
  if rest.length == 2
    host, port = rest
    begin
      addrs = (host and host != "") ? ResolverReplace.getaddresses(host) : []
    rescue ResolverReplace.error_class => e
      raise SocketError, "#{e.class} #{e.message}"
    end
    addrs[0...-1].each {|addr|
      begin
        return original_resolver_send(mesg, flags, addr, port)
      rescue SystemCallError
      end
    }
    original_resolver_send(mesg, flags, addrs[-1], port)
  else
    original_resolver_send(mesg, flags, *rest)
  end
end