You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/session/session_id.go

39 lines
695 B
Go

package session
import "sync/atomic"
type IDMgr struct {
count int64
sid int64
}
func NewSessionIDMgr() *IDMgr {
return &IDMgr{}
}
// Increment the connection count
func (c *IDMgr) Increment() {
atomic.AddInt64(&c.count, 1)
}
// Decrement the connection count
func (c *IDMgr) Decrement() {
atomic.AddInt64(&c.count, -1)
}
// Count returns the connection numbers in current
func (c *IDMgr) Count() int64 {
return atomic.LoadInt64(&c.count)
}
// Reset the connection service status
func (c *IDMgr) Reset() {
atomic.StoreInt64(&c.count, 0)
atomic.StoreInt64(&c.sid, 0)
}
// SessionID returns the session id
func (c *IDMgr) SessionID() int64 {
return atomic.AddInt64(&c.sid, 1)
}