From a5edfceca2b1f6f5a5553e893a8e241767088ae9 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 20 Feb 2016 09:37:51 -0800 Subject: [PATCH] remove missinggo dep --- utp_test.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/utp_test.go b/utp_test.go index 5c2117c..62a3c3a 100644 --- a/utp_test.go +++ b/utp_test.go @@ -7,12 +7,12 @@ import ( "log" "net" "runtime" + "strconv" "sync" "testing" "time" _ "github.com/anacrolix/envpprof" - "github.com/anacrolix/missinggo" "github.com/bradfitz/iter" "github.com/stretchr/testify/require" ) @@ -113,7 +113,7 @@ func TestUTPRawConn(t *testing.T) { utpPeer := func() net.Conn { s, _ := NewSocket("udp", "") defer s.Close() - ret, err := s.Dial(fmt.Sprintf("localhost:%d", missinggo.AddrPort(l.Addr()))) + ret, err := s.Dial(fmt.Sprintf("localhost:%d", AddrPort(l.Addr()))) require.NoError(t, err) return ret }() @@ -148,7 +148,7 @@ func TestUTPRawConn(t *testing.T) { } } }() - udpAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", missinggo.AddrPort(l.Addr()))) + udpAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", AddrPort(l.Addr()))) if err != nil { t.Fatal(err) } @@ -482,3 +482,21 @@ func TestPacketReadTimeout(t *testing.T) { t.Log(a.Close()) t.Log(b.Close()) } + +// Extracts the port as an integer from an address string. +func AddrPort(addr net.Addr) int { + switch raw := addr.(type) { + case *net.UDPAddr: + return raw.Port + default: + _, port, err := net.SplitHostPort(addr.String()) + if err != nil { + panic(err) + } + i64, err := strconv.ParseInt(port, 0, 0) + if err != nil { + panic(err) + } + return int(i64) + } +}