forked from TrueCloudLab/neoneo-go
network: use net.ErrClosed to check network connection was closed
Close #1765.
This commit is contained in:
parent
2096ad6e81
commit
753d604784
1 changed files with 2 additions and 14 deletions
|
@ -1,8 +1,8 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -19,8 +19,6 @@ type TCPTransport struct {
|
|||
quit bool
|
||||
}
|
||||
|
||||
var reClosedNetwork = regexp.MustCompile(".* use of closed network connection")
|
||||
|
||||
// NewTCPTransport returns a new TCPTransport that will listen for
|
||||
// new incoming peer connections.
|
||||
func NewTCPTransport(s *Server, bindAddr string, log *zap.Logger) *TCPTransport {
|
||||
|
@ -65,7 +63,7 @@ func (t *TCPTransport) Accept() {
|
|||
t.lock.Lock()
|
||||
quit := t.quit
|
||||
t.lock.Unlock()
|
||||
if t.isCloseError(err) && quit {
|
||||
if errors.Is(err, net.ErrClosed) && quit {
|
||||
break
|
||||
}
|
||||
t.log.Warn("TCP accept error", zap.Error(err))
|
||||
|
@ -76,16 +74,6 @@ func (t *TCPTransport) Accept() {
|
|||
}
|
||||
}
|
||||
|
||||
func (t *TCPTransport) isCloseError(err error) bool {
|
||||
if opErr, ok := err.(*net.OpError); ok {
|
||||
if reClosedNetwork.Match([]byte(opErr.Error())) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Close implements the Transporter interface.
|
||||
func (t *TCPTransport) Close() {
|
||||
t.lock.Lock()
|
||||
|
|
Loading…
Reference in a new issue