From 9940b69c254a3171a78256ace9b9a037cb954b17 Mon Sep 17 00:00:00 2001 From: 14March <53811984+hcraM41@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:22:19 +0800 Subject: [PATCH] Optimizing graceClose function --- network/kcp/server_conn.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/network/kcp/server_conn.go b/network/kcp/server_conn.go index 07037da..730c27e 100644 --- a/network/kcp/server_conn.go +++ b/network/kcp/server_conn.go @@ -1,6 +1,11 @@ package kcp import ( + "net" + "sync" + "sync/atomic" + "time" + "github.com/dobyte/due/v2/errors" "github.com/dobyte/due/v2/log" "github.com/dobyte/due/v2/network" @@ -9,10 +14,6 @@ import ( "github.com/dobyte/due/v2/utils/xnet" "github.com/dobyte/due/v2/utils/xtime" "github.com/xtaci/kcp-go/v5" - "net" - "sync" - "sync/atomic" - "time" ) type serverConn struct { @@ -166,7 +167,7 @@ func (c *serverConn) init(cm *serverConnMgr, id int64, conn *kcp.UDPSession) { conn.SetWriteDelay(false) conn.SetNoDelay(1, 10, 2, 1) conn.SetMtu(1500) - //conn.SetWindowSize(config.SndWnd, config.RcvWnd) + // conn.SetWindowSize(config.SndWnd, config.RcvWnd) conn.SetACKNoDelay(true) xcall.Go(c.read) @@ -198,6 +199,7 @@ func (c *serverConn) graceClose(isNeedRecycle bool) error { c.rw.RLock() c.chWrite <- chWrite{typ: closeSig} + c.close <- struct{}{} c.rw.RUnlock() <-c.done