Use isErrClosed in Server.Serve

This commit is contained in:
Simon Ser 2021-10-05 14:02:59 +02:00
parent e4f22a8f40
commit 1626ffb97b

View File

@ -6,7 +6,6 @@ import (
"mime" "mime"
"net" "net"
"net/http" "net/http"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -197,8 +196,7 @@ func (s *Server) Serve(ln net.Listener) error {
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()
// TODO: use net.ErrClosed when available if isErrClosed(err) {
if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
return nil return nil
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to accept connection: %v", err) return fmt.Errorf("failed to accept connection: %v", err)