gev

package module
v0.0.0-...-122c724 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 18 Imported by: 0

README

paas-neticko-go

netiko - go nio network framework

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnectionClosed = errors.New("connection closed")

Functions

This section is empty.

Types

type CallBack

type CallBack interface {
	OnMessage(c *Connection, ctx interface{}, data []byte) interface{}
	OnClose(c *Connection)
}

type Connection

type Connection struct {
	KeyValueContext
	// contains filtered or unexported fields
}

Connection TCP 连接

func NewConnection

func NewConnection(fd int,
	loop *eventloop.EventLoop,
	sa unix.Sockaddr,
	protocol Protocol,
	tw *timingwheel.TimingWheel,
	idleTime time.Duration,
	callBack CallBack) *Connection

NewConnection 创建 Connection

func (*Connection) Close

func (c *Connection) Close() error

Close 关闭连接

func (*Connection) Connected

func (c *Connection) Connected() bool

Connected 是否已连接

func (*Connection) Context

func (c *Connection) Context() interface{}

Context 获取 Context

func (*Connection) HandleEvent

func (c *Connection) HandleEvent(fd int, events poller.Event)

HandleEvent 内部使用,event loop 回调

func (*Connection) PeerAddr

func (c *Connection) PeerAddr() string

PeerAddr 获取客户端地址信息

func (*Connection) ReadBufferLength

func (c *Connection) ReadBufferLength() int64

ReadBufferLength read buffer 当前积压的数据长度

func (*Connection) Send

func (c *Connection) Send(data interface{}, opts ...ConnectionOption) error

Send 用来在非 loop 协程发送

func (*Connection) SetContext

func (c *Connection) SetContext(ctx interface{})

SetContext 设置 Context

func (*Connection) ShutdownWrite

func (c *Connection) ShutdownWrite() error

ShutdownWrite 关闭可写端,等待读取完接收缓冲区所有数据

func (*Connection) UserBuffer

func (c *Connection) UserBuffer() *[]byte

func (*Connection) WriteBufferLength

func (c *Connection) WriteBufferLength() int64

WriteBufferLength write buffer 当前积压的数据长度

type ConnectionOption

type ConnectionOption func(*ConnectionOptions)

func SendInLoop

func SendInLoop(f SendInLoopFunc) ConnectionOption

type ConnectionOptions

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

type DefaultProtocol

type DefaultProtocol struct{}

DefaultProtocol 默认 Protocol

func (*DefaultProtocol) Packet

func (d *DefaultProtocol) Packet(c *Connection, data interface{}) []byte

Packet 封包

func (*DefaultProtocol) UnPacket

func (d *DefaultProtocol) UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte)

UnPacket 拆包

type Handler

type Handler interface {
	CallBack
	OnConnect(c *Connection)
}

Handler Server 注册接口

type KeyValueContext

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

func (*KeyValueContext) Delete

func (c *KeyValueContext) Delete(key string)

func (*KeyValueContext) Get

func (c *KeyValueContext) Get(key string) (value interface{}, exists bool)

func (*KeyValueContext) Set

func (c *KeyValueContext) Set(key string, value interface{})

type LoadBalanceStrategy

type LoadBalanceStrategy func([]*eventloop.EventLoop) *eventloop.EventLoop

func LeastConnection

func LeastConnection() LoadBalanceStrategy

func RoundRobin

func RoundRobin() LoadBalanceStrategy

type Option

type Option func(*Options)

Option ...

func Address

func Address(a string) Option

Address server 监听地址

func CustomProtocol

func CustomProtocol(p Protocol) Option

CustomProtocol 数据包处理

func IdleTime

func IdleTime(t time.Duration) Option

IdleTime 最大空闲时间(秒)

func LoadBalance

func LoadBalance(strategy LoadBalanceStrategy) Option

func MetricsServer

func MetricsServer(path, address string) Option

func Network

func Network(n string) Option

Network [tcp] 暂时只支持tcp

func NumLoops

func NumLoops(n int) Option

NumLoops work eventloop 的数量

func ReusePort

func ReusePort(reusePort bool) Option

ReusePort 设置 SO_REUSEPORT

type Options

type Options struct {
	Network   string
	Address   string
	NumLoops  int
	ReusePort bool
	IdleTime  time.Duration
	Protocol  Protocol
	Strategy  LoadBalanceStrategy
	// contains filtered or unexported fields
}

Options 服务配置

type Protocol

type Protocol interface {
	UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte)
	Packet(c *Connection, data interface{}) []byte
}

Protocol 自定义协议编解码接口

type SendInLoopFunc

type SendInLoopFunc func(interface{})

type Server

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

Server gev Server

func NewServer

func NewServer(handler Handler, opts ...Option) (server *Server, err error)

NewServer 创建 Server

func (*Server) Options

func (s *Server) Options() Options

Options 返回 options

func (*Server) RunAfter

func (s *Server) RunAfter(d time.Duration, f func()) *timingwheel.Timer

RunAfter 延时任务

func (*Server) RunEvery

func (s *Server) RunEvery(d time.Duration, f func()) *timingwheel.Timer

RunEvery 定时任务

func (*Server) Start

func (s *Server) Start()

Start 启动 Server

func (*Server) Stop

func (s *Server) Stop()

Stop 关闭 Server

Directories

Path Synopsis
Package log is from https://github.com/micro/go-micro/blob/master/util/log/log.go
Package log is from https://github.com/micro/go-micro/blob/master/util/log/log.go

Jump to

Keyboard shortcuts

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