From 608bd97d7ba75e913e7a11c09c771add11c6d7d5 Mon Sep 17 00:00:00 2001 From: xtaci Date: Wed, 30 Sep 2020 15:26:09 +0800 Subject: [PATCH] use rwlock for sessions object --- sess.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sess.go b/sess.go index 7bce126..cd02163 100644 --- a/sess.go +++ b/sess.go @@ -776,7 +776,7 @@ type ( ownConn bool // true if we created conn internally, false if provided by caller sessions map[string]*UDPSession // all sessions accepted by this Listener - sessionLock sync.Mutex + sessionLock sync.RWMutex chAccepts chan *UDPSession // Listen() backlog chSessionClosed chan net.Addr // session close queue headerSize int // the additional header to a KCP frame @@ -811,9 +811,9 @@ func (l *Listener) packetInput(data []byte, addr net.Addr) { } if dataValid { - l.sessionLock.Lock() + l.sessionLock.RLock() s, ok := l.sessions[addr.String()] - l.sessionLock.Unlock() + l.sessionLock.RUnlock() var conv, sn uint32 convValid := false