File tree Expand file tree Collapse file tree 2 files changed +10
-26
lines changed Expand file tree Collapse file tree 2 files changed +10
-26
lines changed Original file line number Diff line number Diff line change 19
19
package dialer
20
20
21
21
import (
22
+ "errors"
22
23
"fmt"
23
24
"net"
24
- "os"
25
25
"strings"
26
26
"syscall"
27
27
"time"
@@ -34,16 +34,7 @@ func DialAddress(address string) string {
34
34
}
35
35
36
36
func isNoent (err error ) bool {
37
- if err != nil {
38
- if nerr , ok := err .(* net.OpError ); ok {
39
- if serr , ok := nerr .Err .(* os.SyscallError ); ok {
40
- if serr .Err == syscall .ENOENT {
41
- return true
42
- }
43
- }
44
- }
45
- }
46
- return false
37
+ return errors .Is (err , syscall .ENOENT )
47
38
}
48
39
49
40
func dialer (address string , timeout time.Duration ) (net.Conn , error ) {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
22
22
"bufio"
23
23
"context"
24
24
"crypto/sha256"
25
+ "errors"
25
26
"fmt"
26
27
"io"
27
28
"math"
@@ -173,22 +174,14 @@ func RemoveSocket(address string) error {
173
174
// SocketEaddrinuse returns true if the provided error is caused by the
174
175
// EADDRINUSE error number
175
176
func SocketEaddrinuse (err error ) bool {
176
- netErr , ok := err .(* net.OpError )
177
- if ! ok {
178
- return false
179
- }
180
- if netErr .Op != "listen" {
181
- return false
182
- }
183
- syscallErr , ok := netErr .Err .(* os.SyscallError )
184
- if ! ok {
185
- return false
186
- }
187
- errno , ok := syscallErr .Err .(syscall.Errno )
188
- if ! ok {
189
- return false
177
+ var netErr * net.OpError
178
+ if errors .As (err , & netErr ) {
179
+ if netErr .Op != "listen" {
180
+ return false
181
+ }
182
+ return errors .Is (err , syscall .EADDRINUSE )
190
183
}
191
- return errno == syscall . EADDRINUSE
184
+ return false
192
185
}
193
186
194
187
// CanConnect returns true if the socket provided at the address
You can’t perform that action at this time.
0 commit comments