This commit is contained in:
crusader 2018-07-05 15:16:53 +09:00
parent 2d045fa966
commit 6fa01a3e43

View File

@ -78,22 +78,58 @@ func (s *SocketHealthCrawler) GetConnection(config *ocmsc.SensorConfig) (net.Con
} }
func ToSocketErrorEnum(err error) SocketErrorEnum { func ToSocketErrorEnum(err error) SocketErrorEnum {
if e, ok := err.(net.Error); ok && e.Timeout() { switch err.(type) {
return SocketErrorEnumTIMOUT case *net.OpError:
} ne := err.(*net.OpError)
n, ok := err.(*net.OpError).Err.(*os.SyscallError).Err.(syscall.Errno) if ne.Timeout() {
if !ok { return SocketErrorEnumTIMOUT
return SocketErrorEnumUNKNOWN }
} switch ne.Err.(type) {
switch n { case *os.SyscallError:
case syscall.EHOSTUNREACH: sce := ne.Err.(*os.SyscallError)
return SocketErrorEnumHOSTUNREACH switch sce.Err.(type) {
case syscall.ECONNREFUSED: case syscall.Errno:
return SocketErrorEnumCONNREFUSED n := sce.Err.(syscall.Errno)
switch n {
case syscall.EHOSTUNREACH:
return SocketErrorEnumHOSTUNREACH
case syscall.ECONNREFUSED:
return SocketErrorEnumCONNREFUSED
default:
return SocketErrorEnumUNKNOWN
}
default:
return SocketErrorEnumUNKNOWN
}
default:
return SocketErrorEnumUNKNOWN
}
default: default:
return SocketErrorEnumUNKNOWN return SocketErrorEnumUNKNOWN
} }
// e, ok := err.(net.Error)
// ; ok && e.Timeout() {
// return SocketErrorEnumTIMOUT
// }
// if e, ok := err.(net.Error); ok && e.Timeout() {
// return SocketErrorEnumTIMOUT
// }
// n, ok := err.(*net.OpError).Err.(*os.SyscallError).Err.(syscall.Errno)
// if !ok {
// return SocketErrorEnumUNKNOWN
// }
// switch n {
// case syscall.EHOSTUNREACH:
// return SocketErrorEnumHOSTUNREACH
// case syscall.ECONNREFUSED:
// return SocketErrorEnumCONNREFUSED
// default:
// return SocketErrorEnumUNKNOWN
// }
} }
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig, conn net.Conn) error { func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig, conn net.Conn) error {