iface

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 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 IAcceptor

type IAcceptor interface {
	Run(fd int, loop IEventLoop) error
	Exit()
	IncrementID() int
	Close()
}

type IConnect

type IConnect interface {
	Read(bs []byte) (int, error)
	GetFd() int
	GetID() int
	Close() error
	GetPacker() IPacker
	Write(msgID uint32, bs []byte) (int, error)
	GetAddress() net.Addr
	SetEpFd(epfd int)
	GetEpFd() int
	SetPoller(poller IPoller)
	SetWriteBuff([]byte)
	GetWriteBuff() ([]byte, bool)
}

type IConnectManager

type IConnectManager interface {
	Get(connFD int) IConnect
	Add(conn IConnect) int
	Remove(conn IConnect)
	Len() int
	ClearByEpFd(epfd int)
	ClearAll()
}

type IEventLoop

type IEventLoop interface {
	Init(connectMgr IConnectManager) error // 初始化,也就是创建epoll
	Start(messageCh chan<- IRequest)       // 开启事件循环,也就是所有的epoll执行epoll_wait
	Stop()                                 // 停止
	AddRead(conn IConnect) error
	Remove(conn IConnect) error
}

IEventLoop 事件循环抽象层,所有的epoll都是通过这个来操作

type IHooks added in v0.0.2

type IHooks interface {
	OnOpen(connect IConnect)
	OnClose(connect IConnect)
}

type IMessage

type IMessage interface {
	ID() uint32
	Bytes() []byte
	String() string
	Len() int
	SetData([]byte)
	SetReadNum(int)
	GetReadNum() int
}

type IPacker

type IPacker interface {
	ReadFull(fd int) (IMessage, error)              // 读包
	Pack(msgID uint32, data []byte) ([]byte, error) // 封包
	UnPack([]byte) (IMessage, error)                // 解包
}

IPacker 数据封装抽象层

type IPoller

type IPoller interface {
	AddRead(fd int, connID int) error
	AddWrite(fd, connID int) error
	ModWrite(fd, connID int) error
	ModRead(fd, connId int) error
	Wait(emitCh chan<- IRequest)
	Remove(fd int) error
	Close() error
	GetConnectMgr() IConnectManager
}

type IRequest

type IRequest interface {
	GetConnect() IConnect
	GetMessage() IMessage
}

type IRouter

type IRouter interface {
	Do(request IRequest)
}

IRouter 路由抽象,根据业务场景实现这个接口即可,通过msgID和router对应

type IServer

type IServer interface {
	Start()
	Stop()
	AddRouter(msgID uint32, router IRouter)
}

IServer Server抽象层

Jump to

Keyboard shortcuts

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