znet

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: GPL-3.0 Imports: 30 Imported by: 93

Documentation

Index

Constants

View Source
const (
	// The number of stack frames to start tracing from
	// (开始追踪堆栈信息的层数)
	StackBegin = 3
	// The number of stack frames to trace until the end
	// (追踪到最后的层数)
	StackEnd = 5
)
View Source
const (
	PRE_HANDLE  ziface.HandleStep = iota // PreHandle for pre-processing
	HANDLE                               // Handle for processing
	POST_HANDLE                          // PostHandle for post-processing

	HANDLE_OVER
)
View Source
const (
	// If the Worker goroutine pool is not started, a virtual WorkerID is assigned to the MsgHandler, which is 0, for metric counting
	// After starting the Worker goroutine pool, the ID of each worker is 0,1,2,3...
	// (如果不启动Worker协程池,则会给MsgHandler分配一个虚拟的WorkerID,这个workerID为0, 便于指标统计
	// 启动了Worker协程池后,每个worker的ID为0,1,2,3...)
	WorkerIDWithoutWorkerPool int = 0
)

Variables

View Source
var AcceptDelay *acceptDelay
View Source
var RequestPool = new(sync.Pool)

Functions

func GetRequest added in v1.2.3

func GetRequest(conn ziface.IConnection, msg ziface.IMessage) ziface.IRequest

func HeatBeatDefaultHandle added in v1.1.18

func HeatBeatDefaultHandle(req ziface.IRequest)

func NewClient added in v1.1.0

func NewClient(ip string, port int, opts ...ClientOption) ziface.IClient

func NewDefaultRouterSlicesServer added in v1.1.18

func NewDefaultRouterSlicesServer(opts ...Option) ziface.IServer

NewDefaultRouterSlicesServer creates a server handle with a default RouterRecovery processor. (创建一个默认自带一个Recover处理器的服务器句柄)

func NewFuncRequest added in v1.1.18

func NewFuncRequest(conn ziface.IConnection, callFunc func()) ziface.IRequest

func NewHeartbeatChecker added in v1.1.12

func NewHeartbeatChecker(interval time.Duration) ziface.IHeartbeatChecker

func NewRequest added in v1.0.2

func NewRequest(conn ziface.IConnection, msg ziface.IMessage) ziface.IRequest

func NewServer

func NewServer(opts ...Option) ziface.IServer

NewServer creates a server handle (创建一个服务器句柄)

func NewTLSClient added in v1.1.16

func NewTLSClient(ip string, port int, opts ...ClientOption) ziface.IClient

func NewUserConfDefaultRouterSlicesServer added in v1.1.18

func NewUserConfDefaultRouterSlicesServer(config *zconf.Config, opts ...Option) ziface.IServer

NewUserConfDefaultRouterSlicesServer creates a server handle with user-configured options and a default Recover handler. If the user does not wish to use the Use method, they should use NewUserConfServer instead. (创建一个用户配置的自带一个Recover处理器的服务器句柄,如果用户不希望Use这个方法,那么应该使用NewUserConfServer)

func NewUserConfServer added in v1.0.2

func NewUserConfServer(config *zconf.Config, opts ...Option) ziface.IServer

NewUserConfServer creates a server handle using user-defined configuration (创建一个服务器句柄)

func NewWsClient added in v1.1.15

func NewWsClient(ip string, port int, opts ...ClientOption) ziface.IClient

func PutRequest added in v1.2.3

func PutRequest(request ziface.IRequest)

func RouterRecovery added in v1.1.18

func RouterRecovery(request ziface.IRequest)

RouterRecovery If you use the server obtained from initializing with NewDefaultRouterSlicesServer method, this function will be included. It is used to catch any panics that occur during request handling and attempt to record the context information. (如果使用NewDefaultRouterSlicesServer方法初始化的获得的server将自带这个函数 作用是接收业务执行上产生的panic并且尝试记录现场信息)

func RouterTime added in v1.1.18

func RouterTime(request ziface.IRequest)

RouterTime Simply accumulates the time taken by all the routing groups, but not enabled (简单累计所有路由组的耗时,不启用)

Types

type BaseRouter

type BaseRouter struct{}

BaseRouter is used as the base class when implementing a router. Depending on the needs, the methods of this base class can be overridden. (实现router时,先嵌入这个基类,然后根据需要对这个基类的方法进行重写)

func (*BaseRouter) Handle

func (br *BaseRouter) Handle(req ziface.IRequest)

Handle -

func (*BaseRouter) PostHandle

