From f19da2058aac99eb626bd726309796db2cd07647 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 2 Feb 2016 15:03:56 +0000 Subject: [PATCH] actually close tcp and udp servers --- testing/servers/tcp/tcp.go | 5 ++++- testing/servers/udp/udp.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/testing/servers/tcp/tcp.go b/testing/servers/tcp/tcp.go index d4362d08..dd50b4eb 100644 --- a/testing/servers/tcp/tcp.go +++ b/testing/servers/tcp/tcp.go @@ -12,6 +12,7 @@ type Server struct { Port v2net.Port MsgProcessor func(msg []byte) []byte accepting bool + listener *net.TCPListener } func (server *Server) Start() (v2net.Destination, error) { @@ -23,6 +24,7 @@ func (server *Server) Start() (v2net.Destination, error) { if err != nil { return nil, err } + server.listener = listener go server.acceptConnections(listener) localAddr := listener.Addr().(*net.TCPAddr) return v2net.TCPDestination(v2net.IPAddress(localAddr.IP), v2net.Port(localAddr.Port)), nil @@ -55,5 +57,6 @@ func (server *Server) handleConnection(conn net.Conn) { } func (this *Server) Close() { - this.accepting = true + this.accepting = false + this.listener.Close() } diff --git a/testing/servers/udp/udp.go b/testing/servers/udp/udp.go index 4b0828bf..8f4142a0 100644 --- a/testing/servers/udp/udp.go +++ b/testing/servers/udp/udp.go @@ -11,6 +11,7 @@ type Server struct { Port v2net.Port MsgProcessor func(msg []byte) []byte accepting bool + conn *net.UDPConn } func (server *Server) Start() (v2net.Destination, error) { @@ -22,6 +23,7 @@ func (server *Server) Start() (v2net.Destination, error) { if err != nil { return nil, err } + server.conn = conn go server.handleConnection(conn) localAddr := conn.LocalAddr().(*net.UDPAddr) return v2net.UDPDestination(v2net.IPAddress(localAddr.IP), v2net.Port(localAddr.Port)), nil @@ -45,4 +47,5 @@ func (server *Server) handleConnection(conn *net.UDPConn) { func (server *Server) Close() { server.accepting = false + server.conn.Close() }