alpelo object system backport test commit

This commit is contained in:
wish
2025-10-05 16:10:47 +11:00
parent 8f3624d589
commit dd36f367a9
3 changed files with 26 additions and 31 deletions

View File

@@ -49,7 +49,7 @@ type Server struct {
acceptConns chan net.Conn
deleteConns chan net.Conn
sessions map[net.Conn]*Session
objectIDs map[*Session]uint16
//objectIDs map[*Session]uint16
listener net.Listener // Listener that is created when Server.Start is called.
isShuttingDown bool
@@ -155,7 +155,7 @@ func NewServer(config *Config) *Server {
acceptConns: make(chan net.Conn),
deleteConns: make(chan net.Conn),
sessions: make(map[net.Conn]*Session),
objectIDs: make(map[*Session]uint16),
//objectIDs: make(map[*Session]uint16),
stages: make(map[string]*Stage),
userBinaryParts: make(map[userBinaryPartID][]byte),
semaphore: make(map[string]*Semaphore),
@@ -280,6 +280,20 @@ func (s *Server) manageSessions() {
}
}
func (s *Server) getObjectId() uint16 {
ids := make(map[uint16]struct{})
for _, sess := range s.sessions {
ids[sess.objectID] = struct{}{}
}
for i := uint16(1); i < 100; i++ {
if _, ok := ids[i]; !ok {
return i
}
}
s.logger.Warn("object ids overflowed", zap.Int("sessions", len(s.sessions)))
return 0
}
func (s *Server) invalidateSessions() {
for {
if s.isShuttingDown {