Fix TCP rtt
TCP wasn't returning rrt info anymore, fix this. Also add an issue_test.go where fixes for specific issues can be put. Pull the rtt for udp message up into the function where we now also set the rrt for tcp (for symmetry).
This commit is contained in:
parent
2403d251d5
commit
0985f1e8ff
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -10,22 +10,14 @@ func TestTCPRtt(t *testing.T) {
|
|||
m.SetQuestion("example.org.", TypeA)
|
||||
|
||||
c := &Client{}
|
||||
in, rtt, err := c.Exchange(m, "8.8.4.4:53")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
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)
|
||||
}
|
||||
}
|
||||
if rtt == 0 {
|
||||
t.Fatalf("expecting non zero rtt, got zero")
|
||||
}
|
||||
t.Logf("%s", in)
|
||||
|
||||
c.Net = "tcp"
|
||||
in, 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, got zero")
|
||||
}
|
||||
t.Logf("%s", in)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue