1package moxio
2
3import (
4 "errors"
5 "net"
6 "syscall"
7)
8
9// In separate file because of import of syscall.
10
11// IsClosed returns whether i/o failed, typically because the connection is closed
12// or otherwise cannot be used for further i/o.
13//
14// Used to prevent error logging for connections that are closed.
15func IsClosed(err error) bool {
16 return errors.Is(err, net.ErrClosed) || errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) || isRemoteTLSError(err)
17}
18
19// A remote TLS client can send a message indicating failure, this makes it back to
20// us as a write error.
21func isRemoteTLSError(err error) bool {
22 var netErr *net.OpError
23 return errors.As(err, &netErr) && netErr.Op == "remote error"
24}
25