Documentation
¶
Index ¶
- Constants
- func EncodePayLoad(payload Payload) ([]byte, error)
- type BytesPayload
- type Client
- type Link
- func (l *Link) ASend(payload Payload, handler func(Payload)) (err error)
- func (l *Link) AddDataHandler(key string, handler *LinkDataHandler)
- func (l *Link) Close()
- func (l *Link) GetClientID() string
- func (l *Link) GetStatus() StatusType
- func (l *Link) RemoveDataHandler(key string)
- func (l *Link) SSend(payload Payload, timeout time.Duration) (Payload, error)
- func (l *Link) SetClientID(clientID string)
- type LinkDataHandler
- type LinkEventListener
- type Listener
- type Payload
- type StatusType
- type StreamDir
Constants ¶
View Source
const ( WriteInterval = 200 * time.Millisecond KeepAliveTimeout = 60 * time.Minute // 2*time.Minute + 2*time.Second )
Variables ¶
This section is empty.
Functions ¶
func EncodePayLoad ¶
Types ¶
type BytesPayload ¶
type BytesPayload struct {
// contains filtered or unexported fields
}
BytesPayload bytes payload
func (*BytesPayload) Ack ¶
func (b *BytesPayload) Ack(data []byte) Payload
func (*BytesPayload) Bytes ¶
func (b *BytesPayload) Bytes() []byte
func (*BytesPayload) GetPkgIdx ¶
func (b *BytesPayload) GetPkgIdx() uint64
func (*BytesPayload) SetPkgIdx ¶
func (b *BytesPayload) SetPkgIdx(i uint64)
func (*BytesPayload) Size ¶
func (b *BytesPayload) Size() uint32
func (*BytesPayload) Type ¶
func (b *BytesPayload) Type() int8
type Client ¶
type Client struct { Type string // tcp4/udp Address string // listen address sync.Mutex // conneceted 锁 // contains filtered or unexported fields }
func NewLinkClient ¶
func NewLinkClient(clientID, address string, linkEventListener LinkEventListener) *Client
func (*Client) OnStatus ¶
func (c *Client) OnStatus(link *Link, statusType StatusType)
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
func (*Link) AddDataHandler ¶
func (l *Link) AddDataHandler(key string, handler *LinkDataHandler)
AddDataHandler 设置异步数据回调处理接口.
func (*Link) GetClientID ¶
func (*Link) GetStatus ¶
func (l *Link) GetStatus() StatusType
func (*Link) RemoveDataHandler ¶
RemoveDataHandler 设置异步数据回调处理接口.
func (*Link) SetClientID ¶
type LinkDataHandler ¶
type LinkDataHandler struct {
// contains filtered or unexported fields
}
type LinkEventListener ¶
type LinkEventListener interface { // OnStream 数据流 (源, 大小, 方向) OnStream(*Link, Payload, StreamDir) // OnStatus 状态变更(源,状态,附加信息) OnStatus(*Link, StatusType) }
type Listener ¶
type Listener struct { Type string // tcp4/udp Address string // listen address sync.Mutex // connected 锁 // contains filtered or unexported fields }
func NewLinkListener ¶
func NewLinkListener(address string, linkEventListener LinkEventListener) *Listener
func (*Listener) OnStatus ¶
func (l *Listener) OnStatus(link *Link, statusType StatusType)
type Payload ¶
type Payload interface { Size() uint32 Bytes() []byte Type() int8 SetPkgIdx(i uint64) GetPkgIdx() uint64 Ack(data []byte) Payload }
func DecodePayLoad ¶
type StatusType ¶
type StatusType byte
StatusType 状态类型
const ( // StatusInit 初始(Conn已实例化) StatusInit StatusType = iota // StatusError 错误(有异常) StatusError // StatusReady 就绪(可用) StatusReady // StatusClosed 已关闭 StatusClosed )
Click to show internal directories.
Click to hide internal directories.