From 13ddfb32b171c2c646abd2e0de19c0a759b988b1 Mon Sep 17 00:00:00 2001 From: Vasiliev Dmitry Date: Thu, 23 Oct 2014 11:32:23 +0400 Subject: [PATCH] fix close connection && fix sleep in chan --- fastping.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fastping.go b/fastping.go index c7ca0c4..813b6d4 100644 --- a/fastping.go +++ b/fastping.go @@ -484,7 +484,15 @@ func (p *Pinger) recvICMP(conn *net.IPConn, recv chan<- *packet, ctx *context, w } } p.debugln("recvICMP(): p.recv <- packet") - recv <- &packet{bytes: bytes, addr: ra} + + select { + case recv <- &packet{bytes: bytes, addr: ra}: + case <-ctx.stop: + p.debugln("recvICMP(): <-ctx.stop") + wg.Done() + p.debugln("recvICMP(): wg.Done()") + return + } } }