func (br *BaseRouter) PostHandle(req ziface.IRequest)

PostHandle -

func (*BaseRouter) PreHandle

func (br *BaseRouter) PreHandle(req ziface.IRequest)

PreHandle -

type Client added in v1.1.0

type Client struct {
	// Client Name 客户端的名称
	Name string
	// IP of the target server to connect 目标链接服务器的IP
	Ip string
	// Port of the target server to connect 目标链接服务器的端口
	Port int

	// Error channel
	ErrChan chan error
	// contains filtered or unexported fields
}

func (*Client) AddInterceptor added in v1.1.1

func (c *Client) AddInterceptor(interceptor ziface.IInterceptor)

func (*Client) AddRouter added in v1.1.0

func (c *Client) AddRouter(msgID uint32, router ziface.IRouter)

func (*Client) Conn added in v1.1.0

func (c *Client) Conn() ziface.IConnection

func (*Client) GetErrChan added in v1.1.17

func (c *Client) GetErrChan() chan error

func (*Client) GetLengthField added in v1.1.1

func (c *Client) GetLengthField() *ziface.LengthField

func (*Client) GetMsgHandler added in v1.1.0

func (c *Client) GetMsgHandler() ziface.IMsgHandle

func (*Client) GetName added in v1.1.18

func (c *Client) GetName() string

func (*Client) GetOnConnStart added in v1.1.0

func (c *Client) GetOnConnStart() func(ziface.IConnection)

func (*Client) GetOnConnStop added in v1.1.0

func (c *Client) GetOnConnStop() func(ziface.IConnection)

func (*Client) GetPacket added in v1.1.0

func (c *Client) GetPacket() ziface.IDataPack

func (*Client) Restart added in v1.1.18

func (c *Client) Restart()

Start starts the client, sends requests and establishes a connection. (重新启动客户端,发送请求且建立连接)

func (*Client) SetDecoder added in v1.1.3

func (c *Client) SetDecoder(decoder ziface.IDecoder)

func (*Client) SetName added in v1.1.18

func (c *Client) SetName(name string)

func (*Client) SetOnConnStart added in v1.1.0

func (c *Client) SetOnConnStart(hookFunc func(ziface.IConnection))

func (*Client) SetOnConnStop added in v1.1.0

func (c *Client) SetOnConnStop(hookFunc func(ziface.IConnection))

func (*Client) SetPacket added in v1.1.0

func (c *Client) SetPacket(packet ziface.IDataPack)

func (*Client) Start added in v1.1.0

func (c *Client) Start()

Start starts the client, sends requests and establishes a connection. (启动客户端,发送请求且建立链接)

func (*Client) StartHeartBeat added in v1.1.0

func (c *Client) StartHeartBeat(interval time.Duration)

StartHeartBeat starts heartbeat detection with a fixed time interval. interval: the time interval between each heartbeat message. (启动心跳检测, interval: 每次发送心跳的时间间隔)

func (*Client) StartHeartBeatWithOption added in v1.1.0

func (c *Client) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)

StartHeartBeatWithOption starts heartbeat detection with a custom callback function. interval: the time interval between each heartbeat message. option: a HeartBeatOption struct that contains the custom callback function and message 启动心跳检测(自定义回调)

func (*Client) Stop added in v1.1.0

func (c *Client) Stop()

type ClientOption added in v1.1.0

type ClientOption func(c ziface.IClient)

Options for Client

func WithNameClient added in v1.1.18

func WithNameClient(name string) ClientOption

Set client name

func WithPacketClient added in v1.1.0

func WithPacketClient(pack ziface.IDataPack) ClientOption

Implement custom data packet format by implementing the Packet interface for client, otherwise use the default data packet format

type ConnManager

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

func (*ConnManager) Add

func (connMgr *ConnManager) Add(conn ziface.IConnection)

func (*ConnManager) ClearConn

func (connMgr *ConnManager) ClearConn()

func (*ConnManager) Get

func (connMgr *ConnManager) Get(connID uint64) (ziface.IConnection, error)

func (*ConnManager) Get2 added in v1.2.0

func (connMgr *ConnManager) Get2(strConnId string) (ziface.IConnection, error)

Get2 It is recommended to use this method to obtain connection instances

func (*ConnManager) GetAllConnID added in v1.1.0

func (connMgr *ConnManager) GetAllConnID() []uint64

func (*ConnManager) GetAllConnIdStr added in v1.2.0

func (connMgr *ConnManager) GetAllConnIdStr() []string

func (*ConnManager) Len

func (connMgr *ConnManager) Len() int

