gate

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionOnNotify    = errors.New("current session working on notify mode")
	ErrCloseClosedSession = errors.New("close closed session")
	ErrInvalidRegisterReq = errors.New("invalid register request")
	ErrBrokenPipe         = errors.New("broken low-level pipe")
	ErrBufferExceed       = errors.New("session send buffer exceed")
	ErrCloseClosedGroup   = errors.New("close closed group")
	ErrClosedGroup        = errors.New("group closed")
	ErrMemberNotFound     = errors.New("member not found in the group")
	ErrSessionDuplication = errors.New("session has existed in the current group")
	ErrSprotoRequestType  = errors.New("sproto request type")
	ErrSprotoResponseType = errors.New("sproto response type")
	ErrHandShake          = errors.New("handshake failed")
	ErrHeartbeatTimeout   = errors.New("heartbeat timeout")
	ErrDialTimeout        = errors.New("dial timeout")
	ErrDialInterrupt      = errors.New("dial interrupt")
	ErrInvalidAddress     = errors.New("invalid address")
	ErrInvalidMessage     = errors.New("invalid message")
	ErrInvalidHandler     = errors.New("invalid handler")
	ErrInvalidPacket      = errors.New("invalid packet")
	ErrNotHandshake       = errors.New("没握手成功就发了数据包过来")
	ErrNotWorking         = errors.New("非正常状态,无法发送消息")
	ErrInvalidState       = errors.New("invalid state")
	ErrKick               = errors.New("被踢下线")
	ErrConnClosed         = errors.New("连接已关闭")
	ErrConnNotReady       = errors.New("连接末准备好")
	ErrHandShakeAck       = errors.New("handshake ack 出错")
)
View Source
var (
	ErrIllegalUID = errors.New("illegal uid")
)

Functions

This section is empty.

Types

type Conn

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

func (*Conn) Close

func (self *Conn) Close() error

func (*Conn) Kick

func (self *Conn) Kick(reason string) error

func (*Conn) Push

func (self *Conn) Push(route string, data []byte) error

如果链接已关闭, 则返回ErrBrokenPipe

func (*Conn) Recv

func (self *Conn) Recv(ctx context.Context) (msg *Message, err error)

返回接收到的消息 即使链接已经关闭,也会返回已经接收到的消息,直到没有可处理的消息为止,则返回ErrBrokenPipe Returns: msg - 返回接收到的消息 err - 如果连接已关闭, 且没有消息了, 则返回ErrBrokenPipe

func (*Conn) RemoteAddr

func (self *Conn) RemoteAddr() net.Addr

func (*Conn) Response

func (self *Conn) Response(mid uint64, data []byte) error

如果链接已关闭,则返回ErrBrokenPipe

func (*Conn) SendServerDownPacket

func (self *Conn) SendServerDownPacket(reason string) error

func (*Conn) SendServerMaintainPacket

func (self *Conn) SendServerMaintainPacket(reason string) error

func (*Conn) SendServerResumePacket

func (self *Conn) SendServerResumePacket(reason string) error

func (*Conn) SendServerSuspendPacket

func (self *Conn) SendServerSuspendPacket(reason string) error

func (*Conn) String

func (self *Conn) String() string

type Message

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

func (*Message) Payload

func (r *Message) Payload() []byte

func (*Message) Push

func (r *Message) Push(route string, data []byte) error

func (*Message) ReqId

func (r *Message) ReqId() uint64

func (*Message) Response

func (r *Message) Response(data []byte) error

func (*Message) Session

func (r *Message) Session() gira.GatewayConn

type MiddleWareInterface

type MiddleWareInterface interface {
	ServeMessage(r *Message)
	OnSessionOpen(s *Session)
	OnSessionClose(s *Session)
}

type Option

type Option func(gateway *Server)

func WithCheckOriginFunc

func WithCheckOriginFunc(fn func(*http.Request) bool) Option

func WithDebugMode

func WithDebugMode(v bool) Option

func WithDictionary

func WithDictionary(dict map[string]uint16) Option

func WithHandshakeTimeout

func WithHandshakeTimeout(d time.Duration) Option

func WithHandshakeValidator

