Documentation ¶
Index ¶
- type BaseRouter
- type Connect
- func (c *Connect) Close() error
- func (c *Connect) GetAddress() net.Addr
- func (c *Connect) GetCertificate() tls.Certificate
- func (c *Connect) GetConnectMgr() iface.IConnectManager
- func (c *Connect) GetEpFd() int
- func (c *Connect) GetFd() int
- func (c *Connect) GetHandshakeCompleted() bool
- func (c *Connect) GetID() int
- func (c *Connect) GetLastMessageTime() time.Time
- func (c *Connect) GetPacker() iface.IPacker
- func (c *Connect) GetPoller() iface.IPoller
- func (c *Connect) GetTLSEnable() bool
- func (c *Connect) GetTLSLayer() *tls.Conn
- func (c *Connect) GetWriteBuff() ([]byte, bool)
- func (c *Connect) LocalAddr() net.Addr
- func (c *Connect) Read(bs []byte) (int, error)
- func (c *Connect) RemoteAddr() net.Addr
- func (c *Connect) Send(msgID uint32, bytes []byte) (int, error)
- func (c *Connect) SetDeadline(t time.Time) error
- func (c *Connect) SetEpFd(epfd int)
- func (c *Connect) SetHandshakeCompleted()
- func (c *Connect) SetLastMessageTime(duration time.Time)
- func (c *Connect) SetPoller(poller iface.IPoller)
- func (c *Connect) SetReadDeadline(t time.Time) error
- func (c *Connect) SetState(state common.ConnectState)
- func (c *Connect) SetWriteBuff(bytes []byte)
- func (c *Connect) SetWriteDeadline(t time.Time) error
- func (c *Connect) 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 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 WithTls(certFile, keyFile string) Option
- type Options
- type RouterMgr
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
type Connect ¶
Connect TCP连接成功建立后,会抽象一个Connect
func (*Connect) GetAddress ¶
func (*Connect) GetCertificate ¶ added in v0.1.0
func (c *Connect) GetCertificate() tls.Certificate
GetCertificate 获取tls证书配置
func (*Connect) GetConnectMgr ¶ added in v0.1.1
func (c *Connect) GetConnectMgr() iface.IConnectManager
func (*Connect) GetHandshakeCompleted ¶ added in v0.1.0
func (*Connect) GetLastMessageTime ¶ added in v0.0.8
GetLastMessageTime .
func (*Connect) GetTLSEnable ¶ added in v0.1.0
func (*Connect) GetTLSLayer ¶ added in v0.1.0
GetTLSLayer 获取TLS层的对象
func (*Connect) GetWriteBuff ¶ added in v0.0.3
GetWriteBuff .
func (*Connect) RemoteAddr ¶ added in v0.1.0
RemoteAddr ..只是为了实现tls,请勿调用此方法
func (*Connect) SetDeadline ¶ added in v0.1.0
SetDeadline ..只是为了实现tls,请勿调用此方法
func (*Connect) SetHandshakeCompleted ¶ added in v0.1.0
func (c *Connect) SetHandshakeCompleted()
func (*Connect) SetLastMessageTime ¶ added in v0.0.8
SetLastMessageTime 外部请勿调用
func (*Connect) SetReadDeadline ¶ added in v0.1.0
SetReadDeadline ..只是为了实现tls,请勿调用此方法
func (*Connect) SetState ¶ added in v0.0.6
func (c *Connect) SetState(state common.ConnectState)
SetState state取值范围 0 离线,1 在线,2 epoll状态是可写,3 epoll状态是可读
func (*Connect) SetWriteBuff ¶ added in v0.0.3
SetWriteBuff .
func (*Connect) SetWriteDeadline ¶ added in v0.1.0
SetWriteDeadline ..只是为了实现tls,请勿调用此方法
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 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
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 TlsEnable bool }
Options 可选项配置,未配置时使用默认值
type RouterMgr ¶
type RouterMgr struct {
// contains filtered or unexported fields
}
func NewRouterMgr ¶
func NewRouterMgr() *RouterMgr