server

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sid          = "sid"    // 会话标识
	SrvName      = "server" // 会话标识
	CliName      = "auth"   // 会话标识
	RemoteAddr   = "remote" // 发起方地址
	LogKeyErr    = "error"  // 错误信息
	LogKeyPacket = "packet" // 数据包

	LogKeyPoolFree = "g_session_pool_free" // 【全局】当前会话池剩余量
	LogKeyPoolCap  = "g_session_pool_cap"  // 【全局】会话池最大容量

	LogKeyClientConnsCap  = "c_conns_cap" // 【会话级】该连接对应的客户端能建立的最大连接数(待采用redis或数据库存储实时会话数,以实现整个集群的连接数可控)
	LogKeySessionSwCur    = "s_sw_cur"    // 【会话级】接收消息滑动窗口当前大小
	LogKeySessionSwCap    = "s_sw_cap"    // 【会话级】接收消息滑动窗口最大值
	LogKeySessionPoolFree = "s_pool_free" // 【会话级】goroutine goPool 当前使用数
	LogKeySessionPoolCap  = "s_pool_cap"  // 【会话级】goroutine goPool 最大容量
	LogKeyCounterMt       = "s_mt_num"    // 【会话级】下行短信计数
	LogKeyCounterDlv      = "s_dlv_num"   // 【会话级】上行短信计数
	LogKeyCounterRpt      = "s_rpt_num"   // 【会话级】状态报告计数
)
View Source
const (
	CMPP = "cmpp"
	SMGP = "smgp"
	SGIP = "sgip"
)
View Source
const (
	StatConnect stat = iota
	StatLogin
	StatClosing
)

Variables

This section is empty.

Functions

func DecodeAndCheckHeader added in v0.2.0

func DecodeAndCheckHeader(s *Server, c gnet.Conn) (cmd uint32, seq uint32, buff []byte, action gnet.Action, pass bool)

func ErrorField

func ErrorField(err error) log.Field

func ExecuteChain

func ExecuteChain(handlers []TrafficHandler, cmd, seq uint32, buff []byte, c gnet.Conn, s *Server) (action gnet.Action)

ExecuteChain all cmppHandlers

func FlatMapLog

func FlatMapLog(fields ...[]log.Field) []log.Field

func NewSession

func NewSession(c gnet.Conn) *session

func Packet2HexLogStr

func Packet2HexLogStr(pack []byte) log.Field

func SErrField

func SErrField(err string) log.Field

func Session

func Session(c gnet.Conn) *session

func Start

func Start(s *Server)

Types

type Direction

type Direction string
var RC Direction = "<<<" // 交易请求方向 接收 Remote > Local
var SD Direction = ">>>" // 交易请求方向 发送 Local  > Remote

type Operation

type Operation byte

Operation 操作类型定义

const (
	OpFlowControl Operation = iota // 操作类型枚举
	OpConnectionClose
	OpDropMessage
)

func (Operation) Field

func (op Operation) Field() log.Field

func (Operation) String

func (op Operation) String() string

type Server

type Server struct {
	sync.Mutex
	gnet.BuiltinEventEngine
	// contains filtered or unexported fields
}

Server 封装 gnet server

func New

func New(name string) *Server

func (*Server) ActiveSessions

func (s *Server) ActiveSessions() int

func (*Server) Address

func (s *Server) Address() string

func (*Server) CountSessionByClientId

func (s *Server) CountSessionByClientId(clientId string) (counter int)

func (*Server) CreateSession

func (s *Server) CreateSession(c gnet.Conn) *session

func (*Server) Engine

func (s *Server) Engine() gnet.Engine

func (*Server) GoPool

func (s *Server) GoPool() *goroutine.Pool

func (*Server) LogCounter

func (s *Server) LogCounter() []log.Field

func (*Server) LogCounterWithName

func (s *Server) LogCounterWithName() []log.Field

func (*Server) Name

func (s *Server) Name() string

func (*Server) OnBoot

func (s *Server) OnBoot(eng gnet.Engine) (action gnet.Action)

func (*Server) OnClose

func (s *Server) OnClose(c gnet.Conn, e error) (action gnet.Action)

func (*Server) OnOpen

func (s *Server) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*Server) OnShutdown

func (s *Server) OnShutdown(eng gnet.Engine)

func (*Server) OnTick

func (s *Server) OnTick() (delay time.Duration, action gnet.Action)

func (*Server) OnTraffic

func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action)

func (*Server) Port

func (s *Server) Port() int

func (*Server) Protocol

func (s *Server) Protocol() string

func (*Server) SessionPool

func (s *Server) SessionPool() *sync.Map

func (*Server) SessionPoolCap

func (s *Server) SessionPoolCap() int

type TrafficHandler

type TrafficHandler func(cmd, seq uint32, buff []byte, c gnet.Conn, s *Server) (next bool, action gnet.Action)

TrafficHandler Don't Read From gnet.Conn. cmd: command id ; seq: request sequence ; buff: packet body ; next: true continue next handler, false return the action

func CmppHandlers added in v0.2.0

func CmppHandlers() []TrafficHandler

func SgipHandlers added in v0.2.0

func SgipHandlers() []TrafficHandler

func SmgpHandlers added in v0.2.0

func SmgpHandlers() []TrafficHandler

Jump to

Keyboard shortcuts

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