func (*ConnManager) Range added in v1.1.12

func (connMgr *ConnManager) Range(cb func(uint64, ziface.IConnection, interface{}) error, args interface{}) (err error)

func (*ConnManager) Range2 added in v1.2.0

func (connMgr *ConnManager) Range2(cb func(string, ziface.IConnection, interface{}) error, args interface{}) (err error)

Range2 It is recommended to use this method to 'Range'

func (*ConnManager) Remove

func (connMgr *ConnManager) Remove(conn ziface.IConnection)

type Connection

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

Connection TCP connection module Used to handle the read and write business of TCP connections, one Connection corresponds to one connection (用于处理Tcp连接的读写业务 一个连接对应一个Connection)

func (*Connection) AddCloseCallback added in v1.2.3

func (s *Connection) AddCloseCallback(handler, key interface{}, f func())

func (*Connection) Context added in v1.0.1

func (c *Connection) Context() context.Context

func (*Connection) GetConnID

func (c *Connection) GetConnID() uint64

func (*Connection) GetConnIdStr added in v1.2.0

func (c *Connection) GetConnIdStr() string

func (*Connection) GetConnection added in v1.1.0

func (c *Connection) GetConnection() net.Conn

func (*Connection) GetMsgHandler added in v1.1.18

func (c *Connection) GetMsgHandler() ziface.IMsgHandle

func (*Connection) GetName added in v1.1.18

func (c *Connection) GetName() string

func (*Connection) GetProperty

func (c *Connection) GetProperty(key string) (interface{}, error)

func (*Connection) GetTCPConnection deprecated

func (c *Connection) GetTCPConnection() net.Conn

Deprecated: use GetConnection instead

func (*Connection) GetWorkerID added in v1.2.0

func (c *Connection) GetWorkerID() uint32

func (*Connection) GetWsConn added in v1.1.15

func (c *Connection) GetWsConn() *websocket.Conn

func (*Connection) InvokeCloseCallbacks added in v1.2.3

func (s *Connection) InvokeCloseCallbacks()

func (*Connection) IsAlive added in v1.1.0

func (c *Connection) IsAlive() bool

func (*Connection) LocalAddr added in v1.1.0

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

func (*Connection) LocalAddrString added in v1.1.18

func (c *Connection) LocalAddrString() string

func (*Connection) RemoteAddr

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

func (*Connection) RemoteAddrString added in v1.1.18

func (c *Connection) RemoteAddrString() string

func (*Connection) RemoveCloseCallback added in v1.2.3

func (s *Connection) RemoveCloseCallback(handler, key interface{})

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

func (*Connection) Send added in v1.1.1

func (c *Connection) Send(data []byte) error

func (*Connection) SendBuffMsg

func (c *Connection) SendBuffMsg(msgID uint32, data []byte) error

func (*Connection) SendMsg

func (c *Connection) SendMsg(msgID uint32, data []byte) error

SendMsg directly sends Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)

func (*Connection) SendToQueue added in v1.1.1

func (c *Connection) SendToQueue(data []byte) error

func (*Connection) SetHeartBeat added in v1.1.14

func (c *Connection) SetHeartBeat(checker ziface.IHeartbeatChecker)

func (*Connection) SetProperty

func (c *Connection) SetProperty(key string, value interface{})

func (*Connection) Start

func (c *Connection) Start()

Start starts the connection and makes the current connection work. (启动连接,让当前连接开始工作)

func (*Connection) StartReader

func (c *Connection) StartReader()

StartReader is a goroutine that reads data from the client (读消息Goroutine,用于从客户端中读取数据)

func (*Connection) StartWriter

func (c *Connection) StartWriter()

StartWriter is the goroutine that writes messages to the client (写消息Goroutine, 用户将数据发送给客户端)

func (*Connection) Stop

func (c *Connection) Stop()

Stop stops the connection and ends the current connection state. (停止连接,结束当前连接状态)

type GroupRouter added in v1.1.18

type GroupRouter struct {
	Handlers []ziface.RouterHandler
	// contains filtered or unexported fields
}

func NewGroup added in v1.1.18

func NewGroup(start, end uint32, router *RouterSlices, Handlers ...ziface.RouterHandler) *GroupRouter

func (*GroupRouter) AddHandler added in v1.1.18

func (g *GroupRouter) AddHandler(MsgId uint32, Handlers ...ziface.RouterHandler)

func (*GroupRouter) Use added in v1.1.18

func (g *GroupRouter) Use(Handlers ...ziface.RouterHandler)

type HeartbeatChecker added in v1.1.0

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

