Documentation ¶
Index ¶
- Variables
- type CallBack
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Connected() bool
- func (c *Connection) Context() interface{}
- func (c *Connection) HandleEvent(fd int, events poller.Event)
- func (c *Connection) PeerAddr() string
- func (c *Connection) ReadBufferLength() int64
- func (c *Connection) Send(data interface{}, opts ...ConnectionOption) error
- func (c *Connection) SetContext(ctx interface{})
- func (c *Connection) ShutdownWrite() error
- func (c *Connection) UserBuffer() *[]byte
- func (c *Connection) WriteBufferLength() int64
- type ConnectionOption
- type ConnectionOptions
- type DefaultProtocol
- type Handler
- type KeyValueContext
- type LoadBalanceStrategy
- type Option
- func Address(a string) Option
- func CustomProtocol(p Protocol) Option
- func IdleTime(t time.Duration) Option
- func LoadBalance(strategy LoadBalanceStrategy) Option
- func MetricsServer(path, address string) Option
- func Network(n string) Option
- func NumLoops(n int) Option
- func ReusePort(reusePort bool) Option
- type Options
- type Protocol
- type SendInLoopFunc
- type Server
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrConnectionClosed = errors.New("connection closed")
Functions ¶
This section is empty.
Types ¶
type CallBack ¶ added in v0.4.0
type CallBack interface { OnMessage(c *Connection, ctx interface{}, data []byte) interface{} OnClose(c *Connection) }
type Connection ¶ added in v0.4.0
type Connection struct { KeyValueContext // contains filtered or unexported fields }
Connection TCP 连接
func NewConnection ¶ added in v0.4.0
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) Connected ¶ added in v0.4.0
func (c *Connection) Connected() bool
Connected 是否已连接
func (*Connection) Context ¶ added in v0.4.0
func (c *Connection) Context() interface{}
Context 获取 Context
func (*Connection) HandleEvent ¶ added in v0.4.0
func (c *Connection) HandleEvent(fd int, events poller.Event)
HandleEvent 内部使用,event loop 回调
func (*Connection) PeerAddr ¶ added in v0.4.0
func (c *Connection) PeerAddr() string
PeerAddr 获取客户端地址信息
func (*Connection) ReadBufferLength ¶ added in v0.4.0
func (c *Connection) ReadBufferLength() int64
ReadBufferLength read buffer 当前积压的数据长度
func (*Connection) Send ¶ added in v0.4.0
func (c *Connection) Send(data interface{}, opts ...ConnectionOption) error
Send 用来在非 loop 协程发送
func (*Connection) SetContext ¶ added in v0.4.0
func (c *Connection) SetContext(ctx interface{})
SetContext 设置 Context
func (*Connection) ShutdownWrite ¶ added in v0.4.0
func (c *Connection) ShutdownWrite() error
ShutdownWrite 关闭可写端,等待读取完接收缓冲区所有数据
func (*Connection) UserBuffer ¶ added in v0.4.0
func (c *Connection) UserBuffer() *[]byte
func (*Connection) WriteBufferLength ¶ added in v0.4.0
func (c *Connection) WriteBufferLength() int64
WriteBufferLength write buffer 当前积压的数据长度
type ConnectionOption ¶ added in v0.4.0
type ConnectionOption func(*ConnectionOptions)
func SendInLoop ¶ added in v0.4.0
func SendInLoop(f SendInLoopFunc) ConnectionOption
type ConnectionOptions ¶ added in v0.4.0
type ConnectionOptions struct {
// contains filtered or unexported fields
}
type DefaultProtocol ¶ added in v0.4.0
type DefaultProtocol struct{}
DefaultProtocol 默认 Protocol
func (*DefaultProtocol) Packet ¶ added in v0.4.0
func (d *DefaultProtocol) Packet(c *Connection, data interface{}) []byte
Packet 封包
func (*DefaultProtocol) UnPacket ¶ added in v0.4.0
func (d *DefaultProtocol) UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte)
UnPacket 拆包
type KeyValueContext ¶ added in v0.4.0
type KeyValueContext struct {
// contains filtered or unexported fields
}
func (*KeyValueContext) Delete ¶ added in v0.4.0
func (c *KeyValueContext) Delete(key string)
func (*KeyValueContext) Get ¶ added in v0.4.0
func (c *KeyValueContext) Get(key string) (value interface{}, exists bool)
func (*KeyValueContext) Set ¶ added in v0.4.0
func (c *KeyValueContext) Set(key string, value interface{})
type LoadBalanceStrategy ¶ added in v0.2.1
func LeastConnection ¶ added in v0.2.1
func LeastConnection() LoadBalanceStrategy
func RoundRobin ¶ added in v0.2.1
func RoundRobin() LoadBalanceStrategy
type Option ¶
type Option func(*Options)
Option ...
func LoadBalance ¶ added in v0.2.1
func LoadBalance(strategy LoadBalanceStrategy) Option
func MetricsServer ¶ added in v0.1.11
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 ¶ added in v0.1.2
type Protocol interface { UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte) Packet(c *Connection, data interface{}) []byte }
Protocol 自定义协议编解码接口
type SendInLoopFunc ¶ added in v0.4.0
type SendInLoopFunc func(interface{})
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server gev Server
func (*Server) RunAfter ¶ added in v0.0.2
func (s *Server) RunAfter(d time.Duration, f func()) *timingwheel.Timer
RunAfter 延时任务
Example ¶
handler := new(example) s, err := NewServer(handler, Network("tcp"), Address(":1833"), NumLoops(8), ReusePort(true)) if err != nil { panic(err) } go s.Start() defer s.Stop() s.RunAfter(time.Second, func() { fmt.Println("RunAfter") }) time.Sleep(2500 * time.Millisecond)
Output: RunAfter
func (*Server) RunEvery ¶ added in v0.0.2
func (s *Server) RunEvery(d time.Duration, f func()) *timingwheel.Timer
RunEvery 定时任务
Example ¶
handler := new(example) s, err := NewServer(handler, Network("tcp"), Address(":1833"), NumLoops(8), ReusePort(true)) if err != nil { panic(err) } go s.Start() defer s.Stop() t := s.RunEvery(time.Second, func() { fmt.Println("EveryFunc") }) time.Sleep(4500 * time.Millisecond) t.Stop() time.Sleep(4500 * time.Millisecond)
Output: EveryFunc EveryFunc EveryFunc EveryFunc
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
benchmarks
|
|
example
|
|
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 |
plugins
|
|
Click to show internal directories.
Click to hide internal directories.