gnetrpc

package module
v0.0.0-...-b48de1d Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: GPL-3.0 Imports: 21 Imported by: 3

README

基于gnet网络框架实现的rpc

调试工具

Documentation

Index

Constants

View Source
const (
	TcpNetwork  = "tcp"
	Tcp6Network = "tcp6"
	UdpNetwork  = "udp"
	Udp6Network = "udp6"
	UnixNetwork = "unix"
)
View Source
const (
	BuiltinServiceName = "Builtin"
)

Variables

View Source
var (
	NotFoundMethod  = errors.New("not found method")
	NotFoundService = errors.New("not found service")
)

Functions

This section is empty.

Types

type AsyncHandler

type AsyncHandler func(ctx *protocol.Context, tag struct{})

type BaseService

type BaseService struct {
}

func (*BaseService) Alias

func (b *BaseService) Alias() string

func (*BaseService) AsyncHandler

func (b *BaseService) AsyncHandler(ctx *protocol.Context, tag struct{})

AsyncHandler Async handler

func (*BaseService) AsyncHandler0

func (b *BaseService) AsyncHandler0(ctx *protocol.Context, req *struct{}, rsp *struct{}, tag struct{}) *CallMode

AsyncHandler0 Async handler

func (*BaseService) Handler

func (b *BaseService) Handler(ctx *protocol.Context)

Handler sync handler

func (*BaseService) Handler0

func (b *BaseService) Handler0(ctx *protocol.Context, req *struct{}, rsp *struct{}) *CallMode

Handler0 sync handler

func (*BaseService) Init

func (b *BaseService) Init(v ...interface{}) IService

func (*BaseService) PreHandler0

func (b *BaseService) PreHandler0() (f func(ctx *protocol.Context), sort int)

PreHandler0 pre execute a smaller sort value is executed first

func (*BaseService) PreHandler1

func (b *BaseService) PreHandler1() (f func(ctx *protocol.Context), sort int)

PreHandler1 pre execute

func (*BaseService) PreHandler2

func (b *BaseService) PreHandler2() (f func(ctx *protocol.Context), sort int)

PreHandler2 pre execute

func (*BaseService) PreHandler3

func (b *BaseService) PreHandler3() (f func(ctx *protocol.Context), sort int)

PreHandler3 pre execute

type BuiltinService

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

func (*BuiltinService) Alias

func (b *BuiltinService) Alias() string

func (*BuiltinService) Benchmark

func (b *BuiltinService) Benchmark(ctx *protocol.Context, args *protocol.BenchmarkMessage, reply *protocol.BenchmarkMessage, tag struct{}) *CallMode

func (*BuiltinService) Heartbeat

func (b *BuiltinService) Heartbeat(ctx *protocol.Context, args *string, reply *string, tag struct{}) *CallMode

func (*BuiltinService) Init

func (b *BuiltinService) Init(v ...interface{}) IService

type CallMode

type CallMode struct {
	Call CallType
	Ids  []string
}

func CallBroadcast

func CallBroadcast() *CallMode

func CallBroadcastExceptSelf

func CallBroadcastExceptSelf() *CallMode

func CallNone

func CallNone() *CallMode

func CallSelf

func CallSelf() *CallMode

type CallType

type CallType int
const (
	None CallType = iota
	Self
	Broadcast
	BroadcastExceptSelf
	BroadcastSomeone
)

type Client

type Client struct {
	*gnet.BuiltinEventEngine
	// contains filtered or unexported fields
}

func NewClient

func NewClient(address string, network string, options ...OptionFn) *Client

func (*Client) AddPlugin

func (c *Client) AddPlugin(ps ...Plugin)

func (*Client) Call

func (c *Client) Call(servicePath string, serviceMethod string, metadata map[string]string, sType protocol.SerializeType, v interface{}) error

func (*Client) Close

func (c *Client) Close()

func (*Client) CtxChan

func (c *Client) CtxChan() <-chan *protocol.Context

func (*Client) MainGoroutine

func (c *Client) MainGoroutine()

func (*Client) OnBoot

func (c *Client) OnBoot(e gnet.Engine) (action gnet.Action)

func (*Client) OnClose

func (c *Client) OnClose(conn gnet.Conn, err error) gnet.Action

