forked from tevino/tcp-shaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.go
38 lines (30 loc) · 928 Bytes
/
checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// +build !linux
package tcp
import (
"net"
"time"
)
// Checker is a fake implementation.
type Checker struct{}
// NewChecker creates a Checker, parameters are ignored.
func NewChecker(zeroLinger bool) *Checker { return &Checker{} }
// InitChecker is unnecessary on this platform.
func (s *Checker) InitChecker() error { return nil }
// CheckAddr performs a TCP check with given TCP address and timeout.
// NOTE: zeroLinger is ignored on this platform.
func (s *Checker) CheckAddr(addr string, timeout time.Duration, zeroLinger ...bool) error {
conn, err := net.DialTimeout("tcp", addr, timeout)
if conn != nil {
conn.Close()
}
if opErr, ok := err.(*net.OpError); ok {
if opErr.Timeout() {
return ErrTimeout
}
}
return err
}
// Ready is always true on this platform.
func (s *Checker) Ready() bool { return true }
// Close is unnecessary on this platform.
func (s *Checker) Close() error { return nil }