Documentation ¶
Index ¶
- Constants
- Variables
- func BlockMessageLog(msgName string) error
- func DecodeMessage(msgid uint32, data []byte) (interface{}, error)
- func EncodeMessage(msg interface{}) (data []byte, msgid uint32, err error)
- func HandlerChainCall(hlist []EventHandler, ev *Event)
- func HandlerLog(h EventHandler, ev *Event)
- func HandlerName(h EventHandler) string
- func HandlerString(h EventHandler) string
- func IsBlockedMessageByID(msgid uint32) bool
- func MessageFullName(rtype reflect.Type) string
- func MessageNameByID(id uint32) string
- func MsgLog(ev *Event)
- func RegisterCodec(name string, c Codec)
- func RegisterMessageMeta(codecName string, name string, msgType reflect.Type, id uint32)
- func VisitMessageMeta(callback func(*MessageMeta))
- type CallbackHandler
- type Codec
- type DecodePacketHandler
- type EncodePacketHandler
- type Event
- func (self *Event) Clone() *Event
- func (self *Event) FromMessage(msg interface{}) *Event
- func (self *Event) MsgName() string
- func (self *Event) MsgSize() int
- func (self *Event) MsgString() string
- func (self *Event) Parse()
- func (self *Event) PeerName() string
- func (self *Event) Result() Result
- func (self *Event) Send(data interface{})
- func (self *Event) SessionID() int64
- func (self *Event) SetResult(r Result)
- type EventHandler
- func NewCallbackHandler(userCallback func(*Event)) EventHandler
- func NewFixedLengthFrameReader(size int) EventHandler
- func NewFixedLengthFrameWriter() EventHandler
- func NewMatchMsgIDHandler(msgid uint32) EventHandler
- func NewQueuePostHandler(q EventQueue, hlist ...EventHandler) EventHandler
- func StaticDecodePacketHandler() EventHandler
- func StaticEncodePacketHandler() EventHandler
- func StaticMsgLogHandler() EventHandler
- type EventQueue
- type EventType
- type FixedLengthFrameReader
- type FixedLengthFrameWriter
- type HandlerChain
- type HandlerChainList
- type HandlerChainManager
- type HandlerChainManagerImplement
- func (self *HandlerChainManagerImplement) AddChainRecv(recv *HandlerChain) (autoID int64)
- func (self *HandlerChainManagerImplement) ChainListRecv() HandlerChainList
- func (self *HandlerChainManagerImplement) ChainRecvExists(id int64) bool
- func (self *HandlerChainManagerImplement) ChainSend() *HandlerChain
- func (self *HandlerChainManagerImplement) ChainString() string
- func (self *HandlerChainManagerImplement) CreateChainRead() *HandlerChain
- func (self *HandlerChainManagerImplement) CreateChainWrite() *HandlerChain
- func (self *HandlerChainManagerImplement) RemoveChainRecv(id int64)
- func (self *HandlerChainManagerImplement) SetChainSend(chain *HandlerChain)
- func (self *HandlerChainManagerImplement) SetReadWriteChain(read, write func() *HandlerChain)
- type MatchMsgIDHandler
- type MessageMeta
- type MsgLogHandler
- type Peer
- type PeerProfile
- type PeerProfileImplement
- func (self *PeerProfileImplement) Address() string
- func (self *PeerProfileImplement) IsRunning() bool
- func (self *PeerProfileImplement) Name() string
- func (self *PeerProfileImplement) NameOrAddress() string
- func (self *PeerProfileImplement) SetAddress(address string)
- func (self *PeerProfileImplement) SetName(name string)
- func (self *PeerProfileImplement) SetRunning(v bool)
- func (self *PeerProfileImplement) SetTag(tag interface{})
- func (self *PeerProfileImplement) Tag() interface{}
- type QueuePostHandler
- type RegisterMessageContext
- type Result
- type Session
- type SessionAccessor
- type SessionManager
- type SessionManagerImplement
- func (self *SessionManagerImplement) Add(ses Session)
- func (self *SessionManagerImplement) CloseAllSession()
- func (self *SessionManagerImplement) GetSession(id int64) Session
- func (self *SessionManagerImplement) Remove(ses Session)
- func (self *SessionManagerImplement) SessionCount() int
- func (self *SessionManagerImplement) VisitSession(callback func(Session) bool)
Constants ¶
View Source
const DefaultQueueSize = 100
Variables ¶
View Source
var EnableHandlerLog bool
View Source
var ErrCodecNotFound = errors.New("codec not found")
View Source
var (
ErrMessageNotFound = errors.New("msg not exists")
)
Functions ¶
func BlockMessageLog ¶
func DecodeMessage ¶
func EncodeMessage ¶
func HandlerChainCall ¶
func HandlerChainCall(hlist []EventHandler, ev *Event)
func HandlerLog ¶
func HandlerLog(h EventHandler, ev *Event)
func HandlerString ¶
func HandlerString(h EventHandler) string
func IsBlockedMessageByID ¶
func RegisterCodec ¶
func RegisterMessageMeta ¶
注册消息元信息(代码生成专用)
Types ¶
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
func (*CallbackHandler) Call ¶
func (self *CallbackHandler) Call(ev *Event)
type Codec ¶
type Codec interface { Encode(interface{}) ([]byte, error) Decode([]byte, interface{}) error Name() string }
func FetchCodec ¶
type DecodePacketHandler ¶
type DecodePacketHandler struct { }
func (*DecodePacketHandler) Call ¶
func (self *DecodePacketHandler) Call(ev *Event)
type EncodePacketHandler ¶
type EncodePacketHandler struct { }
func (*EncodePacketHandler) Call ¶
func (self *EncodePacketHandler) Call(ev *Event)
type Event ¶
type Event struct { UID int64 Type EventType // 事件类型 MsgID uint32 // 消息ID Msg interface{} // 消息对象 Data []byte // 消息序列化后的数据 Tag interface{} // 事件的连接, 一个处理流程后被Reset TransmitTag interface{} // 接收过程可以传递到发送过程, 不会被清空 Ses Session // 会话 ChainSend *HandlerChain // 发送handler override // contains filtered or unexported fields }
会话事件
func (*Event) FromMessage ¶
type EventHandler ¶
type EventHandler interface {
Call(*Event)
}
func NewCallbackHandler ¶
func NewCallbackHandler(userCallback func(*Event)) EventHandler
func NewFixedLengthFrameReader ¶
func NewFixedLengthFrameReader(size int) EventHandler
func NewFixedLengthFrameWriter ¶
func NewFixedLengthFrameWriter() EventHandler
func NewMatchMsgIDHandler ¶
func NewMatchMsgIDHandler(msgid uint32) EventHandler
func NewQueuePostHandler ¶
func NewQueuePostHandler(q EventQueue, hlist ...EventHandler) EventHandler
func StaticDecodePacketHandler ¶
func StaticDecodePacketHandler() EventHandler
func StaticEncodePacketHandler ¶
func StaticEncodePacketHandler() EventHandler
func StaticMsgLogHandler ¶
func StaticMsgLogHandler() EventHandler
type EventQueue ¶
type EventQueue interface { StartLoop() StopLoop(result int) // 等待退出 Wait() int // 投递事件, 通过队列到达消费者端 Post(callback func()) // 是否捕获异常 EnableCapturePanic(v bool) }
func NewEventQueue ¶
func NewEventQueue() EventQueue
func NewEventQueueByLen ¶
func NewEventQueueByLen(l int) EventQueue
type FixedLengthFrameReader ¶
type FixedLengthFrameReader struct {
// contains filtered or unexported fields
}
func (*FixedLengthFrameReader) Call ¶
func (self *FixedLengthFrameReader) Call(ev *Event)
type FixedLengthFrameWriter ¶
type FixedLengthFrameWriter struct {
// contains filtered or unexported fields
}
func (*FixedLengthFrameWriter) Call ¶
func (self *FixedLengthFrameWriter) Call(ev *Event)
type HandlerChain ¶
type HandlerChain struct {
// contains filtered or unexported fields
}
func NewHandlerChain ¶
func NewHandlerChain(objlist ...interface{}) *HandlerChain
func (*HandlerChain) Call ¶
func (self *HandlerChain) Call(ev *Event)
func (*HandlerChain) String ¶
func (self *HandlerChain) String() string
type HandlerChainList ¶
type HandlerChainList []*HandlerChain
func (HandlerChainList) Call ¶
func (self HandlerChainList) Call(ev *Event)
func (HandlerChainList) String ¶
func (self HandlerChainList) String() string
type HandlerChainManager ¶
type HandlerChainManager interface { // 添加一条接收处理链 AddChainRecv(recv *HandlerChain) int64 // 移除接收处理链, 根据添加时的id RemoveChainRecv(id int64) // 接收处理链是否存在 ChainRecvExists(id int64) bool // 获取当前的处理链(乱序) ChainListRecv() HandlerChainList // 设置发送处理链 SetChainSend(chain *HandlerChain) // 获取当前发送处理链 ChainSend() *HandlerChain // 读写链 CreateChainWrite() *HandlerChain CreateChainRead() *HandlerChain // 设置读写链 SetReadWriteChain(read, write func() *HandlerChain) }
type HandlerChainManagerImplement ¶
type HandlerChainManagerImplement struct {
// contains filtered or unexported fields
}
Peer间的共享数据
func NewHandlerChainManager ¶
func NewHandlerChainManager() *HandlerChainManagerImplement
func (*HandlerChainManagerImplement) AddChainRecv ¶
func (self *HandlerChainManagerImplement) AddChainRecv(recv *HandlerChain) (autoID int64)
func (*HandlerChainManagerImplement) ChainListRecv ¶
func (self *HandlerChainManagerImplement) ChainListRecv() HandlerChainList
func (*HandlerChainManagerImplement) ChainRecvExists ¶
func (self *HandlerChainManagerImplement) ChainRecvExists(id int64) bool
func (*HandlerChainManagerImplement) ChainSend ¶
func (self *HandlerChainManagerImplement) ChainSend() *HandlerChain
func (*HandlerChainManagerImplement) ChainString ¶
func (self *HandlerChainManagerImplement) ChainString() string
func (*HandlerChainManagerImplement) CreateChainRead ¶
func (self *HandlerChainManagerImplement) CreateChainRead() *HandlerChain
func (*HandlerChainManagerImplement) CreateChainWrite ¶
func (self *HandlerChainManagerImplement) CreateChainWrite() *HandlerChain
func (*HandlerChainManagerImplement) RemoveChainRecv ¶
func (self *HandlerChainManagerImplement) RemoveChainRecv(id int64)
func (*HandlerChainManagerImplement) SetChainSend ¶
func (self *HandlerChainManagerImplement) SetChainSend(chain *HandlerChain)
func (*HandlerChainManagerImplement) SetReadWriteChain ¶
func (self *HandlerChainManagerImplement) SetReadWriteChain(read, write func() *HandlerChain)
type MatchMsgIDHandler ¶
type MatchMsgIDHandler struct {
// contains filtered or unexported fields
}
func (*MatchMsgIDHandler) Call ¶
func (self *MatchMsgIDHandler) Call(ev *Event)
func (*MatchMsgIDHandler) String ¶
func (self *MatchMsgIDHandler) String() string
type MessageMeta ¶
type MsgLogHandler ¶
type MsgLogHandler struct { }
func (*MsgLogHandler) Call ¶
func (self *MsgLogHandler) Call(ev *Event)
type Peer ¶
type Peer interface { // 开启/关闭 Start(address string) Peer Stop() Queue() EventQueue // 基础信息 PeerProfile // 定制处理链 HandlerChainManager // 会话管理 SessionAccessor }
端, Connector或Acceptor
type PeerProfile ¶
type PeerProfileImplement ¶
type PeerProfileImplement struct {
// contains filtered or unexported fields
}
Peer间的共享数据
func NewPeerProfile ¶
func NewPeerProfile() *PeerProfileImplement
func (*PeerProfileImplement) Address ¶
func (self *PeerProfileImplement) Address() string
func (*PeerProfileImplement) IsRunning ¶
func (self *PeerProfileImplement) IsRunning() bool
func (*PeerProfileImplement) Name ¶
func (self *PeerProfileImplement) Name() string
func (*PeerProfileImplement) NameOrAddress ¶
func (self *PeerProfileImplement) NameOrAddress() string
func (*PeerProfileImplement) SetAddress ¶
func (self *PeerProfileImplement) SetAddress(address string)
func (*PeerProfileImplement) SetName ¶
func (self *PeerProfileImplement) SetName(name string)
func (*PeerProfileImplement) SetRunning ¶
func (self *PeerProfileImplement) SetRunning(v bool)
func (*PeerProfileImplement) SetTag ¶
func (self *PeerProfileImplement) SetTag(tag interface{})
func (*PeerProfileImplement) Tag ¶
func (self *PeerProfileImplement) Tag() interface{}
type QueuePostHandler ¶
type QueuePostHandler struct {
// contains filtered or unexported fields
}
func (*QueuePostHandler) Call ¶
func (self *QueuePostHandler) Call(ev *Event)
type RegisterMessageContext ¶
type RegisterMessageContext struct {
*MessageMeta
}
func RegisterHandler ¶
func RegisterHandler(p Peer, msgName string, handlers ...EventHandler) *RegisterMessageContext
注册消息处理的一系列Handler, 当有队列时, 投放到队列
func RegisterMessage ¶
func RegisterMessage(p Peer, msgName string, userCallback func(*Event)) *RegisterMessageContext
注册消息处理回调
func RegisterRawHandler ¶
func RegisterRawHandler(p Peer, msgName string, handlers ...EventHandler) *RegisterMessageContext
直接注册回调
type Session ¶
type Session interface { // 发包 Send(interface{}) // 直接发送封包 RawSend(*Event) // 断开 Close() // 标示ID ID() int64 // 归属端 FromPeer() Peer // 将一个用户数据保存在session SetTag(tag interface{}) // 取出与session关联的用户数据 Tag() interface{} // 取原始连接net.Conn RawConn() interface{} }
会话
type SessionAccessor ¶
type SessionAccessor interface { // 获取一个连接 GetSession(int64) Session // 遍历连接 VisitSession(func(Session) bool) // 连接数量 SessionCount() int // 关闭所有连接 CloseAllSession() }
会话访问
type SessionManager ¶
type SessionManager interface { SessionAccessor Add(Session) Remove(Session) }
完整功能的会话管理
func NewSessionManager ¶
func NewSessionManager() SessionManager
type SessionManagerImplement ¶
type SessionManagerImplement struct {
// contains filtered or unexported fields
}
func (*SessionManagerImplement) Add ¶
func (self *SessionManagerImplement) Add(ses Session)
func (*SessionManagerImplement) CloseAllSession ¶
func (self *SessionManagerImplement) CloseAllSession()
func (*SessionManagerImplement) GetSession ¶
func (self *SessionManagerImplement) GetSession(id int64) Session
获得一个连接
func (*SessionManagerImplement) Remove ¶
func (self *SessionManagerImplement) Remove(ses Session)
func (*SessionManagerImplement) SessionCount ¶
func (self *SessionManagerImplement) SessionCount() int
func (*SessionManagerImplement) VisitSession ¶
func (self *SessionManagerImplement) VisitSession(callback func(Session) bool)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
codec
|
|
examples
|
|
chat/proto/chatproto
Package chatproto is a generated protocol buffer package.
|
Package chatproto is a generated protocol buffer package. |
proto
|
|
binary/coredef
Generated by github.com/davyxu/cellnet/objprotogen DO NOT EDIT!
|
Generated by github.com/davyxu/cellnet/objprotogen DO NOT EDIT! |
pb/gamedef
Package gamedef is a generated protocol buffer package.
|
Package gamedef is a generated protocol buffer package. |
Click to show internal directories.
Click to hide internal directories.