func (*Client) OnOpen

func (c *Client) OnOpen(conn gnet.Conn) ([]byte, gnet.Action)

func (*Client) OnShutdown

func (c *Client) OnShutdown(e gnet.Engine)

func (*Client) OnTick

func (c *Client) OnTick() (delay time.Duration, action gnet.Action)

func (*Client) OnTraffic

func (c *Client) OnTraffic(conn gnet.Conn) (action gnet.Action)

func (*Client) Register

func (c *Client) Register(is ...IService) *Client

func (*Client) Run

func (c *Client) Run() (*Client, error)

type ConnMatrix

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

func NewConnMatrix

func NewConnMatrix(async bool) *ConnMatrix

false:sync true:async

func (*ConnMatrix) Add

func (c *ConnMatrix) Add(conn gnet.Conn)

func (*ConnMatrix) Broadcast

func (c *ConnMatrix) Broadcast(buffer *bytebufferpool.ByteBuffer)
func (c *ConnMatrix) RemoveAll(msg string) {
	if c.sync {
		c.locker.Lock()
		defer c.locker.Unlock()
	}
	if c.async{
		c.asyncMap.
	}
	for k, v := range c.connMap {
		v.Close(msg)
		delete(c.connMap, k)
	}
}

func (*ConnMatrix) BroadcastExceptOne

func (c *ConnMatrix) BroadcastExceptOne(buffer *bytebufferpool.ByteBuffer, id string)

func (*ConnMatrix) BroadcastSomeone

func (c *ConnMatrix) BroadcastSomeone(buffer *bytebufferpool.ByteBuffer, ids []string)

func (*ConnMatrix) Len

func (c *ConnMatrix) Len() int

func (*ConnMatrix) Remove

func (c *ConnMatrix) Remove(id string)

func (*ConnMatrix) SendToConn

func (c *ConnMatrix) SendToConn(buffer *bytebufferpool.ByteBuffer, conn gnet.Conn)

func (*ConnMatrix) SendToOne

func (c *ConnMatrix) SendToOne(buffer *bytebufferpool.ByteBuffer, id string)

func (*ConnMatrix) SetAsync

func (c *ConnMatrix) SetAsync(async bool)

type Handler

type Handler func(ctx *protocol.Context)

type HandlerSet

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

func NewHandlerSet

func NewHandlerSet() *HandlerSet

func (*HandlerSet) AsyncCall

func (h *HandlerSet) AsyncCall(ctx *protocol.Context) error

异步

func (*HandlerSet) Call

func (h *HandlerSet) Call(ctx *protocol.Context, gPool *ants.Pool) error

func (*HandlerSet) Register

func (h *HandlerSet) Register(v IService, isPrint bool) *HandlerSet

func (*HandlerSet) SyncCall

func (h *HandlerSet) SyncCall(ctx *protocol.Context) error

同步

type IService

type IService interface {
	Init(v ...interface{}) IService
	Alias() string
}

type OptionFn

type OptionFn func(*serverOption)

func WithAntExpiryDuration

func WithAntExpiryDuration(expiryDuration time.Duration) OptionFn

func WithClientSyncMode

func WithClientSyncMode() OptionFn

func WithDefaultService

func WithDefaultService() OptionFn

func WithDisablePurge

func WithDisablePurge(disable bool) OptionFn

func WithLoadBalancing

func WithLoadBalancing(lb int) OptionFn

func WithLockOSThread

func WithLockOSThread(lockOSThread bool) OptionFn

func WithLogLevel

func WithLogLevel(lvl logging.Level) OptionFn

func WithLogPath

func WithLogPath(fileName string) OptionFn

func WithLogger

func WithLogger(logger logging.Logger) OptionFn

func WithMainGoroutineChannelCap

func WithMainGoroutineChannelCap(cap int) OptionFn

func WithMaxBlockingTasks

func WithMaxBlockingTasks(maxBlockingTasks int) OptionFn

func WithMulticastInterfaceIndex

func WithMulticastInterfaceIndex(idx int) OptionFn

func WithMulticore

func WithMulticore(multicore bool) OptionFn

func WithNonblocking

func WithNonblocking(nonblocking bool) OptionFn

