@@ -6,20 +6,23 @@ import (
6
6
"encoding/binary"
7
7
"encoding/hex"
8
8
"fmt"
9
+ "io"
10
+ "log"
11
+ "math/rand"
12
+ "net/http"
13
+ _ "net/http/pprof"
14
+ "os"
15
+ "time"
16
+
9
17
"github.com/BurntSushi/toml"
10
18
"github.com/gin-gonic/gin"
11
19
"github.com/gin-gonic/gin/binding"
12
20
"github.com/gorilla/websocket"
13
21
json "github.com/json-iterator/go"
14
- "io/ioutil"
15
- "log"
16
- "math/rand"
17
- "net/http"
22
+
18
23
"network-measure/bind"
19
24
"network-measure/tool"
20
25
"network-measure/tool/icmp"
21
- "os"
22
- "time"
23
26
)
24
27
25
28
var config Config
@@ -237,6 +240,10 @@ func getUserAgent() string {
237
240
}
238
241
239
242
func main () {
243
+ // go func() {
244
+ // log.Println(http.ListenAndServe("localhost:6060", nil))
245
+ // }()
246
+ //
240
247
var dialer = websocket.Dialer {
241
248
HandshakeTimeout : 10 * time .Second ,
242
249
ReadBufferSize : 1048576 ,
@@ -265,7 +272,7 @@ func main() {
265
272
log .Printf ("Can't establish connection to server %s: %s\n " , config .Conn .Remote , err )
266
273
goto CleanUp
267
274
} else {
268
- log .Fatalf ("Can't establish connection to server %s: %s\n " , config .Conn .Remote , err )
275
+ log .Fatalf ("Can't establish connection to server %s: %s, Exit. \n " , config .Conn .Remote , err )
269
276
}
270
277
}
271
278
@@ -279,7 +286,6 @@ func main() {
279
286
case <- tick .C :
280
287
_ = conn .WriteMessage (websocket .PingMessage , []byte ("keep-alive" ))
281
288
case <- stopper :
282
- stopper <- struct {}{}
283
289
return
284
290
}
285
291
}()
@@ -296,7 +302,6 @@ func main() {
296
302
log .Printf ("Failed writing response: %s\n " , err )
297
303
}
298
304
case <- stopper :
299
- stopper <- struct {}{}
300
305
return
301
306
}
302
307
}
@@ -318,10 +323,10 @@ func main() {
318
323
}
319
324
320
325
if t == websocket .CloseMessage {
321
- payload , err := ioutil .ReadAll (r )
326
+ payload , err := io .ReadAll (r )
322
327
if err != nil {
323
328
log .Printf ("Connection closed. Can't read reason: %s\n " , err )
324
- stopper <- struct {}{}
329
+ close ( stopper )
325
330
goto CleanUp
326
331
}
327
332
@@ -361,7 +366,7 @@ func main() {
361
366
p := handler (reqBuffer )
362
367
select {
363
368
case <- stopper :
364
- stopper <- struct {}{}
369
+ return
365
370
case pChan <- Response {
366
371
Type : qType ,
367
372
Payload : p ,
@@ -374,12 +379,14 @@ func main() {
374
379
}
375
380
376
381
CleanUp:
382
+ close (stopper )
377
383
if conn != nil {
378
- stopper <- struct {}{}
379
384
_ = conn .Close ()
380
385
}
381
386
icmp .GetICMPManager ().Flush ()
382
387
383
- time .Sleep (time .Duration (config .Conn .Interval ) * time .Second )
388
+ interval := time .Duration (config .Conn .Interval ) * time .Second
389
+ log .Printf ("Wait %s before retry...\n " , interval .String ())
390
+ time .Sleep (interval )
384
391
}
385
392
}
0 commit comments