func (*HeartbeatChecker) BindConn added in v1.1.12

func (h *HeartbeatChecker) BindConn(conn ziface.IConnection)

func (*HeartbeatChecker) BindRouter added in v1.1.0

func (h *HeartbeatChecker) BindRouter(msgID uint32, router ziface.IRouter)

func (*HeartbeatChecker) BindRouterSlices added in v1.1.18

func (h *HeartbeatChecker) BindRouterSlices(msgID uint32, handlers ...ziface.RouterHandler)

func (*HeartbeatChecker) Clone added in v1.1.12

Clone clones to a specified connection (克隆到一个指定的链接上)

func (*HeartbeatChecker) MsgID added in v1.1.12

func (h *HeartbeatChecker) MsgID() uint32

func (*HeartbeatChecker) Router added in v1.1.12

func (h *HeartbeatChecker) Router() ziface.IRouter

func (*HeartbeatChecker) RouterSlices added in v1.1.18

func (h *HeartbeatChecker) RouterSlices() []ziface.RouterHandler

func (*HeartbeatChecker) SendHeartBeatMsg added in v1.1.12

func (h *HeartbeatChecker) SendHeartBeatMsg() error

func (*HeartbeatChecker) SetHeartbeatFunc added in v1.1.15

func (h *HeartbeatChecker) SetHeartbeatFunc(beatFunc ziface.HeartBeatFunc)

func (*HeartbeatChecker) SetHeartbeatMsgFunc added in v1.1.0

func (h *HeartbeatChecker) SetHeartbeatMsgFunc(f ziface.HeartBeatMsgFunc)

func (*HeartbeatChecker) SetOnRemoteNotAlive added in v1.1.0

func (h *HeartbeatChecker) SetOnRemoteNotAlive(f ziface.OnRemoteNotAlive)

func (*HeartbeatChecker) Start added in v1.1.0

func (h *HeartbeatChecker) Start()

func (*HeartbeatChecker) Stop added in v1.1.0

func (h *HeartbeatChecker) Stop()

type HeatBeatDefaultRouter added in v1.1.0

type HeatBeatDefaultRouter struct {
	BaseRouter
}

Default callback routing business for receiving remote heartbeat messages (收到remote心跳消息的默认回调路由业务)

func (*HeatBeatDefaultRouter) Handle added in v1.1.0

func (r *HeatBeatDefaultRouter) Handle(req ziface.IRequest)

type KcpConfig added in v1.2.3

type KcpConfig struct {
	// changes ack flush option, set true to flush ack immediately,
	// (改变ack刷新选项,设置为true立即刷新ack)
	KcpACKNoDelay bool
	// toggles the stream mode on/off
	// (切换流模式开/关)
	KcpStreamMode bool
	// Whether nodelay mode is enabled, 0 is not enabled; 1 enabled.
	// (是否启用nodelay模式,0不启用;1启用)
	KcpNoDelay int
	// Protocol internal work interval, in milliseconds, such as 10 ms or 20 ms.
	// (协议内部工作的间隔,单位毫秒,比如10ms或者20ms)
	KcpInterval int
	// Fast retransmission mode, 0 represents off by default, 2 can be set (2 ACK spans will result in direct retransmission)
	// (快速重传模式,默认为0关闭,可以设置2(2次ACK跨越将会直接重传)
	KcpResend int
	// Whether to turn off flow control, 0 represents “Do not turn off” by default, 1 represents “Turn off”.
	// (是否关闭流控,默认是0代表不关闭,1代表关闭)
	KcpNc int
	// SND_BUF, this unit is the packet, default 32.
	// (SND_BUF发送缓冲区大小,单位是包,默认是32)
	KcpSendWindow int
	// RCV_BUF, this unit is the packet, default 32.
	// (RCV_BUF接收缓冲区大小,单位是包,默认是32)
	KcpRecvWindow int
}

type KcpConnection added in v1.2.0

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

Connection KCP connection module Used to handle the read and write business of KCP connections, one Connection corresponds to one connection (用于处理KCP连接的读写业务 一个连接对应一个Connection)

func (*KcpConnection) AddCloseCallback added in v1.2.3

func (s *KcpConnection) AddCloseCallback(handler, key interface{}, f func())

func (*KcpConnection) Context added in v1.2.0

func (c *KcpConnection) Context() context.Context

func (*KcpConnection) GetConnID added in v1.2.0

func (c *KcpConnection) GetConnID() uint64

func (*KcpConnection) GetConnIdStr added in v1.2.0

func (c *KcpConnection) GetConnIdStr() string

