|
@@ -176,7 +176,24 @@ func (p *Peer) readLoop(errc chan<- error) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (p *Peer) pingLoop() {
|
|
func (p *Peer) pingLoop() {
|
|
|
- // TODO 实现pingLoop
|
|
|
|
|
|
|
+ ping := time.NewTimer(pingInterval)
|
|
|
|
|
+
|
|
|
|
|
+ defer p.wg.Done()
|
|
|
|
|
+ defer ping.Stop()
|
|
|
|
|
+
|
|
|
|
|
+ for {
|
|
|
|
|
+ select {
|
|
|
|
|
+ case <-ping.C:
|
|
|
|
|
+ if err := SendItems(p.rw, pingMsg); err != nil {
|
|
|
|
|
+ p.protoErr <- err
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ping.Reset(pingInterval)
|
|
|
|
|
+ case <-p.closed:
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type protoRW struct {
|
|
type protoRW struct {
|