mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
use rwlock for sessions object
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user