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) Send(buffer []byte) error
- func (c *Connection) SetContext(ctx interface{})
- func (c *Connection) ShutdownWrite() error
- type DefaultProtocol
- type KeyValueContext
- type Protocol
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrConnectionClosed = errors.New("connection closed")
ErrConnectionClosed:生成新错误连接已关闭
Functions ¶
This section is empty.
Types ¶
type CallBack ¶
type CallBack interface { OnMessage(c *Connection, ctx interface{}, data []byte) []byte OnClose(c *Connection) }
CallBack : 回调接口
type Connection ¶
type Connection struct { KeyValueContext // contains filtered or unexported fields }
Connection:TCP 连接结构体
func New ¶
func New(fd int, loop *eventloop.EventLoop, sa unix.Sockaddr, protocol Protocol, tw *timingwheel.TimingWheel, idleTime time.Duration, callBack CallBack) *Connection
New:创建 Connection
func (*Connection) HandleEvent ¶
func (c *Connection) HandleEvent(fd int, events poller.Event)
HandleEvent:内部使用,event loop 回调
func (*Connection) SetContext ¶
func (c *Connection) SetContext(ctx interface{})
SetContext:设置 Context
func (*Connection) ShutdownWrite ¶
func (c *Connection) ShutdownWrite() error
ShutdownWrite:关闭可写端,等待读取完接收缓冲区所有数据
type DefaultProtocol ¶
type DefaultProtocol struct{}
DefaultProtocol:默认 Protocol
func (*DefaultProtocol) Packet ¶
func (d *DefaultProtocol) Packet(c *Connection, data []byte) []byte
Packet:装包
func (*DefaultProtocol) UnPacket ¶
func (d *DefaultProtocol) UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte)
UnPacket:拆包
type KeyValueContext ¶
type KeyValueContext struct {
// contains filtered or unexported fields
}
KeyValueContext:键值对上下文
func (*KeyValueContext) Get ¶
func (c *KeyValueContext) Get(key string) (value interface{}, exists bool)
Get: 根据键 key 得到对应的 value 及是否存在标志 bool
func (*KeyValueContext) Set ¶
func (c *KeyValueContext) Set(key string, value interface{})
Set:进行 KeyValueContext 键值设置
type Protocol ¶
type Protocol interface { // 拆包 UnPacket(c *Connection, buffer *ringbuffer.RingBuffer) (interface{}, []byte) // 装包 Packet(c *Connection, data []byte) []byte }
Protocol:自定义协议编解码接口
Click to show internal directories.
Click to hide internal directories.