Documentation ¶
Overview ¶
Package sid Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license
Package sid Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MailBox ¶
MailBox is a special container to accumulate "pending-to-send" data, in order to send N messages in a single UDP packet instead of N different messages. It will help to improve latency between client and server
func NewMailBox ¶
func NewMailBox() *MailBox
NewMailBox creates a new instance of MailBox. Please don't create a MailBox manually.
func (*MailBox) Flush ¶
Flush unpacks the MailBox to array of messages, so that each element of the array corresponds to a given Session ID. The length of result types "sids" and "messages" is guaranteed to be the same. This action will ERASE the MailBox (and theoretically it can be re-used again)
func (*MailBox) Pick ¶
Pick retrieves all messages for a given Session ID, but doesn't remove them from the MailBox
func (*MailBox) Put ¶
Put adds new message for a given Session ID, thereby appends data at the end of the resulting message. You can call Put several times, and the order of messages will be preserved "sid" - MailBox key (because a MailBox can contain data for several SIDs) "msg" - message to be appended
func (*MailBox) SetPrefix ¶
SetPrefix assigns a new prefix for a given SID, thereby prepends data in the beginning of the resulting message. NOTE: the prefix is single, i.e. this action will overwrite the existing prefix. "sid" - MailBox key (because a MailBox can contain data for several SIDs) "prefix" - arbitrary byte array to be prepended
type TSidManager ¶
TSidManager responsible for a SID distribution This component is independent.
func (*TSidManager) FreeSid ¶
func (mgr *TSidManager) FreeSid(sid Sid)
FreeSid releases the SID and brings it back to the pool
func (*TSidManager) GetSid ¶
func (mgr *TSidManager) GetSid() (Sid, *Error)
GetSid returns an arbitrary free SID. You MUST release it after the use with FreeSid(). Method throws error in case of empty SID pool
func (*TSidManager) GetUsedSidsCount ¶
func (mgr *TSidManager) GetUsedSidsCount() uint16
GetUsedSidsCount returns count of currently BUSY SIDs
type TokenManager ¶
TokenManager responsible for generating new tokens. Token is designed for validation purposes only (not for security), because Session ID (2 bytes) is not enough to identify both user and its session. E.g. if a client has been re-connected, a new token should be generated for him. This component is independent.
func NewTokenManager ¶
func NewTokenManager() *TokenManager
NewTokenManager creates a new instance of a TokenManager. Please don't create a TokenManager manually.
func (*TokenManager) GetToken ¶
func (mgr *TokenManager) GetToken(sid Sid) (token uint32, ok bool)
GetToken returns a previously issued token by a given SID (if there are no match, returns "false")
func (*TokenManager) NewToken ¶
func (mgr *TokenManager) NewToken(sid Sid) (token uint32)
NewToken generates a new randomly generated 32-bit token for a given SID (and stores it for the future reference)