From d10ec5cfa1dd0abd085c445205f96a72e5ccc6d7 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 14 Apr 2024 03:46:21 +0000 Subject: [PATCH] 1 --- main.go | 8 ++++++-- main_test.go | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 3dd6a7c..f73a5d2 100755 --- a/main.go +++ b/main.go @@ -48,7 +48,9 @@ func main() { msdChan, wait := dealConfig(ctx, config) defer wait() - defer pctx.CallCancel(ctx) + defer func() { + _ = pctx.CallCancel(ctx) + }() for { select { @@ -94,7 +96,9 @@ func dealConfig(ctx context.Context, config Config) (msgChan chan ConfigMsg, Wai <-ctx.Done() close() }() - defer pctx.CallCancel(ctx) + defer func() { + _ = pctx.CallCancel(ctx) + }() for { select { diff --git a/main_test.go b/main_test.go index 19a2e4e..d0368a8 100755 --- a/main_test.go +++ b/main_test.go @@ -70,7 +70,9 @@ func Test(t *testing.T) { } }() defer wait() - defer pctx.CallCancel(ctx) + defer func() { + _ = pctx.CallCancel(ctx) + }() time.Sleep(time.Second) if e := tcpSer("127.0.0.1:20000", "127.0.0.1:20001"); e != nil { @@ -131,7 +133,7 @@ func tcpSer(lis, to string) error { // Print the data read from the connection to the terminal // Write back the same message to the client - conn.Write([]byte("Hello TCP Client\n")) + _, _ = conn.Write([]byte("Hello TCP Client\n")) }() } @@ -218,10 +220,10 @@ func udpSer(lis, to string) error { return err } - conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) + _, _ = conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) var buf [512]byte - conn1.SetDeadline(time.Now().Add(time.Second)) + _ = conn1.SetDeadline(time.Now().Add(time.Second)) n, _, err := conn1.ReadFromUDP(buf[0:]) if err != nil { return err @@ -231,8 +233,8 @@ func udpSer(lis, to string) error { return errors.New("no match:" + string(buf[:n])) } - conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) - conn1.SetDeadline(time.Now().Add(time.Second)) + _, _ = conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) + _ = conn1.SetDeadline(time.Now().Add(time.Second)) n, _, err = conn1.ReadFromUDP(buf[0:]) if err != nil { return err @@ -286,7 +288,7 @@ func udp2tcpSer(lis, to string) error { // Print the data read from the connection to the terminal // Write back the same message to the client - conn.Write([]byte("Hello TCP Client\n")) + _, _ = conn.Write([]byte("Hello TCP Client\n")) }() } @@ -302,10 +304,10 @@ func udp2tcpSer(lis, to string) error { return err } - conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) + _, _ = conn1.WriteToUDP([]byte("Hello UDP Server\n"), udpAddr) var buf [512]byte - conn1.SetDeadline(time.Now().Add(time.Second)) + _ = conn1.SetDeadline(time.Now().Add(time.Second)) n, _, err := conn1.ReadFromUDP(buf[0:]) if err != nil { return err @@ -351,7 +353,7 @@ func tcp2udpSer(lis, to string) error { // Print the data read from the connection to the terminal // Write back the same message to the client - conn.Write([]byte("Hello UDP Client\n")) + _, _ = conn.Write([]byte("Hello UDP Client\n")) }() } -- 2.39.2