Documentation ¶
Index ¶
- Constants
- type BaseConnect
- func (c *BaseConnect) Binary(bytes []byte) (int, error)
- func (c *BaseConnect) Close() error
- func (c *BaseConnect) GetAddress() net.Addr
- func (c *BaseConnect) GetCertificate() tls.Certificate
- func (c *BaseConnect) GetConnectMgr() iface.IConnectManager
- func (c *BaseConnect) GetEpFd() int
- func (c *BaseConnect) GetFd() int
- func (c *BaseConnect) GetHandshakeCompleted() bool
- func (c *BaseConnect) GetID() int
- func (c *BaseConnect) GetLastMessageTime() time.Time
- func (c *BaseConnect) GetPacker() iface.IPacker
- func (c *BaseConnect) GetPoller() iface.IPoller
- func (c *BaseConnect) GetQueryStringParam() url.Values
- func (c *BaseConnect) GetTLSEnable() bool
- func (c *BaseConnect) GetTLSLayer() *tls.Conn
- func (c *BaseConnect) GetWriteBuff() ([]byte, bool)
- func (c *BaseConnect) IsUDP() bool
- func (c *BaseConnect) LocalAddr() net.Addr
- func (c *BaseConnect) ProceedWrite() error
- func (c *BaseConnect) Read(bs []byte) (int, error)
- func (c *BaseConnect) RemoteAddr() net.Addr
- func (c *BaseConnect) Send(msgID uint32, bs []byte) (int, error)
- func (c *BaseConnect) SetDeadline(t time.Time) error
- func (c *BaseConnect) SetEpFd(epfd int)
- func (c *BaseConnect) SetHandshakeCompleted()
- func (c *BaseConnect) SetLastMessageTime(duration time.Time)
- func (c *BaseConnect) SetPoller(poller iface.IPoller)
- func (c *BaseConnect) SetReadDeadline(t time.Time) error
- func (c *BaseConnect) SetState(state common.ConnectState)
- func (c *BaseConnect) SetWriteBuff(bytes []byte)
- func (c *BaseConnect) SetWriteDeadline(t time.Time) error
- func (c *BaseConnect) Text(bytes []byte) (int, error)
- func (c *BaseConnect) Write(dataPack []byte) (int, error)
- type ConnectManager
- func (c *ConnectManager) Add(conn iface.IConnect) int
- func (c *ConnectManager) ClearAll()
- func (c *ConnectManager) ClearByEpFd(epfd int)
- func (c *ConnectManager) Get(connFD int) iface.IConnect
- func (c *ConnectManager) GetConnects() []iface.IConnect
- func (c *ConnectManager) HeartbeatCheck()
- func (c *ConnectManager) Len() int
- func (c *ConnectManager) Remove(conn iface.IConnect)
- type MiddlewareGroup
- type Option
- func WithHeartbeatCheckInterval(interval time.Duration) Option
- func WithHeartbeatIdleTime(idleTime time.Duration) Option
- func WithHooks(hooks iface.IHooks) Option
- func WithLogOutput(output io.Writer) Option
- func WithMaxBodyLength(length uint32) Option
- func WithNumEventLoop(numEventLoop int) Option
- func WithPacker(packer iface.IPacker) Option
- func WithTCPKeepAlive(duration time.Duration) Option
- func WithTLSConfig(config *tls.Config) Option
- func WithTls(certFile, keyFile string) Option
- func WithUDPPacketBufferLength(length uint) Option
- type Options
- type RouterMgr
- func (r *RouterMgr) Add(msgID uint32, router iface.IRouter)
- func (r *RouterMgr) Conversion(middlewares []iface.MiddlewareFunc) []iface.IStage
- func (r *RouterMgr) Dispatch(ctx iface.IContext, options *Options)
- func (r *RouterMgr) Do(ctx iface.IContext) error
- func (r *RouterMgr) Get(msgID uint32) (iface.IRouter, error)
- func (r *RouterMgr) NewGroup(callable iface.MiddlewareFunc, more ...iface.MiddlewareFunc) iface.IMiddlewareGroup
- func (r *RouterMgr) ResolveGroup() error
- type Server
- func (s *Server) AddRouter(msgID uint32, router iface.IRouter)
- func (s *Server) Group(callable iface.MiddlewareFunc, more ...iface.MiddlewareFunc) iface.IMiddlewareGroup
- func (s *Server) Start()
- func (s *Server) Stop()
- func (s *Server) TotalConnect() int
- func (s *Server) Use(callable iface.MiddlewareFunc) *Server
Constants ¶
const ( CONTINUATION = iota TEXTMODE BINMODE CLOSE = 8 PING = 9 PONG = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseConnect ¶ added in v0.1.5
func (*BaseConnect) Binary ¶ added in v0.1.5
func (c *BaseConnect) Binary(bytes []byte) (int, error)
Binary ..
func (*BaseConnect) GetAddress ¶ added in v0.1.5
func (c *BaseConnect) GetAddress() net.Addr
func (*BaseConnect) GetCertificate ¶ added in v0.1.5
func (c *BaseConnect) GetCertificate() tls.Certificate
GetCertificate 获取tls证书配置
func (*BaseConnect) GetConnectMgr ¶ added in v0.1.5
func (c *BaseConnect) GetConnectMgr() iface.IConnectManager
GetConnectMgr 获取connectMgr
func (*BaseConnect) GetEpFd ¶ added in v0.1.5
func (c *BaseConnect) GetEpFd() int
GetEpFd 获取这个连接的epoll fd
func (*BaseConnect) GetHandshakeCompleted ¶ added in v0.1.5
func (c *BaseConnect) GetHandshakeCompleted() bool
func (*BaseConnect) GetLastMessageTime ¶ added in v0.1.5
func (c *BaseConnect) GetLastMessageTime() time.Time
GetLastMessageTime .
func (*BaseConnect) GetPacker ¶ added in v0.1.5
func (c *BaseConnect) GetPacker() iface.IPacker
GetPacker 获取packer
func (*BaseConnect) GetPoller ¶ added in v0.1.5
func (c *BaseConnect) GetPoller() iface.IPoller
GetPoller ..
func (*BaseConnect) GetQueryStringParam ¶ added in v1.0.1
func (c *BaseConnect) GetQueryStringParam() url.Values
func (*BaseConnect) GetTLSEnable ¶ added in v0.1.5
func (c *BaseConnect) GetTLSEnable() bool
func (*BaseConnect) GetTLSLayer ¶ added in v0.1.5
func (c *BaseConnect) GetTLSLayer() *tls.Conn
GetTLSLayer 获取TLS层的对象
func (*BaseConnect) GetWriteBuff ¶ added in v0.1.5
func (c *BaseConnect) GetWriteBuff() ([]byte, bool)
GetWriteBuff .
func (*BaseConnect) LocalAddr ¶ added in v0.1.5
func (c *BaseConnect) LocalAddr() net.Addr
LocalAddr ..
func (*BaseConnect) ProceedWrite ¶ added in v0.1.5
func (c *BaseConnect) ProceedWrite() error
ProceedWrite 继续将未发送完毕的数据发送出去
func (*BaseConnect) Read ¶ added in v0.1.5
func (c *BaseConnect) Read(bs []byte) (int, error)
Read 读取数据
func (*BaseConnect) RemoteAddr ¶ added in v0.1.5
func (c *BaseConnect) RemoteAddr() net.Addr
RemoteAddr ..
func (*BaseConnect) Send ¶ added in v0.1.5
func (c *BaseConnect) Send(msgID uint32, bs []byte) (int, error)
Send 会被重写,不会执行到这里
func (*BaseConnect) SetDeadline ¶ added in v0.1.5
func (c *BaseConnect) SetDeadline(t time.Time) error
SetDeadline ..
func (*BaseConnect) SetEpFd ¶ added in v0.1.5
func (c *BaseConnect) SetEpFd(epfd int)
SetEpFd 设置这个连接属于哪个epoll
func (*BaseConnect) SetHandshakeCompleted ¶ added in v0.1.5
func (c *BaseConnect) SetHandshakeCompleted()
func (*BaseConnect) SetLastMessageTime ¶ added in v0.1.5
func (c *BaseConnect) SetLastMessageTime(duration time.Time)
SetLastMessageTime .
func (*BaseConnect) SetPoller ¶ added in v0.1.5
func (c *BaseConnect) SetPoller(poller iface.IPoller)
SetPoller .
func (*BaseConnect) SetReadDeadline ¶ added in v0.1.5
func (c *BaseConnect) SetReadDeadline(t time.Time) error
SetReadDeadline ..
func (*BaseConnect) SetState ¶ added in v0.1.5
func (c *BaseConnect) SetState(state common.ConnectState)
SetState state取值范围 0 离线,1 在线,2 epoll状态是可写,3 epoll状态是可读
func (*BaseConnect) SetWriteBuff ¶ added in v0.1.5
func (c *BaseConnect) SetWriteBuff(bytes []byte)
SetWriteBuff .
func (*BaseConnect) SetWriteDeadline ¶ added in v0.1.5
func (c *BaseConnect) SetWriteDeadline(t time.Time) error
SetWriteDeadline ..
type ConnectManager ¶
ConnectManager 所有连接都保存在这里
func (*ConnectManager) ClearByEpFd ¶
func (c *ConnectManager) ClearByEpFd(epfd int)
ClearByEpFd 删除在这个epfd上管理的所有连接,只有这个epoll出现错误的时候才会调用这个方法 一份数据最好不要存多个地方,在一个地方统一管理
func (*ConnectManager) Get ¶
func (c *ConnectManager) Get(connFD int) iface.IConnect
Get 通过connID获取连接实例
func (*ConnectManager) GetConnects ¶ added in v0.1.1
func (c *ConnectManager) GetConnects() []iface.IConnect
GetConnects 获取所有连接
func (*ConnectManager) HeartbeatCheck ¶ added in v0.0.8
func (c *ConnectManager) HeartbeatCheck()
HeartbeatCheck 心跳检测
type MiddlewareGroup ¶ added in v0.1.7
type MiddlewareGroup struct {
// contains filtered or unexported fields
}
func (*MiddlewareGroup) AddRouter ¶ added in v0.1.7
func (m *MiddlewareGroup) AddRouter(msgID uint32, router iface.IRouter)
AddRouter 添加路由
func (*MiddlewareGroup) GetMiddlewares ¶ added in v0.1.7
func (m *MiddlewareGroup) GetMiddlewares() []iface.MiddlewareFunc
func (*MiddlewareGroup) GetRouters ¶ added in v0.1.7
func (m *MiddlewareGroup) GetRouters() map[uint32]iface.IRouter
type Option ¶
type Option = func(opts *Options)
func WithHeartbeatCheckInterval ¶ added in v0.0.8
WithHeartbeatCheckInterval 服务端多长时间检测一次客户端心跳
func WithHeartbeatIdleTime ¶ added in v0.0.8
WithHeartbeatIdleTime 允许连接最大空闲时间,也就是允许连接最长多少时间不发送消息
func WithMaxBodyLength ¶ added in v0.0.8
WithMaxBodyLength 配置包体部分最大长度
func WithNumEventLoop ¶
WithNumEventLoop event-loop数量配置
func WithTCPKeepAlive ¶
WithTCPKeepAlive 设置时间 TCP keepalive
func WithTLSConfig ¶ added in v0.1.4
WithTLSConfig 自定义tls配置,更灵活,如果WithTls,和WithTLSConfig同时配置,则使用WithTLSConfig
func WithUDPPacketBufferLength ¶ added in v1.0.3
WithUDPPacketBufferLength 每次读取UDP数据报的长度
type Options ¶
type Options struct { NumEventLoop int // 配置event-loop数量,默认:2 NumWorker int // 用来处理业务逻辑的goroutine数量,默认CPU核心数 LogOutput io.Writer // 日志保存目标,默认:Stdout Packer iface.IPacker // 实现这个接口可以使用自定义的封包方式 TCPKeepAlive time.Duration // TCP keepalive Hooks iface.IHooks // hooks MaxBodyLength uint32 // 包体部分最大长度,默认:0(不限制大小) HeartbeatCheckInterval time.Duration // 表示多久进行轮询一次心跳检测 HeartbeatIdleTime time.Duration // 连接最大允许空闲的时间,二者需要同时配置才会生效 TlsCertificate *tls.Certificate // tls证书 TlsEnable bool // 是否开启tls TlsConfig *tls.Config // 自定义tls配置 WebsocketHandler iface.IWebsocketHandler // websocket回调 Application common.ApplicationMode // 应用层协议类型 UDPPacketBufferLength uint // 每次读取UDP数据报的长度 }
Options 可选项配置,未配置时使用默认值
type RouterMgr ¶
type RouterMgr struct {
// contains filtered or unexported fields
}
func NewRouterMgr ¶
func NewRouterMgr() *RouterMgr
NewRouterMgr 中间件执行顺序 globalMiddleware -> routerMiddleware
func (*RouterMgr) Conversion ¶ added in v0.1.7
func (r *RouterMgr) Conversion(middlewares []iface.MiddlewareFunc) []iface.IStage
Conversion 将中间件转换为stage类型
func (*RouterMgr) NewGroup ¶ added in v0.1.7
func (r *RouterMgr) NewGroup(callable iface.MiddlewareFunc, more ...iface.MiddlewareFunc) iface.IMiddlewareGroup
NewGroup 中间一个中间件组
func (*RouterMgr) ResolveGroup ¶ added in v0.1.7
ResolveGroup 处理路由分组的数据
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Group ¶ added in v0.1.7
func (s *Server) Group(callable iface.MiddlewareFunc, more ...iface.MiddlewareFunc) iface.IMiddlewareGroup
Group 分组中间件
func (*Server) TotalConnect ¶ added in v1.0.5
TotalConnect 当前总连接数