Merge pull request #10174 from dcantah/simplify-errs
Chore: Simplify some syscall error checks
This commit is contained in:
commit
c0e34fb7c8
@ -19,9 +19,9 @@
|
|||||||
package dialer
|
package dialer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -34,16 +34,7 @@ func DialAddress(address string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isNoent(err error) bool {
|
func isNoent(err error) bool {
|
||||||
if err != nil {
|
return errors.Is(err, syscall.ENOENT)
|
||||||
if nerr, ok := err.(*net.OpError); ok {
|
|
||||||
if serr, ok := nerr.Err.(*os.SyscallError); ok {
|
|
||||||
if serr.Err == syscall.ENOENT {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dialer(address string, timeout time.Duration) (net.Conn, error) {
|
func dialer(address string, timeout time.Duration) (net.Conn, error) {
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
@ -173,22 +174,14 @@ func RemoveSocket(address string) error {
|
|||||||
// SocketEaddrinuse returns true if the provided error is caused by the
|
// SocketEaddrinuse returns true if the provided error is caused by the
|
||||||
// EADDRINUSE error number
|
// EADDRINUSE error number
|
||||||
func SocketEaddrinuse(err error) bool {
|
func SocketEaddrinuse(err error) bool {
|
||||||
netErr, ok := err.(*net.OpError)
|
var netErr *net.OpError
|
||||||
if !ok {
|
if errors.As(err, &netErr) {
|
||||||
return false
|
|
||||||
}
|
|
||||||
if netErr.Op != "listen" {
|
if netErr.Op != "listen" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
syscallErr, ok := netErr.Err.(*os.SyscallError)
|
return errors.Is(err, syscall.EADDRINUSE)
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
errno, ok := syscallErr.Err.(syscall.Errno)
|
|
||||||
if !ok {
|
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
return errno == syscall.EADDRINUSE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanConnect returns true if the socket provided at the address
|
// CanConnect returns true if the socket provided at the address
|
||||||
|
Loading…
Reference in New Issue
Block a user