1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-11-23 12:02:58 -05:00

pooled session objects

This commit is contained in:
Darien Raymond
2018-09-11 20:15:15 +02:00
parent ed1d713ef4
commit a89ff38fe6
5 changed files with 38 additions and 5 deletions

View File

@@ -101,13 +101,24 @@ type ServerSession struct {
responseHeader byte
}
var serverSessionPool = sync.Pool{
New: func() interface{} { return &ServerSession{} },
}
// NewServerSession creates a new ServerSession, using the given UserValidator.
// The ServerSession instance doesn't take ownership of the validator.
func NewServerSession(validator *vmess.TimedUserValidator, sessionHistory *SessionHistory) *ServerSession {
return &ServerSession{
userValidator: validator,
sessionHistory: sessionHistory,
}
session := serverSessionPool.Get().(*ServerSession)
session.userValidator = validator
session.sessionHistory = sessionHistory
return session
}
func ReleaseServerSession(session *ServerSession) {
session.responseWriter = nil
session.userValidator = nil
session.sessionHistory = nil
serverSessionPool.Put(session)
}
func parseSecurityType(b byte) protocol.SecurityType {