From e6db19f5fd2242ca8dee39c990e0634fe70b24c4 Mon Sep 17 00:00:00 2001 From: sjlleo Date: Wed, 8 Jun 2022 19:49:42 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=94=B9=E8=BF=9BTCP/UDP=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trace/tcp_ipv4.go | 14 +++++++++++++- trace/udp.go | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) 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