Skip to content

Commit

Permalink
Close the listener after a single request
Browse files Browse the repository at this point in the history
  • Loading branch information
tobio authored and nemith committed Mar 23, 2022
1 parent 463724b commit abd6db4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tcp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ func WithListenServer(t *testing.T, test func(server string)) {
defer l.Close()

go func() {
for {
conn, err := l.Accept()
if err != nil {
fmt.Println("Failed to accept connection: ", err.Error())
continue
}

handleRequest(conn)
conn, err := l.Accept()
if err != nil {
t.Logf("Failed to accept connection: %s", err.Error())
}

handleRequest(conn)
}()

test(server)
Expand Down

0 comments on commit abd6db4

Please sign in to comment.