From 57937127ee5ca9332326a4313cad1b4de8893647 Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Thu, 21 May 2026 21:23:20 +0800 Subject: [PATCH] fix: windows may have <0.001ms, filter it --- internal/cli/cli.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 9f0f6de..2d53abf 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -107,19 +107,28 @@ func Run() { done := make(chan bool, 1) go func() { + probe := 0 for i := 0; infinite || i < count; i++ { start := time.Now() conn, err := net.DialTimeout("tcp", address, timeoutDuration) duration := time.Since(start) - attemptCount++ - fmt.Printf("[%d] ", i+1) if err != nil { - fmt.Printf("Connection to %s failed: %s\n", address, "timeout") + attemptCount++ + probe++ + fmt.Printf("[%d] Connection to %s failed: %s\n", probe, address, "timeout") + } else if duration < 500*time.Microsecond { + conn.Close() + if !infinite { + count++ + } + continue } else { + attemptCount++ + probe++ successCount++ successDelay = append(successDelay, duration) - fmt.Printf("Reply from %s: time=%s\n", address, fmt.Sprintf("%.3fms", float64(duration)/float64(time.Millisecond))) + fmt.Printf("[%d] Reply from %s: time=%.3fms\n", probe, address, float64(duration)/float64(time.Millisecond)) conn.Close() }