znet

package
v0.0.11-otel Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(conf *zconfig.ZConfig) ziface.IServer

Types

type ConnManager

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

func NewConnManager

func NewConnManager() *ConnManager

func (*ConnManager) Add

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

func (*ConnManager) ClearConn

func (cm *ConnManager) ClearConn()

func (*ConnManager) Get

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

func (*ConnManager) Len

func (cm *ConnManager) Len() int

func (*ConnManager) Remove

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

type Connection

type Connection struct {
	TCPServer  ziface.IServer
	Conn       *net.TCPConn
	ConnID     uint64
	MsgHandler ziface.IMsgHandle

	ExitBuffChan chan struct{}
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(server ziface.IServer, conn *net.TCPConn, connID uint64, mh ziface.IMsgHandle) *Connection

func (*Connection) GetConnID

func (c *Connection) GetConnID() uint64

func (*Connection) GetProperty

func (c *Connection) GetProperty(key string) (any, bool)

func (*Connection) GetTCPConnection

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

func (*Connection) RemoteAddr

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

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

func (*Connection) SendMsg

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

func (*Connection) SetProperty

func (c *Connection) SetProperty(key string, value any)

func (*Connection) Start

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

func (*Connection) Stop

func (c *Connection) Stop()

type DataPack

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

func NewDataPack

func NewDataPack(c *zconfig.ZConfig) *DataPack

func (*DataPack) GetHeadLen

func (dp *DataPack) GetHeadLen() uint32

func (*DataPack) Pack

func (dp *DataPack) Pack(msg ziface.IMessage) ([]byte, error)

func (*DataPack) Unpack

func (dp *DataPack) Unpack(data []byte) (ziface.IMessage, error)

type Message

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

func NewMsgPackage

func NewMsgPackage(id uint32, data []byte) *Message

func (*Message) GetData

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

func (*Message) GetDataLen

func (m *Message) GetDataLen() uint32

func (*Message) GetMsgID

func (m *Message) GetMsgID() uint32

func (*Message) SetData

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

type MsgHandle

type MsgHandle struct {
	Apis      map[uint32]ziface.HandleFunc
	TaskQueue []chan ziface.IRequest
	// contains filtered or unexported fields
}

func NewMsgHandle

func NewMsgHandle(config *zconfig.ZConfig) *MsgHandle

func (*MsgHandle) AddRouter

func (mh *MsgHandle) AddRouter(msgID uint32, handle ziface.HandleFunc)

func (*MsgHandle) DoMsgHandle

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

func (*MsgHandle) SendMsgToTaskQueue

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

func (*MsgHandle) StarWorkerPool

func (mh *MsgHandle) StarWorkerPool()

type Request

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

func (*Request) GetConnection

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

func (*Request) GetData

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

func (*Request) GetMsgID

func (r *Request) GetMsgID() uint32

type Server

type Server struct {
	ConnIDGen atomic.Uint64 // TODO: use distributed unique id to support multiple servers

	ConnMgr ziface.IConnManager
	// contains filtered or unexported fields
}

func (*Server) AddRouter

func (s *Server) AddRouter(msgID uint32, handle ziface.HandleFunc)

func (*Server) CallOnConnStart

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

func (*Server) CallOnConnStop

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

func (*Server) Config

func (s *Server) Config() *zconfig.ZConfig

func (*Server) GetConnMgr

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

func (*Server) NotifyClose

func (s *Server) NotifyClose(c ziface.IConnection)

func (*Server) Serve

func (s *Server) Serve()

func (*Server) SetOnConnStart

func (s *Server) SetOnConnStart(f func(conn ziface.IConnection))

func (*Server) SetOnConnStop

func (s *Server) SetOnConnStop(f func(conn ziface.IConnection))

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

Jump to

Keyboard shortcuts

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