From 2441534a930f4cfc96eed34e26fc8574167b8f4f Mon Sep 17 00:00:00 2001 From: CHN-STUDENT Date: Mon, 14 Dec 2020 09:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clients/golang/awesomeProject/main.go | 4 ++-- clients/golang/awesomeProject/ping.go | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clients/golang/awesomeProject/main.go b/clients/golang/awesomeProject/main.go index f8cba48..cca37b9 100644 --- a/clients/golang/awesomeProject/main.go +++ b/clients/golang/awesomeProject/main.go @@ -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 diff --git a/clients/golang/awesomeProject/ping.go b/clients/golang/awesomeProject/ping.go index f203f66..5065337 100644 --- a/clients/golang/awesomeProject/ping.go +++ b/clients/golang/awesomeProject/ping.go @@ -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