server

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: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRouter

type BaseRouter struct{}

func (*BaseRouter) Do

func (b *BaseRouter) Do(request iface.IRequest)

Do 默认实现

type Connect

type Connect struct {
	Address net.Addr //
	// contains filtered or unexported fields
}

Connect TCP连接成功建立后,会抽象一个Connect

func (*Connect) Close

func (c *Connect) Close() error

Close 断开连接

func (*Connect) GetAddress

func (c *Connect) GetAddress() net.Addr

func (*Connect) GetEpFd

func (c *Connect) GetEpFd() int

GetEpFd 获取这个连接的epoll fd

func (*Connect) GetFd

func (c *Connect) GetFd() int

GetFd 获取系统分配的fd

func (*Connect) GetID

func (c *Connect) GetID() int

GetID 获取连接ID

func (*Connect) GetPacker

func (c *Connect) GetPacker() iface.IPacker

GetPacker 获取packer

func (*Connect) GetWriteBuff added in v0.0.3

func (c *Connect) GetWriteBuff() ([]byte, bool)

GetWriteBuff .

func (*Connect) Read

func (c *Connect) Read(bs []byte) (int, error)

Read 读取数据

func (*Connect) SetEpFd

func (c *Connect) SetEpFd(epfd int)

SetEpFd 设置这个连接属于哪个epoll

func (*Connect) SetPoller added in v0.0.3

func (c *Connect) SetPoller(poller iface.IPoller)

SetPoller .

func (*Connect) SetWriteBuff added in v0.0.3

func (c *Connect) SetWriteBuff(bytes []byte)

SetWriteBuff .

func (*Connect) Write

func (c *Connect) Write(msgID uint32, bytes []byte) (int, error)

Write 写数据

type ConnectManager

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

ConnectManager 所有连接都保存在这里

func NewConnectManager

func NewConnectManager() *ConnectManager

NewConnectManager 构造一个实例

func (*ConnectManager) Add

func (c *ConnectManager) Add(conn iface.IConnect) int

Add 添加一个连接

func (*ConnectManager) ClearAll

func (c *ConnectManager) ClearAll()

ClearAll 清除所有连接

func (*ConnectManager) ClearByEpFd

func (c *ConnectManager) ClearByEpFd(epfd int)

ClearByEpFd 删除在这个epfd上管理的所有连接,只有这个epoll出现错误的时候才会调用这个方法 一份数据最好不要存多个地方,在一个地方统一管理

func (*ConnectManager) Get

func (c *ConnectManager) Get(connFD int) iface.IConnect

Get 通过connID获取连接实例

func (*ConnectManager) Len

func (c *ConnectManager) Len() int

Len 获取有多少个连接

func (*ConnectManager) Remove

func (c *ConnectManager) Remove(conn iface.IConnect)

Remove 删除一个连接

type Option

type Option = func(opts *Options)

func WithHooks added in v0.0.2

func WithHooks(hooks iface.IHooks) Option

WithHooks hooks

func WithLogOutput

func WithLogOutput(output io.Writer) Option

WithLogOutput 日志保存目录,默认按天保存在logs目录

func WithNumEventLoop

func WithNumEventLoop(numEventLoop int) Option

WithNumEventLoop event-loop数量配置

func WithPacker

func WithPacker(packer iface.IPacker) Option

WithPacker 使用自定义的封包方式

func WithTCPKeepAlive

func WithTCPKeepAlive(duration time.Duration) Option

WithTCPKeepAlive 设置时间 TCP keepalive

type Options

type Options struct {
	NumEventLoop int           // 配置event-loop数量,默认:2
	NumWorker    int           // 用来处理业务逻辑的goroutine数量,默认CPU核心数
	LogOutput    io.Writer     // 日志保存目标,默认:Stdout
	Packer       iface.IPacker // 实现这个接口可以使用自定义的封包方式
	TCPKeepAlive time.Duration // TCP keepalive
	Hooks        iface.IHooks  // hooks
}

Options 可选项配置,未配置时使用默认值

type RouterMgr

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

func NewRouterMgr

func NewRouterMgr() *RouterMgr

func (*RouterMgr) Add

func (r *RouterMgr) Add(msgID uint32, router iface.IRouter)

Add 添加路由

func (*RouterMgr) Do

func (r *RouterMgr) Do(request iface.IRequest) error

func (*RouterMgr) Get

func (r *RouterMgr) Get(msgID uint32) (iface.IRouter, error)

Get 根据msgID获取路由

type Server

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

func New

func New(ip string, port int, opts ...Option) *Server

New 创建Server

func (*Server) AddRouter

func (s *Server) AddRouter(msgID uint32, router iface.IRouter)

AddRouter 添加路由处理

func (*Server) Start

func (s *Server) Start()

Start 启动

func (*Server) Stop

func (s *Server) Stop()

Stop 停止

Jump to

Keyboard shortcuts

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