Skip to content

Commit

Permalink
use rwlock for sessions object
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Sep 30, 2020
1 parent f45217e commit 608bd97
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 608bd97

Please sign in to comment.