func WithNumEventLoop

func WithNumEventLoop(numEventLoop int) OptionFn

func WithPanicHandler

func WithPanicHandler(panicHandler func(interface{})) OptionFn

func WithPreAlloc

func WithPreAlloc(preAlloc bool) OptionFn

func WithPrintRegisteredMethod

func WithPrintRegisteredMethod() OptionFn

func WithReadBufferCap

func WithReadBufferCap(readBufferCap int) OptionFn

func WithReuseAddr

func WithReuseAddr(reuseAddr bool) OptionFn

func WithReusePort

func WithReusePort(reusePort bool) OptionFn

func WithSocketRecvBuffer

func WithSocketRecvBuffer(recvBuf int) OptionFn

func WithSocketSendBuffer

func WithSocketSendBuffer(sendBuf int) OptionFn

func WithTCPKeepAlive

func WithTCPKeepAlive(tcpKeepAlive time.Duration) OptionFn

func WithTCPNoDelay

func WithTCPNoDelay(tcpNoDelay int) OptionFn

func WithTicker

func WithTicker(ticker bool) OptionFn

func WithWriteBufferCap

func WithWriteBufferCap(writeBufferCap int) OptionFn

type Plugin

type Plugin interface {
	OnDo(v ...interface{}) error
	Type() PluginType
	Init(v ...interface{}) Plugin
}

type PluginType

type PluginType uint16
const (
	PluginTypeOnBoot PluginType = iota
	PluginTypeOnShutdown
	PluginTypeOnOpen
	PluginTypeOnClose
	PluginTypeOnTraffic
	PluginTypeOnTick
)

type PreFunc

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

type PreFuncList

type PreFuncList []PreFunc

func (PreFuncList) Call

func (p PreFuncList) Call(ctx *protocol.Context)

func (PreFuncList) Len

func (p PreFuncList) Len() int

func (PreFuncList) Less

func (p PreFuncList) Less(i, j int) bool

func (PreFuncList) Swap

func (p PreFuncList) Swap(i, j int)

type PreHandler

type PreHandler func() (func(ctx *protocol.Context), int)

type Reset

type Reset interface {
	Reset()
}

Reset defines Reset method for pooled object.

type Server

type Server struct {
	gnet.BuiltinEventEngine
	// contains filtered or unexported fields
}

func NewServer

func NewServer(options ...OptionFn) *Server

func (*Server) AddPlugin

func (s *Server) AddPlugin(ps ...Plugin)

func (*Server) OnBoot

func (s *Server) OnBoot(engine gnet.Engine) (action gnet.Action)

func (*Server) OnClose

func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action)

func (*Server) OnOpen

func (s *Server) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*Server) OnShutdown

func (s *Server) OnShutdown(engine gnet.Engine)

func (*Server) OnTick

func (s *Server) OnTick() (delay time.Duration, action gnet.Action)

func (*Server) OnTraffic

func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action)

func (*Server) Register

func (s *Server) Register(is ...IService)

func (*Server) Run

func (s *Server) Run(netWork string, addr string) error

func (*Server) SendMessage

func (s *Server) SendMessage(conn gnet.Conn, path, method string, metadata map[string]string, body []byte)

func (*Server) UseAuthFunc

func (s *Server) UseAuthFunc(f func(ctx *protocol.Context, token string) error)

type Service

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

type ServiceSet

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

func NewServiceSet

func NewServiceSet(pool *ants.Pool, connMatrix *ConnMatrix) *ServiceSet

func (*ServiceSet) AsyncCall

func (s *ServiceSet) AsyncCall(ctx *protocol.Context) error

异步

func (*ServiceSet) Call

func (s *ServiceSet) Call(ctx *protocol.Context, tmpService *Service, mType *methodType, isAsync bool) error

func (*ServiceSet) GetService

func (s *ServiceSet) GetService(sp string) (bool, *Service)

func (*ServiceSet) Register

func (s *ServiceSet) Register(v IService, isPrint bool)

func (*ServiceSet) SyncCall

func (s *ServiceSet) SyncCall(ctx *protocol.Context) error

同步

Directories

Path Synopsis
example
gameserver Module
tool
debugtool Module

Jump to

Keyboard shortcuts

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