use rwlock for sessions object

This commit is contained in:
xtaci
2020-09-30 15:26:09 +08:00
parent f45217ee3a
commit 608bd97d7b
+3 -3
View File
@@ -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