Skip to content

Commit

Permalink
cmd/pingnet: throttle requests, when socket buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
dmke committed Mar 16, 2018
1 parent 0efdd37 commit c810287
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/pingnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"os"
"runtime"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -135,7 +136,16 @@ func main() {
for i := 0; i < poolSize; i++ {
go func() {
for ip := range ips {
rtt, err := pinger.PingAttempts(&ip, timeout, attempts)
var err error
var rtt time.Duration
for i := 1; ; i++ {
rtt, err = pinger.PingAttempts(&ip, timeout, attempts)
if err == nil || !strings.Contains(err.Error(), "no buffer space available") {
break
}
time.Sleep(timeout * time.Duration(i))
}

res <- &result{addr: ip, rtt: rtt, err: err}
}
wg.Done()
Expand Down

0 comments on commit c810287

Please sign in to comment.