connection

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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.1.10

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 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) Close added in v0.1.9

func (c *Connection) Close() error

Close 关闭连接

func (*Connection) Connected added in v0.0.2

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 added in v0.1.10

func (c *Connection) ReadBufferLength() int64

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

func (*Connection) Send

func (c *Connection) Send(data interface{}, opts ...Option) 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 added in v0.2.0

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

func (*Connection) WriteBufferLength added in v0.1.10

func (c *Connection) WriteBufferLength() int64

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

type DefaultProtocol added in v0.1.2

type DefaultProtocol struct{}

DefaultProtocol 默认 Protocol

func (*DefaultProtocol) Packet added in v0.1.2

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

Packet 封包

func (*DefaultProtocol) UnPacket added in v0.1.2

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

UnPacket 拆包

type KeyValueContext added in v0.1.10

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

func (*KeyValueContext) Delete added in v0.1.10

func (c *KeyValueContext) Delete(key string)

func (*KeyValueContext) Get added in v0.1.10

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

func (*KeyValueContext) Set added in v0.1.10

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

type Option added in v0.3.0

type Option func(*Options)

func SendInLoop added in v0.3.0

func SendInLoop(f SendInLoopFunc) Option

type Options added in v0.3.0

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

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.3.0

type SendInLoopFunc func(interface{})

Jump to

Keyboard shortcuts

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