尝试修复bug

pull/92/head
CHN-STUDENT 2020-12-14 09:25:32 +08:00
parent 6caf964490
commit 2441534a93
2 changed files with 15 additions and 15 deletions

View File

@ -179,8 +179,8 @@ func getLoad() {
}
var CU_ADDR = CU + ":" + strconv.Itoa(PORBEPORT)
var CT_ADDR = CU + ":" + strconv.Itoa(PORBEPORT)
var CM_ADDR = CU + ":" + strconv.Itoa(PORBEPORT)
var CT_ADDR = CT + ":" + strconv.Itoa(PORBEPORT)
var CM_ADDR = CM + ":" + strconv.Itoa(PORBEPORT)
func getNetworkStatus() {
defaulttimeout := 1 * time.Second

View File

@ -39,13 +39,13 @@ func (pingValue *PingValue) RunCU() {
pingValue.mtx.Lock()
t := time.Now()
conn , err := net.DialTimeout("tcp",CU_ADDR,defaulttimeout)
defer conn.Close()
//defer conn.Close()
if err != nil {
fmt.Println("Error try to connect China unicom :", err)
conn.Close()
_ = conn.Close()
lostPacket += 1
} else {
conn.Close()
_ = conn.Close()
}
diffTime := time.Since(t)
//TODO:三网延迟和丢包率算法存在问题
@ -55,7 +55,7 @@ func (pingValue *PingValue) RunCU() {
pingValue.lostRate = float64(lostPacket/allPacket)
}
pingValue.ping = uint64(diffTime/time.Millisecond)
resetTime := uint64(time.Since(startTime) * time.Second)
resetTime := uint64(time.Since(startTime) / time.Second)
if resetTime > 3600 {
lostPacket = 0
allPacket = 0
@ -84,13 +84,13 @@ func (pingValue *PingValue) RunCT() {
pingValue.mtx.Lock()
t := time.Now()
conn , err := net.DialTimeout("tcp",CT_ADDR,defaulttimeout)
defer conn.Close()
//defer conn.Close()
if err != nil {
fmt.Println("Error try to connect China Telecom :", err)
conn.Close()
_ = conn.Close()
lostPacket += 1
} else {
conn.Close()
_ = conn.Close()
}
diffTime := time.Since(t)
allPacket += 1
@ -98,7 +98,7 @@ func (pingValue *PingValue) RunCT() {
pingValue.lostRate = float64(lostPacket/allPacket)
}
pingValue.ping = uint64(diffTime/time.Millisecond)
resetTime := uint64(time.Since(startTime) * time.Second)
resetTime := uint64(time.Since(startTime) / time.Second)
if resetTime > 3600 {
lostPacket = 0
allPacket = 0
@ -126,14 +126,14 @@ func (pingValue *PingValue) RunCM() {
case <-t.C:
pingValue.mtx.Lock()
t := time.Now()
conn , err := net.DialTimeout("tcp",CT_ADDR,defaulttimeout)
defer conn.Close()
conn , err := net.DialTimeout("tcp",CM_ADDR,defaulttimeout)
//defer conn.Close()
if err != nil {
fmt.Println("Error try to connect China mobile :", err)
conn.Close()
_ = conn.Close()
lostPacket += 1
} else {
conn.Close()
_ = conn.Close()
}
diffTime := time.Since(t)
allPacket += 1
@ -141,7 +141,7 @@ func (pingValue *PingValue) RunCM() {
pingValue.lostRate = float64(lostPacket/allPacket)
}
pingValue.ping = uint64(diffTime/time.Millisecond)
resetTime := uint64(time.Since(startTime) * time.Second)
resetTime := uint64(time.Since(startTime) / time.Second)
if resetTime > 3600 {
lostPacket = 0
allPacket = 0