gascnet

package module
v0.0.0-...-3aa6513 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: BSD-2-Clause Imports: 13 Imported by: 0

README

gascnet�ο�gnet��evioʵ�֣�ֻ��epoll��kqueue���˼򵥵ķ�װ���ṩ��tcp���ӿɶ���д�¼��ļ�����

gascnet��gnet��evio�IJ�ͬ�����ڻص��д�����eventloopʵ����id�ţ��Ա��������л����ܹ�������������

����˵����

����Dial��������ij����ַ��

����NewEngine���ڴ����¼�engine��

����WithLoops��������engine��eventloop������ÿһ��eventloop��һ��epoll��kqueue��ʵ����������ֵ����0�򴴽���eventloop��������cpu����С��0��eventloop��������cpu����ȥ��ֵ������0����ʵ�ʵ�eventloop����һ����

����WithLoops��������engine��ÿһ��eventloop�Ƿ���ռһ���̡߳�

����WithProtoAddr��������service�󶨵�ip�Ͷ˿�,service���Բ����ø�ֵ��

����WithListenbacklog��������service listeen��backlog���ȡ�

����WithReusePort��WithReuseAddr����service�󶨵ĵ�ַ�Ͷ˿��Ƿ���ռ��

����WithLoadBalance����service��accept���µ����Ӻ��ĸ��ؾ������ԡ�

engine�Ľӿ���

LoopNum���� ���ڻ�ȡ��ǰengine��evloop������

AddTask���ڴ���һ����ָ��loopid��ִ�к��������񡣻ص���������һ��ר�ŵ�Э���е��á�

AddService���ڴ���service���ص���������һ��ר�ŵ�Э���е��á�

StartService��������service��������serviceʹ��WithProtoAddr�����˵�ַ����ʱ���󶨸õ�ַ���ص���������һ��ר�ŵ�Э���е��á�

StopServiceֹͣservice��������service�����˵�ַ����close���ص���������һ��ר�ŵ�Э���е��á�

DelService�Ƴ���service���ص���������һ��ר�ŵ�Э���е��á�

AddToService�����������ӵ�ָ��loop�ϵ�ָ��service�ϣ���Ҫ���ڹ����������������ӡ�

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFuncQueue

func NewFuncQueue(initlen, maxlen int) *funcqueue

Types

type Conn

type Conn interface {
	SetCtx(ctx interface{})
	GetCtx() (ctx interface{})

	//当前连接运行的 loopid
	GetLoopid() int
	//从loop上移除
	Detach() error

	LocalAddr() string
	RemoteAddr() string

	//socket读写缓存大小
	SetReadBuffer(bytes int) error
	SetWriteBuffer(bytes int) error

	//socket opt
	SetLinger(sec int) error
	SetKeepAlivePeriod(sec, probes int) error
	SetNoDelay(nodelay bool) error

	Close() error

	Watch(canread, canwrite bool) error

	Read(buf []byte) (int, error)
	Write(buf []byte) (int, error)
}

func Dial

func Dial(protoaddr string) (Conn, error)

type EngOption

type EngOption func(*engoption)

func WithLockThread

func WithLockThread(value bool) EngOption

func WithLoops

func WithLoops(value int) EngOption

func WithNotifyQueueLen

func WithNotifyQueueLen(value int) EngOption

type Engine

type Engine interface {
	LoopNum() int
	AddTask(loopid int, call func(loopid int)) error

	AddService(svrid int, call func(svrid int, err error), evhandle EvHandler, opts ...SvrOption) error
	StartService(svrid int, call func(svrid int, err error)) error
	StopService(svrid int, call func(svrid int, err error)) error
	DelService(svrid int, call func(svrid int, err error)) error

	//not thread safe
	AddToService(loopid, svrid int, conn Conn) error
}

func NewEngine

func NewEngine(opts ...EngOption) Engine

type EvHandler

type EvHandler interface {
	//service出错时调用
	OnServiceErr(loopid int, err error)

	//新连接创建成功调用
	OnConnOpen(loopid int, conn Conn)

	//连接关闭成功调用
	OnConnClose(loopid int, conn Conn, err error)

	//连接接收到流量调用
	OnConnReadWrite(loopid int, conn Conn, canread, canwrite bool)
}

type LoadBalance

type LoadBalance int
const (
	LoadBalanceRR  LoadBalance = iota //轮询
	LoadBalanceLC                     //最少连接
	LoadBalanceSAH                    //源地址哈希
)

type SvrOption

type SvrOption func(*svroption)

func WithListenbacklog

func WithListenbacklog(value int) SvrOption

func WithLoadBalance

func WithLoadBalance(value LoadBalance) SvrOption

func WithProtoAddr

func WithProtoAddr(value string) SvrOption

func WithReuseAddr

func WithReuseAddr(value bool) SvrOption

func WithReusePort

func WithReusePort(value bool) SvrOption

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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