Use the Dial and DialTimeout function internally

This commit is contained in:
Miek Gieben 2013-11-01 09:42:55 +00:00
parent d789796e53
commit 37c7c70289

View File

@ -39,8 +39,8 @@ type Client struct {
// Exchange performs a synchronous UDP query. It sends the message m to the address // Exchange performs a synchronous UDP query. It sends the message m to the address
// contained in a and waits for an reply. // contained in a and waits for an reply.
func Exchange(m *Msg, a string) (r *Msg, err error) { func Exchange(m *Msg, a string) (r *Msg, err error) {
co := new(Conn) var co *Conn
co.Conn, err = net.DialTimeout("udp", a, dnsTimeout) co, err = DialTimeout("udp", a, dnsTimeout)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -108,15 +108,15 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
} }
func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err error) { func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err error) {
co := new(Conn)
timeout := dnsTimeout timeout := dnsTimeout
var co *Conn
if c.DialTimeout != 0 { if c.DialTimeout != 0 {
timeout = c.DialTimeout timeout = c.DialTimeout
} }
if c.Net == "" { if c.Net == "" {
co.Conn, err = net.DialTimeout("udp", a, timeout) co, err = DialTimeout("udp", a, timeout)
} else { } else {
co.Conn, err = net.DialTimeout(c.Net, a, timeout) co, err = DialTimeout(c.Net, a, timeout)
} }
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err