Documentation ¶
Index ¶
- Constants
- type Context
- func (c *Context) Broadcast(msgId uint32, msg any)
- func (c *Context) GetEventHandler() IEventHandler
- func (c *Context) GetIdleSession() ISession
- func (c *Context) GetSession(id uint64) (ISession, bool)
- func (c *Context) PushGlobalMessageQueue(msg IMessage)
- func (c *Context) RecycleSession(session ISession)
- func (c *Context) SessionCount() int32
- type DefaultNetPackager
- type GoroutinePool
- type IClient
- type IEventHandler
- type IMessage
- type INetPackager
- type IServer
- type ISession
- type Option
- func MustWithCodec(codec codec.ICodec) Option
- func MustWithLogger(l ilog.ILogger) Option
- func MustWithSessionType(t reflect.Type) Option
- func WithEventHandler(handler IEventHandler) Option
- func WithGQSize(size int32) Option
- func WithMaxSessions(max int) Option
- func WithNetPackager(packager INetPackager) Option
- func WithPoolMaxIdleRoutines(num int32) Option
- func WithPoolMaxRoutines(num int32) Option
- type PeerCommon
- type SessionCommon
- type TransportProtocol
Constants ¶
View Source
const ( MTU = 1500 // 最大传输单元 PktSizeOffset = 2 // 包体大小字段 MsgIDOffset = 4 // 消息ID字段 HeaderOffset = MsgIDOffset + MsgIDOffset //包头部分 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { //message codec codec.ICodec ilog.ILogger //net package parser INetPackager // contains filtered or unexported fields }
func NewContext ¶
func (*Context) GetEventHandler ¶
func (c *Context) GetEventHandler() IEventHandler
func (*Context) GetIdleSession ¶
func (*Context) PushGlobalMessageQueue ¶
push the message to the routine pool
func (*Context) RecycleSession ¶
func (*Context) SessionCount ¶
type GoroutinePool ¶
type GoroutinePool struct { *Context // contains filtered or unexported fields }
Lightweight goroutine pool
type IEventHandler ¶
type INetPackager ¶
type INetPackager interface { Package(s ISession, msgID uint32, v any) ([]byte, error) UnPackage(s ISession, data []byte) (IMessage, int, error) }
网络包解析器(network package)
type ISession ¶
type ISession interface { //ID ID() uint64 //close the connection Close() error //send the message to the other side Send(msgID uint32, msg any) error //remote addr RemoteAddr() net.Addr //convenient session storage data Store(value any) //load the data Load() (value any) //get the working Context GetContext() *Context }
type Option ¶
type Option func(o *Context)
func MustWithCodec ¶
Default json codec, message codec
func WithEventHandler ¶
func WithEventHandler(handler IEventHandler) Option
Default:0 means is no limit
func WithPoolMaxIdleRoutines ¶
allow max idle routines
func WithPoolMaxRoutines ¶
Default is runtime.NumCPU(), means no goroutines will be dynamically scaled
type PeerCommon ¶
type PeerCommon struct { *Context // contains filtered or unexported fields }
func (*PeerCommon) Addr ¶
func (s *PeerCommon) Addr() string
func (*PeerCommon) SetAddr ¶
func (s *PeerCommon) SetAddr(addr string)
func (*PeerCommon) WithContext ¶
func (s *PeerCommon) WithContext(c *Context)
type SessionCommon ¶
type SessionCommon struct { atomic.Value spinlock.Locker // contains filtered or unexported fields }
核心会话标志
func (*SessionCommon) Clear ¶
func (s *SessionCommon) Clear()
func (*SessionCommon) GetContext ¶
func (s *SessionCommon) GetContext() *Context
func (*SessionCommon) ID ¶
func (s *SessionCommon) ID() uint64
func (*SessionCommon) SetID ¶
func (s *SessionCommon) SetID(id uint64)
func (*SessionCommon) UpdateID ¶
func (s *SessionCommon) UpdateID(id uint64)
func (*SessionCommon) WithContext ¶
func (s *SessionCommon) WithContext(c *Context)
type TransportProtocol ¶
type TransportProtocol string
const ( TCP TransportProtocol = "tcp" KCP TransportProtocol = "kcp" UDP TransportProtocol = "udp" WS TransportProtocol = "websocket" HTTP TransportProtocol = "http" QUIC TransportProtocol = "quic" RPC TransportProtocol = "rpc" )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.