go-ping / ping

ICMP Ping library for Go
MIT License
1.32k stars 344 forks source link

Allow intervals of 0 seconds #154

Closed mem closed 3 years ago

mem commented 3 years ago

time.NewTicker doesn't like an interval of 0, but it's useful in order to send a "flood ping" (see for example https://www.freebsd.org/cgi/man.cgi?ping(8) or https://linux.die.net/man/8/ping). It would be up to the user of the library to limit the number of in-flight pings in the manner described in the manpages.

Signed-off-by: Marcelo E. Magallon marcelo.magallon@grafana.com

mem commented 3 years ago

This works but I wonder if a simpler approach would just be to set p.Interval = time.Nanosecond?

Sure, that works. That was in fact my first approach. It has the nasty side-effect of the ticker triggering as fast as it can and it keeps firing until all the packets have been received. This implementation does the same with a little less overhead and blocking that select interval case as soon as all the required packets have been sent out.