Update session.go

This commit is contained in:
风扇滑翔翼 2025-07-08 22:18:24 +08:00 committed by GitHub
parent 0c95642099
commit f14c548451
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,11 +50,13 @@ func (m *SessionManager) Count() int {
return int(m.count)
}
func (m *SessionManager) Allocate(MaxConcurrency int) *Session {
func (m *SessionManager) Allocate(Strategy ClientStrategy) *Session {
MaxConcurrency := int(Strategy.MaxConcurrency)
MaxConnection := uint16(Strategy.MaxConnection)
m.Lock()
defer m.Unlock()
if m.closed || (MaxConcurrency > 0 && len(m.sessions) >= MaxConcurrency) {
if m.closed || (MaxConcurrency > 0 && len(m.sessions) >= MaxConcurrency) || (MaxConnection > 0 && m.count >= MaxConnection) {
return nil
}