func (*KcpConnection) GetConnection added in v1.2.0

func (c *KcpConnection) GetConnection() net.Conn

func (*KcpConnection) GetMsgHandler added in v1.2.0

func (c *KcpConnection) GetMsgHandler() ziface.IMsgHandle

func (*KcpConnection) GetName added in v1.2.0

func (c *KcpConnection) GetName() string

func (*KcpConnection) GetProperty added in v1.2.0

func (c *KcpConnection) GetProperty(key string) (interface{}, error)

func (*KcpConnection) GetTCPConnection deprecated added in v1.2.0

func (c *KcpConnection) GetTCPConnection() net.Conn

Deprecated: use GetConnection instead

func (*KcpConnection) GetWorkerID added in v1.2.0

func (c *KcpConnection) GetWorkerID() uint32

func (*KcpConnection) GetWsConn added in v1.2.0

func (c *KcpConnection) GetWsConn() *websocket.Conn

func (*KcpConnection) InvokeCloseCallbacks added in v1.2.3

func (s *KcpConnection) InvokeCloseCallbacks()

invokeCloseCallbacks 触发 close callback, 在独立协程完成

func (*KcpConnection) IsAlive added in v1.2.0

func (c *KcpConnection) IsAlive() bool

func (*KcpConnection) LocalAddr added in v1.2.0

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

func (*KcpConnection) LocalAddrString added in v1.2.0

func (c *KcpConnection) LocalAddrString() string

func (*KcpConnection) RemoteAddr added in v1.2.0

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

func (*KcpConnection) RemoteAddrString added in v1.2.0

func (c *KcpConnection) RemoteAddrString() string

func (*KcpConnection) RemoveCloseCallback added in v1.2.3

func (s *KcpConnection) RemoveCloseCallback(handler, key interface{})

func (*KcpConnection) RemoveProperty added in v1.2.0

func (c *KcpConnection) RemoveProperty(key string)

func (*KcpConnection) Send added in v1.2.0

func (c *KcpConnection) Send(data []byte) error

func (*KcpConnection) SendBuffMsg added in v1.2.0

func (c *KcpConnection) SendBuffMsg(msgID uint32, data []byte) error

func (*KcpConnection) SendMsg added in v1.2.0

func (c *KcpConnection) SendMsg(msgID uint32, data []byte) error

SendMsg directly sends Message data to the remote KCP client. (直接将Message数据发送数据给远程的KCP客户端)

func (*KcpConnection) SendToQueue added in v1.2.0

func (c *KcpConnection) SendToQueue(data []byte) error

func (*KcpConnection) SetHeartBeat added in v1.2.0

func (c *KcpConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)

func (*KcpConnection) SetProperty added in v1.2.0

func (c *KcpConnection) SetProperty(key string, value interface{})

func (*KcpConnection) Start added in v1.2.0

func (c *KcpConnection) Start()

Start starts the connection and makes the current connection work. (启动连接,让当前连接开始工作)

func (*KcpConnection) StartReader added in v1.2.0

func (c *KcpConnection) StartReader()

StartReader is a goroutine that reads data from the client (读消息Goroutine,用于从客户端中读取数据)

func (*KcpConnection) StartWriter added in v1.2.0

func (c *KcpConnection) StartWriter()

StartWriter is the goroutine that writes messages to the client (写消息Goroutine, 用户将数据发送给客户端)

func (*KcpConnection) Stop added in v1.2.0

func (c *KcpConnection) Stop()

Stop stops the connection and ends the current connection state. (停止连接,结束当前连接状态)

type MsgHandle

type MsgHandle struct {
	// A map property that stores the processing methods for each MsgID
	// (存放每个MsgID 所对应的处理方法的map属性)
	Apis map[uint32]ziface.IRouter

	// The number of worker goroutines in the business work Worker pool
	// (业务工作Worker池的数量)
	WorkerPoolSize uint32

	// A message queue for workers to take tasks
	// (Worker负责取任务的消息队列)
	TaskQueue []chan ziface.IRequest

	RouterSlices *RouterSlices
	// contains filtered or unexported fields
}

MsgHandle is the module for handling message processing callbacks (对消息的处理回调模块)

func (*MsgHandle) AddInterceptor added in v1.1.1

func (mh *MsgHandle) AddInterceptor(interceptor ziface.IInterceptor)

func (*MsgHandle) AddRouter

func (mh *MsgHandle) AddRouter(msgID uint32, router ziface.IRouter)

AddRouter adds specific processing logic for messages (为消息添加具体的处理逻辑)

