From 092e49221ea0dca9e64de843283b7765d4ed34bf Mon Sep 17 00:00:00 2001 From: r3inbowari Date: Sat, 4 May 2024 14:11:19 +0800 Subject: [PATCH] fix: wrong number of connections in saving mode --- speedtest.go | 26 +++++++++++++------------- speedtest/speedtest.go | 6 ++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/speedtest.go b/speedtest.go index 047a358..d6c8d5b 100644 --- a/speedtest.go +++ b/speedtest.go @@ -47,20 +47,20 @@ func main() { // 0. speed test setting var speedtestClient = speedtest.New(speedtest.WithUserConfig( &speedtest.UserConfig{ - UserAgent: *userAgent, - Proxy: *proxy, - Source: *source, - DnsBindSource: *dnsBindSource, - Debug: *debug, - PingMode: parseProto(*pingMode), // TCP as default - SavingMode: *savingMode, - CityFlag: *city, - LocationFlag: *location, - Keyword: *search, - NoDownload: *noDownload, - NoUpload: *noUpload, + UserAgent: *userAgent, + Proxy: *proxy, + Source: *source, + DnsBindSource: *dnsBindSource, + Debug: *debug, + PingMode: parseProto(*pingMode), // TCP as default + SavingMode: *savingMode, + MaxConnections: *thread, + CityFlag: *city, + LocationFlag: *location, + Keyword: *search, + NoDownload: *noDownload, + NoUpload: *noUpload, })) - speedtestClient.SetNThread(*thread) if *showCityList { speedtest.PrintCityList() diff --git a/speedtest/speedtest.go b/speedtest/speedtest.go index 371c9eb..3ba393d 100644 --- a/speedtest/speedtest.go +++ b/speedtest/speedtest.go @@ -46,7 +46,8 @@ type UserConfig struct { Debug bool PingMode Proto - SavingMode bool + SavingMode bool + MaxConnections int CityFlag string LocationFlag string @@ -72,8 +73,9 @@ func (s *Speedtest) NewUserConfig(uc *UserConfig) { } if uc.SavingMode { - s.SetNThread(1) // Set the number of concurrent connections to 1 + uc.MaxConnections = 1 // Set the number of concurrent connections to 1 } + s.SetNThread(uc.MaxConnections) if len(uc.CityFlag) > 0 { var err error