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 {
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
switch err.(type) {
case *net.OpError:
ne := err.(*net.OpError)
if ne.Timeout() {
return SocketErrorEnumTIMOUT
}
switch ne.Err.(type) {
case *os.SyscallError:
sce := ne.Err.(*os.SyscallError)
switch sce.Err.(type) {
case syscall.Errno:
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:
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 {