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

View File

@ -78,13 +78,18 @@ 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) {
case *net.OpError:
ne := err.(*net.OpError)
if ne.Timeout() {
return SocketErrorEnumTIMOUT return SocketErrorEnumTIMOUT
} }
n, ok := err.(*net.OpError).Err.(*os.SyscallError).Err.(syscall.Errno) switch ne.Err.(type) {
if !ok { case *os.SyscallError:
return SocketErrorEnumUNKNOWN sce := ne.Err.(*os.SyscallError)
} switch sce.Err.(type) {
case syscall.Errno:
n := sce.Err.(syscall.Errno)
switch n { switch n {
case syscall.EHOSTUNREACH: case syscall.EHOSTUNREACH:
return SocketErrorEnumHOSTUNREACH return SocketErrorEnumHOSTUNREACH
@ -93,6 +98,37 @@ func ToSocketErrorEnum(err error) SocketErrorEnum {
default: default:
return SocketErrorEnumUNKNOWN 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
// }
} }