Skip to content

Commit 6a21e1b

Browse files
ws: do not wait if last connection established
1 parent 7b9e24c commit 6a21e1b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

exec/http/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import (
55
"crypto/sha256"
66
"encoding/hex"
77
"fmt"
8-
"github.com/BurntSushi/toml"
9-
"github.com/gin-gonic/gin"
10-
"github.com/gin-gonic/gin/binding"
11-
"github.com/jellydator/ttlcache/v2"
128
"io/ioutil"
139
"log"
1410
"net/http"
@@ -17,6 +13,11 @@ import (
1713
"os"
1814
"strconv"
1915
"time"
16+
17+
"github.com/BurntSushi/toml"
18+
"github.com/gin-gonic/gin"
19+
"github.com/gin-gonic/gin/binding"
20+
"github.com/jellydator/ttlcache/v2"
2021
)
2122

2223
var config Config
@@ -28,18 +29,18 @@ var (
2829
)
2930

3031
func init() {
31-
if len(os.Args) > 1 && os.Args[1] == "--version" {
32-
fmt.Println(fullVersion)
33-
os.Exit(0)
32+
var configFile = "./config.toml"
33+
if len(os.Args) > 1 {
34+
if os.Args[1] == "--version" {
35+
fmt.Println(fullVersion)
36+
os.Exit(0)
37+
}
38+
configFile = os.Args[1]
3439
}
3540

3641
log.Printf("network-measure HTTP %s, built at %s\n", fullVersion, buildDate)
3742
config.SetDefault()
3843

39-
var configFile = "./config.toml"
40-
if len(os.Args) > 1 {
41-
configFile = os.Args[1]
42-
}
4344
if c, err := os.ReadFile(configFile); err == nil {
4445
if err = toml.Unmarshal(c, &config); err != nil {
4546
log.Printf("Failed loading config: %s, use default settings.\n", err)

exec/ws/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ func main() {
265265
rand.Seed(time.Now().UnixNano())
266266

267267
retryCount := uint32(0)
268+
established := false
268269

269270
for {
271+
established = false
270272
identifier := fmt.Sprintf("%s.%x.%x", config.Conn.Name, time.Now().Unix(), rand.Uint64())
271273
header := http.Header{}
272274
header.Set("User-Agent", getUserAgent())
@@ -325,6 +327,7 @@ func main() {
325327
})
326328

327329
log.Printf("Connection to %s established.\n", config.Conn.Remote)
330+
established = true
328331

329332
NextMsg:
330333
for {
@@ -399,8 +402,10 @@ func main() {
399402
}
400403
icmp.GetICMPManager().Flush()
401404

402-
interval := time.Duration(config.Conn.Interval) * time.Second
403-
log.Printf("Wait %s before retry...\n", interval.String())
404-
time.Sleep(interval)
405+
if !established {
406+
interval := time.Duration(config.Conn.Interval) * time.Second
407+
log.Printf("Wait %s before retry...\n", interval.String())
408+
time.Sleep(interval)
409+
}
405410
}
406411
}

0 commit comments

Comments
 (0)