func (*MsgHandle) AddRouterSlices added in v1.1.18

func (mh *MsgHandle) AddRouterSlices(msgId uint32, handler ...ziface.RouterHandler) ziface.IRouterSlices

AddRouterSlices adds router handlers using slices (切片路由添加)

func (*MsgHandle) Execute added in v1.1.15

func (mh *MsgHandle) Execute(request ziface.IRequest)

func (*MsgHandle) Group added in v1.1.18

func (mh *MsgHandle) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices

Group routes into a group (路由分组)

func (*MsgHandle) Intercept added in v1.1.1

func (mh *MsgHandle) Intercept(chain ziface.IChain) ziface.IcResp

Data processing interceptor that is necessary by default in Zinx (Zinx默认必经的数据处理拦截器)

func (*MsgHandle) SendMsgToTaskQueue

func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest)

SendMsgToTaskQueue sends the message to the TaskQueue for processing by the worker (将消息交给TaskQueue,由worker进行处理)

func (*MsgHandle) StartOneWorker

func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest)

StartOneWorker starts a worker workflow (启动一个Worker工作流程)

func (*MsgHandle) StartWorkerPool

func (mh *MsgHandle) StartWorkerPool()

StartWorkerPool starts the worker pool

func (*MsgHandle) Use added in v1.1.18

func (mh *MsgHandle) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices

type Option added in v1.0.1

type Option func(s *Server)

Options for Server (Server的服务Option)

func WithPacket added in v1.0.1

func WithPacket(pack ziface.IDataPack) Option

Implement custom data packet format by implementing the Packet interface, otherwise use the default data packet format (只要实现Packet 接口可自由实现数据包解析格式,如果没有则使用默认解析格式)

type Request

type Request struct {
	ziface.BaseRequest
	// contains filtered or unexported fields
}

Request 请求

func (*Request) Abort added in v1.0.2

func (r *Request) Abort()

func (*Request) BindRouter added in v1.0.2

func (r *Request) BindRouter(router ziface.IRouter)

func (*Request) BindRouterSlices added in v1.1.18

func (r *Request) BindRouterSlices(handlers []ziface.RouterHandler)

BindRouterSlices New version

func (*Request) Call added in v1.0.2

func (r *Request) Call()

func (*Request) Copy added in v1.2.3

func (r *Request) Copy() ziface.IRequest

Copy 在执行路由函数的时候可能会出现需要再起一个协程的需求,但是 Request 对象由对象池管理后无法保证新协程中的 Request 参数一致 通过 Copy 方法复制一份 Request 对象保持创建协程时候的参数一致。但新开的协程不应该在对原始的执行过程有影响,所以不包含连接和路由对象。 但如果一定对连接信息有所需要可以在 Copy 后手动 set 一份参数在 Request 对象中

func (*Request) Get added in v1.2.3

func (r *Request) Get(key string) (value interface{}, exists bool)

Get 在 Request 中取出一个上下文信息

func (*Request) GetConnection

func (r *Request) GetConnection() ziface.IConnection

func (*Request) GetData

func (r *Request) GetData() []byte

func (*Request) GetMessage added in v1.1.1

func (r *Request) GetMessage() ziface.IMessage

func (*Request) GetMsgID

func (r *Request) GetMsgID() uint32

func (*Request) GetResponse added in v1.1.1

func (r *Request) GetResponse() ziface.IcResp

func (*Request) Goto added in v1.0.2

func (r *Request) Goto(step ziface.HandleStep)

func (*Request) Reset added in v1.2.3

func (r *Request) Reset(conn ziface.IConnection, msg ziface.IMessage)

func (*Request) RouterSlicesNext added in v1.1.18

func (r *Request) RouterSlicesNext()

func (*Request) Set added in v1.2.3

func (r *Request) Set(key string, value interface{})

Set 在 Request 中存放一个上下文,如果 keys 为空会实例化一个

func (*Request) SetResponse added in v1.1.1

func (r *Request) SetResponse(response ziface.IcResp)

type RequestFunc added in v1.1.18

type RequestFunc struct {
	ziface.BaseRequest
	// contains filtered or unexported fields
}

func (*RequestFunc) CallFunc added in v1.1.18

func (rf *RequestFunc) CallFunc()

func (*RequestFunc) GetConnection added in v1.1.18

func (rf *RequestFunc) GetConnection() ziface.IConnection

type RouterSlices added in v1.1.18

type RouterSlices struct {
	Apis     map[uint32][]ziface.RouterHandler
	Handlers []ziface.RouterHandler
	sync.RWMutex
}

