Drop isErrClosed

We require a new enough Go version now.
This commit is contained in:
Simon Ser 2023-02-23 10:32:36 +01:00
parent 522f8a80d7
commit 7e891569b8
4 changed files with 4 additions and 28 deletions

View File

@ -2,6 +2,7 @@ package soju
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -163,7 +164,7 @@ func newConn(srv *Server, ic ircConn, options *connOptions) *conn {
break break
} }
} }
if err := c.conn.Close(); err != nil && !isErrClosed(err) { if err := c.conn.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
c.logger.Printf("failed to close connection: %v", err) c.logger.Printf("failed to close connection: %v", err)
} else { } else {
c.logger.Debugf("connection closed") c.logger.Debugf("connection closed")
@ -202,7 +203,7 @@ func (c *conn) Close() error {
func (c *conn) ReadMessage() (*irc.Message, error) { func (c *conn) ReadMessage() (*irc.Message, error) {
msg, err := c.conn.ReadMessage() msg, err := c.conn.ReadMessage()
if isErrClosed(err) { if errors.Is(err, net.ErrClosed) {
return nil, io.EOF return nil, io.EOF
} else if err != nil { } else if err != nil {
return nil, err return nil, err

View File

@ -1,12 +0,0 @@
//go:build !go1.16
// +build !go1.16
package soju
import (
"strings"
)
func isErrClosed(err error) bool {
return err != nil && strings.Contains(err.Error(), "use of closed network connection")
}

View File

@ -1,13 +0,0 @@
//go:build go1.16
// +build go1.16
package soju
import (
"errors"
"net"
)
func isErrClosed(err error) bool {
return errors.Is(err, net.ErrClosed)
}

View File

@ -581,7 +581,7 @@ func (s *Server) Serve(ln net.Listener, handler func(ircConn)) error {
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()
if isErrClosed(err) { if errors.Is(err, net.ErrClosed) {
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)