Merge pull request #325 from miekg/issue-324

Issue 324
This commit is contained in:
Miek Gieben 2016-02-28 19:27:08 +00:00
commit cce6c130cd
2 changed files with 25 additions and 3 deletions

View File

@ -258,7 +258,7 @@ func (co *Conn) ReadMsgHeader(hdr *Header) ([]byte, error) {
}
p = make([]byte, l)
n, err = tcpRead(r, p)
co.rtt = time.Since(co.t)
default:
if co.UDPSize > MinMsgSize {
p = make([]byte, co.UDPSize)
@ -266,6 +266,7 @@ func (co *Conn) ReadMsgHeader(hdr *Header) ([]byte, error) {
p = make([]byte, MinMsgSize)
}
n, err = co.Read(p)
co.rtt = time.Since(co.t)
}
if err != nil {
@ -342,8 +343,6 @@ func (co *Conn) Read(p []byte) (n int, err error) {
if err != nil {
return n, err
}
co.rtt = time.Since(co.t)
return n, err
}

23
issue_test.go Normal file
View File

@ -0,0 +1,23 @@
package dns
// Tests that solve that an specific issue.
import "testing"
func TestTCPRtt(t *testing.T) {
m := new(Msg)
m.RecursionDesired = true
m.SetQuestion("example.org.", TypeA)
c := &Client{}
for _, proto := range []string{"udp", "tcp"} {
c.Net = proto
_, rtt, err := c.Exchange(m, "8.8.4.4:53")
if err != nil {
t.Fatal(err)
}
if rtt == 0 {
t.Fatalf("expecting non zero rtt %s, got zero", c.Net)
}
}
}