server

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRouter

type BaseRouter struct{}

func (*BaseRouter) Do

func (b *BaseRouter) Do(request iface.IRequest)

Do 默认实现

type Connect

type Connect struct {
	Address net.Addr //
	// contains filtered or unexported fields
}

Connect TCP连接成功建立后,会抽象一个Connect

func (*Connect) Close

func (c *Connect) Close() error

Close 断开连接

func (*Connect) GetAddress

func (c *Connect) GetAddress() net.Addr

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) GetEpFd

func (c *Connect) GetEpFd() int

GetEpFd 获取这个连接的epoll fd

func (*Connect) GetFd

func (c *Connect) GetFd() int

GetFd 获取系统分配的fd

func (*Connect) GetHandshakeCompleted added in v0.1.0

func (c *Connect) GetHandshakeCompleted() bool

func (*Connect) GetID

func (c *Connect) GetID() int

GetID 获取连接ID

func (*Connect) GetLastMessageTime added in v0.0.8

func (c *Connect) GetLastMessageTime() time.Time

GetLastMessageTime .

func (*Connect) GetPacker

func (c *Connect) GetPacker() iface.IPacker

GetPacker 获取packer

func (*Connect) GetPoller added in v0.0.9

func (c *Connect) GetPoller() iface.IPoller

GetPoller ..

func (*Connect) GetTLSEnable added in v0.1.0

func (c *Connect) GetTLSEnable() bool

func (*Connect) GetTLSLayer added in v0.1.0

func (c *Connect) GetTLSLayer() *tls.Conn

GetTLSLayer 获取TLS层的对象

func (*Connect) GetWriteBuff added in v0.0.3

func (c *Connect) GetWriteBuff() ([]byte, bool)

GetWriteBuff .

func (*Connect) LocalAddr added in v0.1.0

func (c *Connect) LocalAddr() net.Addr

LocalAddr ..只是为了实现tls,请勿调用此方法

func (*Connect) Read

func (c *Connect) Read(bs []byte) (int, error)

Read 读取数据

func (*Connect) RemoteAddr added in v0.1.0

func (c *Connect) RemoteAddr() net.Addr

RemoteAddr ..只是为了实现tls,请勿调用此方法

func (*Connect) Send added in v0.1.0

func (c *Connect) Send(msgID uint32, bytes []byte) (int, error)

Send 写数据

func (*Connect) SetDeadline added in v0.1.0

func (c *Connect) SetDeadline(t time.Time) error

SetDeadline ..只是为了实现tls,请勿调用此方法

func (*Connect) SetEpFd

func (c *Connect) SetEpFd(epfd int)

SetEpFd 设置这个连接属于哪个epoll

func (*Connect) SetHandshakeCompleted added in v0.1.0

func (c *Connect) SetHandshakeCompleted()

func (*Connect) SetLastMessageTime added in v0.0.8

func (c *Connect) SetLastMessageTime(duration time.Time)

SetLastMessageTime 外部请勿调用

func (*Connect) SetPoller added in v0.0.3

func (c *Connect) SetPoller(poller iface.IPoller)

SetPoller .

func (*Connect) SetReadDeadline added in v0.1.0

func (c *Connect) SetReadDeadline(t time.Time) error

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

func (c *Connect) SetWriteBuff(bytes []byte)

SetWriteBuff .

func (*Connect) SetWriteDeadline added in v0.1.0

func (c *Connect) SetWriteDeadline(t time.Time) error

SetWriteDeadline ..只是为了实现tls,请勿调用此方法

func (*Connect) Write

func (c *Connect) Write(dataPack []byte) (int, error)

Write ..只是为了实现tls,请勿调用此方法,应该调用Send方法

type ConnectManager

type ConnectManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConnectManager 所有连接都保存在这里

func (*ConnectManager) Add

func (c *ConnectManager) Add(conn iface.IConnect) int

Add 添加一个连接

func (*ConnectManager) ClearAll

func (c *ConnectManager) ClearAll()

ClearAll 清除所有连接

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 心跳检测

func (*ConnectManager) Len

func (c *ConnectManager) Len() int

Len 获取有多少个连接

func (*ConnectManager) Remove

func (c *ConnectManager) Remove(conn iface.IConnect)

Remove 删除一个连接

type Option

type Option = func(opts *Options)

func WithHeartbeatCheckInterval added in v0.0.8

func WithHeartbeatCheckInterval(interval time.Duration) Option

WithHeartbeatCheckInterval 服务端多长时间检测一次客户端心跳

func WithHeartbeatIdleTime added in v0.0.8

func WithHeartbeatIdleTime(idleTime time.Duration) Option

WithHeartbeatIdleTime 允许连接最大空闲时间,也就是允许连接最长多少时间不发送消息

func WithHooks added in v0.0.2

func WithHooks(hooks iface.IHooks) Option

WithHooks hooks

func WithLogOutput

func WithLogOutput(output io.Writer) Option

WithLogOutput 日志保存目录,默认按天保存在logs目录

func WithMaxBodyLength added in v0.0.8

func WithMaxBodyLength(length uint32) Option

WithMaxBodyLength 配置包体部分最大长度

func WithNumEventLoop

func WithNumEventLoop(numEventLoop int) Option

WithNumEventLoop event-loop数量配置

func WithPacker

func WithPacker(packer iface.IPacker) Option

WithPacker 使用自定义的封包方式

func WithTCPKeepAlive

func WithTCPKeepAlive(duration time.Duration) Option

WithTCPKeepAlive 设置时间 TCP keepalive

func WithTls added in v0.1.0

func WithTls(certFile, keyFile string) Option

WithTls tls配置

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

func (*RouterMgr) Add

func (r *RouterMgr) Add(msgID uint32, router iface.IRouter)

Add 添加路由

func (*RouterMgr) Do

func (r *RouterMgr) Do(request iface.IRequest) error

func (*RouterMgr) Get

func (r *RouterMgr) Get(msgID uint32) (iface.IRouter, error)

Get 根据msgID获取路由

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(ip string, port int, opts ...Option) *Server

New 创建Server

func (*Server) AddRouter

func (s *Server) AddRouter(msgID uint32, router iface.IRouter)

AddRouter 添加路由处理

func (*Server) Start

func (s *Server) Start()

Start 启动

func (*Server) Stop

func (s *Server) Stop()

Stop 停止

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL