package net import ( "git.noahlan.cn/northlan/nnet/interfaces" "sync" ) type SessionMgr struct { sync.RWMutex sessions map[int64]interfaces.ISession } func (m *SessionMgr) storeSession(s interfaces.ISession) { m.Lock() defer m.Unlock() m.sessions[s.ID()] = s } func (m *SessionMgr) findSession(sid int64) interfaces.ISession { m.RLock() defer m.RUnlock() return m.sessions[sid] } func (m *SessionMgr) findOrCreateSession(sid int64) interfaces.ISession { m.RLock() s, ok := m.sessions[sid] m.RUnlock() if !ok { s = newSession() m.Lock() m.sessions[s.ID()] = s m.Unlock() } return s }