From dc06b3bde1afb45bc3f637a5eaed30c307b8a5f6 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 17 Jul 2014 20:48:28 +0300 Subject: [PATCH] undo some changes --- server_test.go | 28 ++++++++++++++++++---------- udp.go | 20 ++++++++++++++++++++ udp_linux.go | 18 ------------------ udp_other.go | 8 ++++---- udp_windows.go | 24 ++++++++++++------------ 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/server_test.go b/server_test.go index a3fc8cf9..763e25b7 100644 --- a/server_test.go +++ b/server_test.go @@ -44,36 +44,41 @@ func TestServing(t *testing.T) { time.Sleep(4e8) c := new(Client) m := new(Msg) - m.SetQuestion("miek.nl.", TypeTXT) r, _, err := c.Exchange(m, "127.0.0.1:8053") if err != nil { - t.Fatal("Failed to exchange miek.nl", err) + t.Log("Failed to exchange miek.nl", err) + t.Fail() } txt := r.Extra[0].(*TXT).Txt[0] if txt != "Hello world" { - t.Fatal("Unexpected result for miek.nl", txt, "!= Hello world") + t.Log("Unexpected result for miek.nl", txt, "!= Hello world") + t.Fail() } m.SetQuestion("example.com.", TypeTXT) r, _, err = c.Exchange(m, "127.0.0.1:8053") if err != nil { - t.Fatal("Failed to exchange example.com", err) + t.Log("Failed to exchange example.com", err) + t.Fail() } txt = r.Extra[0].(*TXT).Txt[0] if txt != "Hello example" { - t.Fatal("Unexpected result for example.com", txt, "!= Hello example") + t.Log("Unexpected result for example.com", txt, "!= Hello example") + t.Fail() } // Test Mixes cased as noticed by Ask. m.SetQuestion("eXaMplE.cOm.", TypeTXT) r, _, err = c.Exchange(m, "127.0.0.1:8053") if err != nil { - t.Fatal("Failed to exchange eXaMplE.cOm", err) + t.Log("Failed to exchange eXaMplE.cOm", err) + t.Fail() } txt = r.Extra[0].(*TXT).Txt[0] if txt != "Hello example" { - t.Fatal("Unexpected result for example.com", txt, "!= Hello example") + t.Log("Unexpected result for example.com", txt, "!= Hello example") + t.Fail() } } @@ -247,7 +252,8 @@ func TestServingLargeResponses(t *testing.T) { M.Unlock() _, _, err := c.Exchange(m, "127.0.0.1:10000") if err != nil { - t.Fatalf("Failed to exchange: %s", err.Error()) + t.Logf("Failed to exchange: %s", err.Error()) + t.Fail() } // This must fail M.Lock() @@ -255,12 +261,14 @@ func TestServingLargeResponses(t *testing.T) { M.Unlock() _, _, err = c.Exchange(m, "127.0.0.1:10000") if err == nil { - t.Fatalf("Failed to fail exchange, this should generate packet error") + t.Logf("Failed to fail exchange, this should generate packet error") + t.Fail() } // But this must work again c.UDPSize = 7000 _, _, err = c.Exchange(m, "127.0.0.1:10000") if err != nil { - t.Fatalf("Failed to exchange: %s", err.Error()) + t.Logf("Failed to exchange: %s", err.Error()) + t.Fail() } } diff --git a/udp.go b/udp.go index 432af818..dad7c684 100644 --- a/udp.go +++ b/udp.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !windows + package dns import ( @@ -38,3 +40,21 @@ func setUDPSocketOptions(conn *net.UDPConn) error { } return nil } + +// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a +// net.UDPAddr. +func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) { + oob := make([]byte, 40) + n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob) + if err != nil { + return n, nil, err + } + session := &sessionUDP{raddr, oob[:oobn]} + return n, session, err +} + +// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr. +func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) { + n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr) + return n, err +} diff --git a/udp_linux.go b/udp_linux.go index 2a4517f6..aedc7663 100644 --- a/udp_linux.go +++ b/udp_linux.go @@ -19,24 +19,6 @@ import ( "syscall" ) -// readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a -// net.UDPAddr. -func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) { - oob := make([]byte, 40) - n, oobn, _, raddr, err := conn.ReadMsgUDP(b, oob) - if err != nil { - return n, nil, err - } - session := &sessionUDP{raddr, oob[:oobn]} - return n, session, err -} - -// writeToSessionUDP acts just like net.UDPConn.WritetTo(), but uses a *sessionUDP instead of a net.Addr. -func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, error) { - n, _, err := conn.WriteMsgUDP(b, session.context, session.raddr) - return n, err -} - // setUDPSocketOptions4 prepares the v4 socket for sessions. func setUDPSocketOptions4(conn *net.UDPConn) error { file, err := conn.File() diff --git a/udp_other.go b/udp_other.go index 2ec15216..65cfe642 100644 --- a/udp_other.go +++ b/udp_other.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !linux, !windows +// +build !linux package dns @@ -15,7 +15,7 @@ import ( // We tried to adhire to some kind of naming scheme. -func setUDPSocketOptions4(conn *net.UDPConn) error { return nil } -func setUDPSocketOptions6(conn *net.UDPConn) error { return nil } -func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil } +func setUDPSocketOptions4(conn *net.UDPConn) error { return nil } +func setUDPSocketOptions6(conn *net.UDPConn) error { return nil } +func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil } func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) { return nil, nil } diff --git a/udp_windows.go b/udp_windows.go index b492e66a..3612526f 100644 --- a/udp_windows.go +++ b/udp_windows.go @@ -6,10 +6,11 @@ package dns -import ( - "net" - "syscall" -) +import "net" + +type sessionUDP struct { + raddr *net.UDPAddr +} // readFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a // net.UDPAddr. @@ -18,7 +19,7 @@ func readFromSessionUDP(conn *net.UDPConn, b []byte) (int, *sessionUDP, error) { if err != nil { return n, nil, err } - session := &sessionUDP{raddr.(*net.UDPAddr), nil} + session := &sessionUDP{raddr.(*net.UDPAddr)} return n, session, err } @@ -28,11 +29,10 @@ func writeToSessionUDP(conn *net.UDPConn, b []byte, session *sessionUDP) (int, e return n, err } -// These do nothing. See udp_linux.go for an example of how to implement this. +func (s *sessionUDP) RemoteAddr() net.Addr { return s.raddr } -// We tried to adhire to some kind of naming scheme. - -func setUDPSocketOptions4(conn *net.UDPConn) error { return nil } -func setUDPSocketOptions6(conn *net.UDPConn) error { return nil } -func getUDPSocketOptions6Only(conn *net.UDPConn) (bool, error) { return false, nil } -func getUDPSocketName(conn *net.UDPConn) (syscall.Sockaddr, error) { return nil, nil } +// setUDPSocketOptions sets the UDP socket options. +// This function is implemented on a per platform basis. See udp_*.go for more details +func setUDPSocketOptions(conn *net.UDPConn) error { + return nil +}