server

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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

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

func (*BaseConnect) Binary added in v0.1.5

func (c *BaseConnect) Binary(bytes []byte) (int, error)

Binary ..

func (*BaseConnect) Close added in v0.1.5

func (c *BaseConnect) Close() error

Close 会被重写,不会执行到这里

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) GetFd added in v0.1.5

func (c *BaseConnect) GetFd() int

GetFd 获取系统分配的fd

func (*BaseConnect) GetHandshakeCompleted added in v0.1.5

func (c *BaseConnect) GetHandshakeCompleted() bool

func (*BaseConnect) GetID added in v0.1.5

func (c *BaseConnect) GetID() int

GetID 获取连接ID

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) IsUDP added in v1.0.3

func (c *BaseConnect) IsUDP() bool

IsUDP 是否为UDP

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 ..

func (*BaseConnect) Text added in v0.1.5

func (c *BaseConnect) Text(bytes []byte) (int, error)

Text ..

func (*BaseConnect) Write added in v0.1.5

func (c *BaseConnect) 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 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

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 WithTLSConfig added in v0.1.4

func WithTLSConfig(config *tls.Config) Option

WithTLSConfig 自定义tls配置,更灵活,如果WithTls,和WithTLSConfig同时配置,则使用WithTLSConfig

func WithTls added in v0.1.0

func WithTls(certFile, keyFile string) Option

WithTls tls配置 Deprecated: 建议使用WithTLSConfig,将在后续版本中删除

func WithUDPPacketBufferLength added in v1.0.3

func WithUDPPacketBufferLength(length uint) Option

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

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

Add 添加路由

func (*RouterMgr) Conversion added in v0.1.7

func (r *RouterMgr) Conversion(middlewares []iface.MiddlewareFunc) []iface.IStage

Conversion 将中间件转换为stage类型

func (*RouterMgr) Dispatch added in v0.1.7

func (r *RouterMgr) Dispatch(ctx iface.IContext, options *Options)

Dispatch 路由分发和中间件执行

func (*RouterMgr) Do

func (r *RouterMgr) Do(ctx iface.IContext) error

func (*RouterMgr) Get

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

Get 根据msgID获取路由

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

func (r *RouterMgr) ResolveGroup() error

ResolveGroup 处理路由分组的数据

type Server

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

func New

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

New 创建Server

func UDP added in v1.0.3

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

func Websocket added in v0.1.5

func Websocket(ip string, port int, handler iface.IWebsocketHandler, opts ...Option) *Server

Websocket 创建一个websocket server

func (*Server) AddRouter

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

AddRouter 添加路由处理

func (*Server) Group added in v0.1.7

Group 分组中间件

func (*Server) Start

func (s *Server) Start()

Start 启动

func (*Server) Stop

func (s *Server) Stop()

Stop 停止

func (*Server) TotalConnect added in v1.0.5

func (s *Server) TotalConnect() int

TotalConnect 当前总连接数

func (*Server) Use added in v0.1.7

func (s *Server) Use(callable iface.MiddlewareFunc) *Server

Use 全局中间件

Jump to

Keyboard shortcuts

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