Documentation ¶
Index ¶
- type Conn
- type TCPTransfer
- func (t *TCPTransfer) Close(addr string) error
- func (t *TCPTransfer) Handler(r *tcp.Remote) error
- func (t *TCPTransfer) OnAccepted(r *tcp.Remote) error
- func (t *TCPTransfer) OnClosed(r *tcp.Remote) error
- func (t *TCPTransfer) Serve() error
- func (t *TCPTransfer) SetHost(host string)
- func (t *TCPTransfer) SetLogger(logger logger.Iface)
- func (t *TCPTransfer) SetMaxOpenConn(num int)
- func (t *TCPTransfer) SetOnClosedHandler(fn func(addr string))
- func (t *TCPTransfer) SetOnConnectedHandler(fn func(c Conn))
- func (t *TCPTransfer) SetOnFrameParseErrorHandler(fn func(frame *proto.TransferFrame, c Conn))
- func (t *TCPTransfer) SetOnReceivedHandler(fn func(frame *proto.TransferFrame, c Conn))
- func (t *TCPTransfer) SetPort(port string)
- func (t *TCPTransfer) Stop()
- type Transfer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { Addr() string // 获取远端地址 IsConnected() bool // 是否已连接 Close() error // 关闭与对端的连接 Read(p []byte) (int, error) // 将缓冲区的数据读取到切片buf内,并返回实际读取的数据长度 ReadN(n int) []byte // 读取N个字节的数据 Len() int // 获取接收数据的总长度 Copy(p []byte) (int, error) // 将缓冲区的数据拷贝到切片p内,并返回实际读取的数据长度 Write(p []byte) (int, error) // 将切片buf中的内容追加到发数据缓冲区内,并返回写入的数据长度 Seek(offset int64, whence int) (int64, error) Drain() error // 将缓冲区的数据发生到客户端 }
Conn 客户端连接实现
type TCPTransfer ¶
type TCPTransfer struct {
// contains filtered or unexported fields
}
TCPTransfer TCP传输层实现
func (*TCPTransfer) Close ¶
func (t *TCPTransfer) Close(addr string) error
func (*TCPTransfer) OnAccepted ¶
func (t *TCPTransfer) OnAccepted(r *tcp.Remote) error
func (*TCPTransfer) OnClosed ¶
func (t *TCPTransfer) OnClosed(r *tcp.Remote) error
OnClosed 连接关闭, 删除此连接的消费者记录或生产者记录
func (*TCPTransfer) SetHost ¶
func (t *TCPTransfer) SetHost(host string)
func (*TCPTransfer) SetLogger ¶
func (t *TCPTransfer) SetLogger(logger logger.Iface)
func (*TCPTransfer) SetMaxOpenConn ¶
func (t *TCPTransfer) SetMaxOpenConn(num int)
func (*TCPTransfer) SetOnClosedHandler ¶
func (t *TCPTransfer) SetOnClosedHandler(fn func(addr string))
SetOnClosedHandler 设置当客户端断开连接时的事件
func (*TCPTransfer) SetOnConnectedHandler ¶
func (t *TCPTransfer) SetOnConnectedHandler(fn func(c Conn))
SetOnConnectedHandler 设置当客户端连接成功时的事件
func (*TCPTransfer) SetOnFrameParseErrorHandler ¶
func (t *TCPTransfer) SetOnFrameParseErrorHandler(fn func(frame *proto.TransferFrame, c Conn))
SetOnFrameParseErrorHandler 设置当客户端数据帧解析出错时的事件
func (*TCPTransfer) SetOnReceivedHandler ¶
func (t *TCPTransfer) SetOnReceivedHandler(fn func(frame *proto.TransferFrame, c Conn))
SetOnReceivedHandler 设置当收到客户端数据帧时的事件
func (*TCPTransfer) SetPort ¶
func (t *TCPTransfer) SetPort(port string)
func (*TCPTransfer) Stop ¶
func (t *TCPTransfer) Stop()
type Transfer ¶
type Transfer interface { SetHost(host string) SetPort(port string) // 设置绑定端口 SetMaxOpenConn(num int) // 设置最大连接数量 SetLogger(logger logger.Iface) // logger // SetOnConnectedHandler 设置当客户端连接成功时的事件 SetOnConnectedHandler(fn func(c Conn)) // SetOnClosedHandler 设置当客户端断开连接时的事件 SetOnClosedHandler(fn func(addr string)) // SetOnReceivedHandler 设置当收到客户端数据帧时的事件 SetOnReceivedHandler(fn func(frame *proto.TransferFrame, c Conn)) // SetOnFrameParseErrorHandler 设置当客户端数据帧解析出错时的事件 SetOnFrameParseErrorHandler(fn func(frame *proto.TransferFrame, c Conn)) Close(addr string) error // 主动关闭一个客户端连接 Serve() error // 阻塞式启动服务 Stop() }
Transfer Engine 传输层实现
Click to show internal directories.
Click to hide internal directories.