This commit is contained in:
esrrhs 2018-12-20 14:15:36 +08:00
parent 3ed77ca749
commit ab0935816d

View File

@ -112,16 +112,12 @@ func (p *Client) Run() {
interval := time.NewTicker(time.Second) interval := time.NewTicker(time.Second)
defer interval.Stop() defer interval.Stop()
intervalPing := time.NewTicker(time.Second * 10)
defer interval.Stop()
for { for {
select { select {
case <-interval.C: case <-interval.C:
p.checkTimeoutConn() p.checkTimeoutConn()
p.showNet()
case <-intervalPing.C:
p.ping() p.ping()
p.showNet()
case r := <-recv: case r := <-recv:
p.processPacket(r) p.processPacket(r)
} }
@ -231,10 +227,12 @@ func (p *Client) checkTimeoutConn() {
} }
func (p *Client) ping() { func (p *Client) ping() {
now := time.Now() if p.sendPacket == 0 && p.recvPacket == 0 {
b, _ := now.MarshalBinary() now := time.Now()
sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto) b, _ := now.MarshalBinary()
fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto) sendICMP(*p.conn, p.ipaddrServer, p.targetAddr, "", (uint32)(PING), b, p.sproto, p.rproto)
fmt.Printf("ping %s %s %d %d\n", p.addrServer, now.String(), p.sproto, p.rproto)
}
} }
func (p *Client) showNet() { func (p *Client) showNet() {