common

package
v0.0.0-...-730ab85 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tcp = iota
	Websocket
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRouter

type BaseRouter struct{}

func (*BaseRouter) Handle

func (br *BaseRouter) Handle(req *Request)

func (*BaseRouter) PostHandle

func (br *BaseRouter) PostHandle(req *Request)

func (*BaseRouter) PreHandle

func (br *BaseRouter) PreHandle(req *Request)

type ConnManager

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

func NewConnManager

func NewConnManager() *ConnManager

func (*ConnManager) Add

func (connMgr *ConnManager) Add(conn *Connection)

func (*ConnManager) ClearConn

func (connMgr *ConnManager) ClearConn()

func (*ConnManager) Get

func (connMgr *ConnManager) Get(connID uint32) (*Connection, error)

func (*ConnManager) Len

func (connMgr *ConnManager) Len() int

func (*ConnManager) Remove

func (connMgr *ConnManager) Remove(conn *Connection)

func (*ConnManager) ShowConn

func (connMgr *ConnManager) ShowConn()

type Connection

type Connection struct {
	Conn          net.Conn
	TcpConn       *net.TCPConn
	WebsocketConn *websocket.Conn

	ConnID uint32

	ExitBuffChan chan bool

	OnClose func(conn *Connection)
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(types int, conn net.Conn, connID uint32, maxMsgChanLen uint32, maxPacketSize uint32) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Closed

func (c *Connection) Closed() bool

func (*Connection) GetConnID

func (c *Connection) GetConnID() uint32

func (*Connection) GetConnection

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

func (*Connection) GetMsgBuffChan

func (c *Connection) GetMsgBuffChan() <-chan *Message

func (*Connection) GetMsgChan

func (c *Connection) GetMsgChan() <-chan *Message

func (*Connection) GetProperty

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

func (*Connection) GetTcpConnection

func (c *Connection) GetTcpConnection() *net.TCPConn

func (*Connection) GetUpdateTime

func (c *Connection) GetUpdateTime() int64

func (*Connection) GetWebsocketConnection

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

func (*Connection) OnlineDuration

func (c *Connection) OnlineDuration() int64

func (*Connection) RemoteAddr

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

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

func (*Connection) SendBuffMsg

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

func (*Connection) SendMsg

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

func (*Connection) SetOnClose

func (c *Connection) SetOnClose(hookFunc func(*Connection))

func (*Connection) SetProperty

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

func (*Connection) SetTcpConn

func (c *Connection) SetTcpConn(tcpConn *net.TCPConn)

func (*Connection) SetWebsocketConn

func (c *Connection) SetWebsocketConn(websocketConn *websocket.Conn)

func (*Connection) UpdateTime

func (c *Connection) UpdateTime()

type IRouter

type IRouter interface {
	PreHandle(req *Request)
	Handle(req *Request)
	PostHandle(req *Request)
}

type Message

type Message struct {
	DataLen uint32
	Id      byte
	Data    []byte
}

func NewMsg

func NewMsg(id byte, data []byte) *Message

func (*Message) GetData

func (msg *Message) GetData() []byte

func (*Message) GetDataLen

func (msg *Message) GetDataLen() uint32

func (*Message) GetMsgId

func (msg *Message) GetMsgId() byte

func (*Message) SetData

func (msg *Message) SetData(data []byte)

func (*Message) SetDataLen

func (msg *Message) SetDataLen(len uint32)

func (*Message) SetMsgId

func (msg *Message) SetMsgId(msgId byte)

type MsgHandle

type MsgHandle struct {
	Apis             map[byte]IRouter
	WorkerPoolSize   uint32
	TaskQueue        []chan *Request
	MaxWorkerTaskLen uint32
}

func NewMsgHandle

func NewMsgHandle(workerPoolSize uint32, maxWorkerTaskLen uint32) *MsgHandle

func (*MsgHandle) AddRouter

func (mh *MsgHandle) AddRouter(msgId byte, router IRouter)

func (*MsgHandle) DoMsgHandler

func (mh *MsgHandle) DoMsgHandler(request *Request)

func (*MsgHandle) DoReceive

func (mh *MsgHandle) DoReceive(request *Request)

func (*MsgHandle) SendMsgToTaskQueue

func (mh *MsgHandle) SendMsgToTaskQueue(request *Request)

func (*MsgHandle) StartOneWorker

func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan *Request)

func (*MsgHandle) StartWorkerPool

func (mh *MsgHandle) StartWorkerPool()

type Request

type Request struct {
	Conn *Connection
	Msg  *Message
}

func (*Request) GetConnection

func (r *Request) GetConnection() *Connection

func (*Request) GetData

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

func (*Request) GetMsgID

func (r *Request) GetMsgID() byte

Jump to

Keyboard shortcuts

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