func WithHandshakeValidator(fn func([]byte) error) Option

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) Option

func WithIsWebsocket

func WithIsWebsocket(enableWs bool) Option

func WithRSAPrivateKey

func WithRSAPrivateKey(keyFile string) Option

func WithRecvBacklog

func WithRecvBacklog(v int) Option

func WithRecvBuffSize

func WithRecvBuffSize(v int) Option

func WithSendBacklog

func WithSendBacklog(v int) Option

func WithSessionModifer

func WithSessionModifer(v uint64) Option

func WithTSLConfig

func WithTSLConfig(certificate, key string) Option

func WithWSPath

func WithWSPath(path string) Option

type Server

type Server struct {
	BindAddr string
	Host     string
	Port     int32

	Stat Stat
	// contains filtered or unexported fields
}

func Listen

func Listen(ctx context.Context, addr string, opts ...Option) (*Server, error)

func NewConfigServer

func NewConfigServer(ctx context.Context, config gira.GatewayConfig) (*Server, error)

func (*Server) Kick

func (server *Server) Kick(reason string)

func (*Server) Maintain

func (server *Server) Maintain(m bool)

设置成维持状态,不接受新的连接

func (*Server) Serve

func (server *Server) Serve(handler gira.GatewayHandler) error

func (*Server) Shutdown

func (server *Server) Shutdown()

func (*Server) UseMiddleware

func (server *Server) UseMiddleware(m MiddleWareInterface)

type Session

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

func (*Session) Bind

func (s *Session) Bind(uid int64) error

func (*Session) Clear

func (s *Session) Clear()

func (*Session) Close

func (s *Session) Close() error

func (*Session) Float32

func (s *Session) Float32(key string) float32

func (*Session) Float64

func (s *Session) Float64(key string) float64

func (*Session) HasKey

func (s *Session) HasKey(key string) bool

func (*Session) Id

func (s *Session) Id() uint64

func (*Session) Int

func (s *Session) Int(key string) int

func (*Session) Int16

func (s *Session) Int16(key string) int16

func (*Session) Int32

func (s *Session) Int32(key string) int32

func (*Session) Int64

func (s *Session) Int64(key string) int64

func (*Session) Int8

func (s *Session) Int8(key string) int8

func (*Session) Kick

func (s *Session) Kick(reason string)

func (*Session) Push

func (s *Session) Push(route string, data []byte) error

func (*Session) Recv

func (s *Session) Recv(ctx context.Context) (gira.GatewayMessage, error)

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

func (*Session) Remove

func (s *Session) Remove(key string)

func (*Session) Response

func (s *Session) Response(mid uint64, data []byte) error

func (*Session) Restore

func (s *Session) Restore(data map[string]interface{})

func (*Session) SendServerDown

func (s *Session) SendServerDown(reason string)

func (*Session) SendServerMaintain

func (s *Session) SendServerMaintain(reason string)

func (*Session) SendServerResume

func (s *Session) SendServerResume(reason string)

func (*Session) SendServerSuspend

func (s *Session) SendServerSuspend(reason string)

func (*Session) Set

func (s *Session) Set(key string, value interface{})

func (*Session) SetUserData

func (s *Session) SetUserData(value interface{})

func (*Session) State

func (s *Session) State() map[string]interface{}

func (*Session) String

func (s *Session) String(key string) string

func (*Session) UID

func (s *Session) UID() int64

func (*Session) Uint

func (s *Session) Uint(key string) uint

func (*Session) Uint16

func (s *Session) Uint16(key string) uint16

func (*Session) Uint32

func (s *Session) Uint32(key string) uint32

func (*Session) Uint64

func (s *Session) Uint64(key string) uint64

func (*Session) Uint8

func (s *Session) Uint8(key string) uint8

func (*Session) UserData

func (s *Session) UserData() interface{}

func (*Session) Value

func (s *Session) Value(key string) interface{}

type Stat

type Stat struct {
	ActiveSessionCount        int64 // 当前会话数量
	CumulativeSessionCount    int64 // 累计会话数量
	CumulativeConnectionCount int64 // 累计连接数量
	ActiveConnectionCount     int64 // 当前连接数量
	HandshakeErrorCount       int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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