aiface

package
v0.0.0-...-6c53c4d Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandleFunc

type HandleFunc func(*net.TCPConn, []byte, int) error

Define a method to handle connection business, and bind it to the connection

type IConnManager

type IConnManager interface {
	Add(conn IConnection) //add connection
	Remove(conn IConnection)
	Get(connID uint32) (IConnection, error) //get connection with the conngID
	Len() int                               //get the number of connections
	ClearConn()                             //Delete and stop all connections
}

Connection management abstraction layer

type IConnection

type IConnection interface {

	//1. Start, get the current connection ready to work
	Start()

	//2. Stop work
	Stop()

	//3. Get the currently Connection's socket conn
	GetTCPConnection() *net.TCPConn

	//4. Get the ID of the connected module
	GetConnID() uint32

	//5. Get the TCP status of the remote client
	GetRemoteAddr() net.Addr

	//6. send data
	SendMsg(msgId uint32, data []byte) error

	//7. Send Message data directly to remote TCP client with buffer
	SendBuffMsg(msgId uint32, data []byte) error

	//8. Set connection properties
	SetProperty(key string, value interface{})

	//8. Get connection properties
	GetProperty(key string) (interface{}, error)

	RemoveProperty(key string)
}

Define the abstraction layer of the connection module

type IMessage

type IMessage interface {
	GetMegId() uint32

	GetMsgLen() uint32

	GetData() []byte

	SetMsgId(uint32)

	SetData([]byte)

	SetDataLen(uint32)
}

type IMsgHandle

type IMsgHandle interface {

	// Immediately process messages in a non-blocking manner
	DoMsgHandler(request IRequest)

	// Add route
	AddRouter(msgId uint32, router IRouter)

	//Start the worker pool
	StartWorkerPool()

	//handed over the message to the TaskQueue
	SendMsgToTaskQueue(request IRequest)
}

Message management abstraction layer

type IRequest

type IRequest interface {

	// Get the current connection
	GetConnection() IConnection

	// Get the requested message data
	GetData() []byte

	// Get the requested message ID
	GetMsgId() uint32
}

Encapsulate the connection and data of the client's request into a Request

type IRouter

type IRouter interface {

	// Method before handling conn business
	PreHandle(request IRequest)

	// Methods of handling business
	Handle(request IRequest)

	PostHandle(requst IRequest)
}

type IServer

type IServer interface {
	Start()

	Stop()

	Serve()

	AddRouter(msgId uint32, router IRouter)

	GetConnMgr() IConnManager

	//Set the Hook function when the server connection is created
	SetOnConnStart(func(IConnection))

	SetOnConnStop(func(IConnection))

	CallOnConnStart(conn IConnection)

	CallOnConnStop(conn IConnection)
}

type IdataPack

type IdataPack interface {

	// get the length of the pack
	GetHeadLen() uint32

	Pack(msg IMessage) ([]byte, error)

	Unpack([]byte) (IMessage, error)
}

Jump to

Keyboard shortcuts

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