Skip to content

Commit

Permalink
Merge pull request #94 from ravsii/fix/ended-at
Browse files Browse the repository at this point in the history
fix: `-c` missing ended at stats
  • Loading branch information
pouriyajamshidi committed Jun 7, 2023
2 parents 4298a7b + 64aa52c commit c6d1a2d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tcping.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ func signalHandler(tcpStats *stats) {

go func() {
<-sigChan
totalRuntime := tcpStats.totalUnsuccessfulProbes + tcpStats.totalSuccessfulProbes
tcpStats.endTime = tcpStats.startTime.Add(time.Duration(totalRuntime) * time.Second)
tcpStats.printStats()
os.Exit(0)
shutdown(tcpStats)
}()
}

Expand Down Expand Up @@ -625,6 +622,15 @@ func monitorStdin(stdinChan chan string) {
}
}

// shutdown calculates endTime, prints statistics and callc os.Exit(0).
// This should be used as a main exit-point.
func shutdown(tcpStats *stats) {
totalRuntime := tcpStats.totalUnsuccessfulProbes + tcpStats.totalSuccessfulProbes
tcpStats.endTime = tcpStats.startTime.Add(time.Duration(totalRuntime) * time.Second)
tcpStats.printStats()
os.Exit(0)
}

func main() {
tcpStats := &stats{
ticker: time.NewTicker(time.Second),
Expand Down Expand Up @@ -660,8 +666,7 @@ func main() {

probeCount++
if probeCount == tcpStats.probesBeforeQuit {
tcpStats.printStats()
return
shutdown(tcpStats)
}
}
}

0 comments on commit c6d1a2d

Please sign in to comment.