diff options
author | Leah Neukirchen <leah@vuxu.org> | 2024-02-24 00:30:39 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2024-02-24 00:30:39 +0100 |
commit | 3a6c485329aa4e35c4b0a080154e78a775ee3a9a (patch) | |
tree | 3f79c2c2ab036b00fa2a66e813524bd60e5318df | |
parent | ff90c9bdc73f9588da936373dffff06e621fd723 (diff) | |
download | htping-3a6c485329aa4e35c4b0a080154e78a775ee3a9a.tar.gz htping-3a6c485329aa4e35c4b0a080154e78a775ee3a9a.tar.xz htping-3a6c485329aa4e35c4b0a080154e78a775ee3a9a.zip |
compute network once
-rw-r--r-- | htping.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/htping.go b/htping.go index 9e13baa..b480237 100644 --- a/htping.go +++ b/htping.go @@ -87,6 +87,7 @@ var ntotal int32 var flag4 bool var flag6 bool +var network = "tcp" var quiet bool var myHeaders headers var method string @@ -150,16 +151,7 @@ func newTransport() *transport { ForceAttemptHTTP2: !http11, DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) { - var network string - switch { - case flag4: - network = "tcp4" - case flag6: - network = "tcp6" - default: - network = "tcp" - } - return dialer.DialContext(ctx, network, addr) + return dialer.DialContext(ctx, network, addr) // force our network preference }, } @@ -334,6 +326,13 @@ func main() { os.Exit(2) } + switch { + case flag4: + network = "tcp4" + case flag6: + network = "tcp6" + } + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() |