func NewRouterSlices added in v1.1.18

func NewRouterSlices() *RouterSlices

func (*RouterSlices) AddHandler added in v1.1.18

func (r *RouterSlices) AddHandler(msgId uint32, Handlers ...ziface.RouterHandler)

func (*RouterSlices) GetHandlers added in v1.1.18

func (r *RouterSlices) GetHandlers(MsgId uint32) ([]ziface.RouterHandler, bool)

func (*RouterSlices) Group added in v1.1.18

func (r *RouterSlices) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices

func (*RouterSlices) Use added in v1.1.18

func (r *RouterSlices) Use(handles ...ziface.RouterHandler)

type Server

type Server struct {
	// Name of the server (服务器的名称)
	Name string
	//tcp4 or other
	IPVersion string
	// IP version (e.g. "tcp4") - 服务绑定的IP地址
	IP string
	// IP address the server is bound to (服务绑定的端口)
	Port int
	// 服务绑定的websocket 端口 (Websocket port the server is bound to)
	WsPort int
	// 服务绑定的kcp 端口 (kcp port the server is bound to)
	KcpPort int

	// Routing mode (路由模式)
	RouterSlicesMode bool
	// Request 对象池模式
	RequestPoolMode bool
	// Current server's connection manager (当前Server的链接管理器)
	ConnMgr ziface.IConnManager
	// contains filtered or unexported fields
}

Server interface implementation, defines a Server service class (接口实现,定义一个Server服务类)

func (*Server) AddInterceptor added in v1.1.1

func (s *Server) AddInterceptor(interceptor ziface.IInterceptor)

func (*Server) AddRouter

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

func (*Server) AddRouterSlices added in v1.1.18

func (s *Server) AddRouterSlices(msgID uint32, router ...ziface.RouterHandler) ziface.IRouterSlices

func (*Server) GetConnMgr

func (s *Server) GetConnMgr() ziface.IConnManager

func (*Server) GetHeartBeat added in v1.1.12

func (s *Server) GetHeartBeat() ziface.IHeartbeatChecker

func (*Server) GetLengthField added in v1.1.1

func (s *Server) GetLengthField() *ziface.LengthField

func (*Server) GetMsgHandler added in v1.1.0

func (s *Server) GetMsgHandler() ziface.IMsgHandle

func (*Server) GetOnConnStart added in v1.1.0

func (s *Server) GetOnConnStart() func(ziface.IConnection)

func (*Server) GetOnConnStop added in v1.1.0

func (s *Server) GetOnConnStop() func(ziface.IConnection)

func (*Server) GetPacket added in v1.1.0

func (s *Server) GetPacket() ziface.IDataPack

func (*Server) Group added in v1.1.18

func (s *Server) Group(start, end uint32, Handlers ...ziface.RouterHandler) ziface.IGroupRouterSlices

func (*Server) ListenKcpConn added in v1.2.0

func (s *Server) ListenKcpConn()

func (*Server) ListenTcpConn added in v1.1.17

func (s *Server) ListenTcpConn()

func (*Server) ListenWebsocketConn added in v1.1.17

func (s *Server) ListenWebsocketConn()

func (*Server) Serve

func (s *Server) Serve()

Serve runs the server (运行服务)

func (*Server) ServerName added in v1.1.18

func (s *Server) ServerName() string

func (*Server) SetDecoder added in v1.1.3

func (s *Server) SetDecoder(decoder ziface.IDecoder)

func (*Server) SetOnConnStart

func (s *Server) SetOnConnStart(hookFunc func(ziface.IConnection))

func (*Server) SetOnConnStop

func (s *Server) SetOnConnStop(hookFunc func(ziface.IConnection))

func (*Server) SetPacket added in v1.1.0

func (s *Server) SetPacket(packet ziface.IDataPack)

func (*Server) SetWebsocketAuth added in v1.1.17

func (s *Server) SetWebsocketAuth(f func(r *http.Request) error)

func (*Server) Start

func (s *Server) Start()

Start the network service (开启网络服务)

func (*Server) StartConn added in v1.1.17

func (s *Server) StartConn(conn ziface.IConnection)

func (*Server) StartHeartBeat added in v1.1.0

func (s *Server) StartHeartBeat(interval time.Duration)

StartHeartBeat starts the heartbeat check. interval is the time interval between each heartbeat. (启动心跳检测 interval 每次发送心跳的时间间隔)

func (*Server) StartHeartBeatWithOption added in v1.1.0

func (s *Server) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption)

