diff --git a/trace/tcp_ipv4.go b/trace/tcp_ipv4.go index 4bb62e6..53f98b6 100644 --- a/trace/tcp_ipv4.go +++ b/trace/tcp_ipv4.go @@ -64,14 +64,26 @@ func (t *TCPTracer) Execute() (*Result, error) { t.sem = semaphore.NewWeighted(int64(t.ParallelRequests)) for ttl := 1; ttl <= t.MaxHops; ttl++ { + // 如果到达最终跳,则退出 + if t.final != -1 && ttl > t.final { + break + } for i := 0; i < t.NumMeasurements; i++ { t.wg.Add(1) go t.send(ttl) } + if t.RealtimePrinter != nil { + // 对于实时模式,应该按照TTL进行并发请求 + t.wg.Wait() + t.RealtimePrinter(&t.res, ttl-1) + } time.Sleep(1 * time.Millisecond) } - t.wg.Wait() + // 如果是表格模式,则一次性并发请求 + if t.RealtimePrinter == nil { + t.wg.Wait() + } t.res.reduce(t.final) return &t.res, nil diff --git a/trace/udp.go b/trace/udp.go index 98005f8..e9d28a1 100644 --- a/trace/udp.go +++ b/trace/udp.go @@ -53,13 +53,26 @@ func (t *UDPTracer) Execute() (*Result, error) { t.sem = semaphore.NewWeighted(int64(t.ParallelRequests)) for ttl := 1; ttl <= t.MaxHops; ttl++ { + // 如果到达最终跳,则退出 + if t.final != -1 && ttl > t.final { + break + } for i := 0; i < t.NumMeasurements; i++ { t.wg.Add(1) go t.send(ttl) - } - } - t.wg.Wait() + } + if t.RealtimePrinter != nil { + // 对于实时模式,应该按照TTL进行并发请求 + t.wg.Wait() + t.RealtimePrinter(&t.res, ttl-1) + } + time.Sleep(1 * time.Millisecond) + } + // 如果是表格模式,则一次性并发请求 + if t.RealtimePrinter == nil { + t.wg.Wait() + } t.res.reduce(t.final) return &t.res, nil