Documentation
¶
Index ¶
- type BidirectionalSession
- type ClientPool
- func (p *ClientPool) Call(route string, payload []byte, timeout time.Duration) ([]byte, error)
- func (p *ClientPool) CallStream(route string, payload []byte, timeout time.Duration) (<-chan []byte, error)
- func (p *ClientPool) Close()
- func (p *ClientPool) CreateBidirectionalSession(route string, handler func([]byte)) (*BidirectionalSession, error)
- func (p *ClientPool) EnableBidirectional()
- func (p *ClientPool) OnMessage(route string, handler func([]byte))
- func (p *ClientPool) ReceiveMessage() (*protocol.Frame, bool)
- func (p *ClientPool) ReceiveMessageBlocking() (*protocol.Frame, error)
- func (p *ClientPool) SendMessage(route string, data []byte) error
- func (p *ClientPool) SetCleanupInterval(interval time.Duration)
- func (p *ClientPool) SetSize(size int)
- type Conn
- func (cc *Conn) EnableBidirectional()
- func (cc *Conn) GetConnID() uint64
- func (cc *Conn) IsDead() bool
- func (cc *Conn) OnMessage(route string, handler func([]byte))
- func (cc *Conn) ReceiveMessage() (*protocol.Frame, bool)
- func (cc *Conn) ReceiveMessageBlocking() (*protocol.Frame, error)
- func (cc *Conn) SendMessage(route string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BidirectionalSession ¶
type BidirectionalSession struct {
// contains filtered or unexported fields
}
BidirectionalSession 表示一个双向通信会话
func (*BidirectionalSession) Receive ¶
func (s *BidirectionalSession) Receive() ([]byte, bool)
Receive 接收消息(非阻塞)
func (*BidirectionalSession) ReceiveBlocking ¶
func (s *BidirectionalSession) ReceiveBlocking() ([]byte, error)
ReceiveBlocking 接收消息(阻塞)
func (*BidirectionalSession) Send ¶
func (s *BidirectionalSession) Send(data []byte) error
Send 发送消息到服务器
type ClientPool ¶
type ClientPool struct {
Addr string // 服务器地址
TLSConfig *tls.Config // TLS配置
Size int // 连接池目标大小
DialTimeout time.Duration // 连接超时时间
// contains filtered or unexported fields
}
ClientPool 管理连接池中的多个TCP连接
func (*ClientPool) CallStream ¶
func (p *ClientPool) CallStream(route string, payload []byte, timeout time.Duration) (<-chan []byte, error)
CallStream 进行流式远程服务调用,返回数据通道
func (*ClientPool) CreateBidirectionalSession ¶
func (p *ClientPool) CreateBidirectionalSession(route string, handler func([]byte)) (*BidirectionalSession, error)
CreateBidirectionalSession 创建专用的双向通信会话
func (*ClientPool) EnableBidirectional ¶
func (p *ClientPool) EnableBidirectional()
EnableBidirectional 为连接池启用双向通信模式
func (*ClientPool) OnMessage ¶
func (p *ClientPool) OnMessage(route string, handler func([]byte))
OnMessage 注册全局消息处理器(对所有连接生效)
func (*ClientPool) ReceiveMessage ¶
func (p *ClientPool) ReceiveMessage() (*protocol.Frame, bool)
ReceiveMessage 接收服务器推送的消息(非阻塞,使用轮询连接)
func (*ClientPool) ReceiveMessageBlocking ¶
func (p *ClientPool) ReceiveMessageBlocking() (*protocol.Frame, error)
ReceiveMessageBlocking 接收服务器推送的消息(阻塞,使用第一个双向连接)
func (*ClientPool) SendMessage ¶
func (p *ClientPool) SendMessage(route string, data []byte) error
SendMessage 向服务器发送双向消息(使用第一个可用连接)
func (*ClientPool) SetCleanupInterval ¶
func (p *ClientPool) SetCleanupInterval(interval time.Duration)
SetCleanupInterval 设置清理间隔
func (*ClientPool) SetSize ¶
func (p *ClientPool) SetSize(size int)
SetSize 动态调整连接池大小(安全版本)
重要改进: - 不会立即关闭正在使用的连接 - 通过目标大小和清理任务逐步调整 - 只在连接空闲且满足清理条件时才关闭
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn 包装客户端连接
func (*Conn) EnableBidirectional ¶
func (cc *Conn) EnableBidirectional()
EnableBidirectional 启用双向通信模式
func (*Conn) ReceiveMessage ¶
ReceiveMessage 接收服务器推送的消息(非阻塞)
func (*Conn) ReceiveMessageBlocking ¶
ReceiveMessageBlocking 接收服务器推送的消息(阻塞)
Click to show internal directories.
Click to hide internal directories.