StartHeartBeatWithOption starts the heartbeat detection with the given configuration. interval is the time interval for sending heartbeat messages. option is the configuration for heartbeat detection. 启动心跳检测 (option 心跳检测的配置)

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server (停止服务)

func (*Server) Use added in v1.1.18

func (s *Server) Use(Handlers ...ziface.RouterHandler) ziface.IRouterSlices

type WsConnection added in v1.1.15

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

WsConnection is a module for handling the read and write operations of a WebSocket connection. (Websocket连接模块, 用于处理 Websocket 连接的读写业务 一个连接对应一个Connection)

func (*WsConnection) AddCloseCallback added in v1.2.3

func (s *WsConnection) AddCloseCallback(handler, key interface{}, f func())

func (*WsConnection) Context added in v1.1.15

func (c *WsConnection) Context() context.Context

Context returns the context for the connection, which can be used by user-defined goroutines to get the connection exit status. (返回ctx,用于用户自定义的go程获取连接退出状态)

func (*WsConnection) GetConnID added in v1.1.15

func (c *WsConnection) GetConnID() uint64

func (*WsConnection) GetConnIdStr added in v1.2.0

func (c *WsConnection) GetConnIdStr() string

func (*WsConnection) GetConnection added in v1.1.15

func (c *WsConnection) GetConnection() net.Conn

func (*WsConnection) GetMsgHandler added in v1.1.18

func (c *WsConnection) GetMsgHandler() ziface.IMsgHandle

func (*WsConnection) GetName added in v1.1.18

func (c *WsConnection) GetName() string

func (*WsConnection) GetProperty added in v1.1.15

func (c *WsConnection) GetProperty(key string) (interface{}, error)

func (*WsConnection) GetTCPConnection deprecated added in v1.1.15

func (c *WsConnection) GetTCPConnection() net.Conn

Deprecated: use GetConnection instead

func (*WsConnection) GetWorkerID added in v1.2.0

func (c *WsConnection) GetWorkerID() uint32

func (*WsConnection) GetWsConn added in v1.1.15

func (c *WsConnection) GetWsConn() *websocket.Conn

func (*WsConnection) InvokeCloseCallbacks added in v1.2.3

func (s *WsConnection) InvokeCloseCallbacks()

func (*WsConnection) IsAlive added in v1.1.15

func (c *WsConnection) IsAlive() bool

func (*WsConnection) LocalAddr added in v1.1.15

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

func (*WsConnection) LocalAddrString added in v1.1.18

func (c *WsConnection) LocalAddrString() string

func (*WsConnection) RemoteAddr added in v1.1.15

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

func (*WsConnection) RemoteAddrString added in v1.1.18

func (c *WsConnection) RemoteAddrString() string

func (*WsConnection) RemoveCloseCallback added in v1.2.3

func (s *WsConnection) RemoveCloseCallback(handler, key interface{})

func (*WsConnection) RemoveProperty added in v1.1.15

func (c *WsConnection) RemoveProperty(key string)

func (*WsConnection) Send added in v1.1.15

func (c *WsConnection) Send(data []byte) error

func (*WsConnection) SendBuffMsg added in v1.1.15

func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte) error

SendBuffMsg sends BuffMsg

func (*WsConnection) SendMsg added in v1.1.15

func (c *WsConnection) SendMsg(msgID uint32, data []byte) error

SendMsg directly sends the Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)

func (*WsConnection) SendToQueue added in v1.1.15

func (c *WsConnection) SendToQueue(data []byte) error

func (*WsConnection) SetHeartBeat added in v1.1.15

func (c *WsConnection) SetHeartBeat(checker ziface.IHeartbeatChecker)

func (*WsConnection) SetProperty added in v1.1.15

func (c *WsConnection) SetProperty(key string, value interface{})

func (*WsConnection) Start added in v1.1.15

func (c *WsConnection) Start()

Start starts the connection and makes it work. (Start 启动连接,让当前连接开始工作)

func (*WsConnection) StartReader added in v1.1.15

func (c *WsConnection) StartReader()

StartReader is a Goroutine that reads messages from the client. (StartReader 读消息Goroutine,用于从客户端中读取数据)

func (*WsConnection) StartWriter added in v1.1.15

func (c *WsConnection) StartWriter()

StartWriter is a Goroutine that sends messages to the client (StartWriter 写消息Goroutine, 用户将数据发送给客户端)

func (*WsConnection) Stop added in v1.1.15

func (c *WsConnection) Stop()

Stop stops the connection and ends its current state. (停止连接,结束当前连接状态)

Jump to

Keyboard shortcuts

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