Skip to content

Commit

Permalink
fix timeout behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Dec 27, 2018
1 parent 227ce1f commit 673d093
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dnscrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const (
// Client contains parameters for a DNSCrypt client
type Client struct {
Proto string // Protocol ("udp" or "tcp"). Empty means "udp".
Timeout time.Duration // Timeout for read/write operations
Timeout time.Duration // Timeout for read/write operations (0 means infinite timeout)
AdjustPayloadSize bool // If true, the client will automatically add a EDNS0 RR that will advertise a larger buffer
}

Expand Down Expand Up @@ -185,7 +185,9 @@ func (c *Client) ExchangeConn(m *dns.Msg, s *ServerInfo, conn net.Conn) (*dns.Ms
}
}

conn.SetDeadline(time.Now().Add(c.Timeout))
if c.Timeout > 0 {
conn.SetDeadline(time.Now().Add(c.Timeout))
}
conn.Write(encryptedQuery)
encryptedResponse := make([]byte, maxDNSPacketSize)

Expand Down

0 comments on commit 673d093

Please sign in to comment.