Documentation ¶
Index ¶
- type CarryFunc
- type IAcceptor
- type IConnect
- type IConnectEvent
- type IConnectManager
- type IContext
- type IEventLoop
- type IHooks
- type IMessage
- type IMiddlewareGroup
- type IPacker
- type IPipeline
- type IPoller
- type IRequest
- type IRouter
- type IServer
- type IStage
- type IWebsocketHandler
- type MiddlewareFunc
- type Next
- type NextFunc
- type PipeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CarryFunc ¶ added in v0.1.7
type CarryFunc = func(stack interface{}, item interface{}) interface{}
type IAcceptor ¶
type IAcceptor interface { Run(fd int, loop IEventLoop) error Exit() IncrementID() int Close() }
type IConnect ¶
type IConnect interface { Read(bs []byte) (int, error) GetFd() int GetID() int Close() error GetPacker() IPacker Send(msgID uint32, bs []byte) (int, error) GetAddress() net.Addr GetEpFd() int GetPoller() IPoller GetWriteBuff() ([]byte, bool) SetLastMessageTime(lastMessageTime time.Time) GetLastMessageTime() time.Time GetTLSEnable() bool GetHandshakeCompleted() bool SetHandshakeCompleted() GetCertificate() tls.Certificate GetTLSLayer() *tls.Conn GetConnectMgr() IConnectManager Text([]byte) (int, error) // 发送websocket text数据 Binary([]byte) (int, error) // 发送 websocket 二进制格式数据 }
type IConnectEvent ¶ added in v0.1.3
type IConnectEvent interface { DecodePacket() (IMessage, error) ProceedWrite() error SetState(state common.ConnectState) SetWriteBuff([]byte) SetEpFd(epfd int) SetPoller(poller IPoller) }
IConnectEvent 专门处理epoll/kqueue事件的方法,无需对外提供
type IConnectManager ¶
type IEventLoop ¶
type IEventLoop interface { Init(connectMgr IConnectManager) error // 初始化,也就是创建epoll Start(messageCh chan<- IContext) // 开启事件循环,也就是所有的epoll执行epoll_wait Stop() // 停止 AddRead(conn IConnect) error Remove(conn IConnect) error }
IEventLoop 事件循环抽象层,所有的epoll都是通过这个来操作
type IMiddlewareGroup ¶ added in v0.1.7
type IMiddlewareGroup interface { AddRouter(msgID uint32, router IRouter) GetMiddlewares() []MiddlewareFunc GetRouters() map[uint32]IRouter }
type IPacker ¶
type IPacker interface { Pack(msgID uint32, data []byte) ([]byte, error) // 封包 UnPack([]byte) (IMessage, error) // 解包 SetMaxBodyLength(uint32) // 设置包体最大长度限制 GetHeaderLength() uint32 // 获取头部长度 }
IPacker 数据封装抽象层
type IRouter ¶
type IRouter interface {
Do(request IRequest)
}
IRouter 路由抽象,根据业务场景实现这个接口即可,通过msgID和router对应
type IServer ¶
type IServer interface { Start() Stop() AddRouter(msgID uint32, router IRouter) SetWebSocketHandler(IWebsocketHandler) }
IServer Server抽象层
type IStage ¶ added in v0.1.7
type IStage interface {
Process(value interface{}, next NextFunc) interface{}
}
type IWebsocketHandler ¶ added in v0.1.5
type IWebsocketHandler interface { Open(connect IConnect) // onopen Message(request IRequest) // onmessage Close(connect IConnect) // onclose }
IWebsocketHandler websocket协议相关回调
type MiddlewareFunc ¶ added in v0.1.7
Click to show internal directories.
Click to hide internal directories.