Documentation ¶
Index ¶
- Variables
- type AvailUdpConnPool
- type ModUdpConnectionOption
- type OnReadUdpPacket
- type UdpConnection
- func (c *UdpConnection) Dispose() error
- func (c *UdpConnection) ReadWithTimeout(timeoutMs int) ([]byte, *net.UDPAddr, error)
- func (c *UdpConnection) RunLoop(onRead OnReadUdpPacket) error
- func (c *UdpConnection) SetReadBuffer(bufSize int) error
- func (c *UdpConnection) SetRemoteAddr(rAddr string) error
- func (c *UdpConnection) SetWriteBuffer(bufSize int) error
- func (c *UdpConnection) Write(b []byte) error
- func (c *UdpConnection) WriteByAddr(b []byte, rAddr *net.UDPAddr) error
- type UdpConnectionOption
Constants ¶
This section is empty.
Variables ¶
var NotAvailablePort = errors.New("AvailUdpConnPool: not available port")
Functions ¶
This section is empty.
Types ¶
type AvailUdpConnPool ¶
type AvailUdpConnPool struct {
// contains filtered or unexported fields
}
AvailUdpConnPool *****************************************************
- @Description: 从指定的UDP端口范围内,寻找可绑定监听的端口,绑定监听并返回
- Pool只提供Acquire获取接口,不提供释放接口,连接资源是标准*net.UDPConn对象,需要释放时,外部直接Close即可 *****************************************************
func NewAvailUdpConnPool ¶
func NewAvailUdpConnPool(host string, startPort uint16, endPort uint16) *AvailUdpConnPool
func (*AvailUdpConnPool) Acquire ¶
func (a *AvailUdpConnPool) Acquire() (*net.UDPConn, uint16, error)
func (*AvailUdpConnPool) Acquire2 ¶
Acquire2 *****************************************************
- @Description: 返回连续的两个端口
- @receiver a
- @return *net.UDPConn
- @return uint16
- @return *net.UDPConn
- @return uint16
- @return error *****************************************************
func (*AvailUdpConnPool) Peek ¶
func (a *AvailUdpConnPool) Peek() (uint16, error)
Peek *****************************************************
- @Description: 通过Acquire获取到可用net.UDPConn对象后,将对象关闭,只返回可用的端口
- @receiver a
- @return uint16
- @return error *****************************************************
type ModUdpConnectionOption ¶
type ModUdpConnectionOption func(option *UdpConnectionOption)
type UdpConnection ¶
type UdpConnection struct {
// contains filtered or unexported fields
}
UdpConnection *****************************************************
- @Description: *****************************************************
func NewUdpConnection ¶
func NewUdpConnection(modOptions ...ModUdpConnectionOption) (*UdpConnection, error)
NewUdpConnection *****************************************************
- @Description: 新建连接节点
- @param modOptions
- @return *UdpConnection
- @return error *****************************************************
func (*UdpConnection) Dispose ¶
func (c *UdpConnection) Dispose() error
Dispose *****************************************************
- @Description: 释放
- @receiver c
- @return error *****************************************************
func (*UdpConnection) ReadWithTimeout ¶
ReadWithTimeout *****************************************************
- @Description: 直接读取数据,不使用RunLoop
- @receiver c
- @param timeoutMs
- @return []byte
- @return *net.UDPAddr
- @return error *****************************************************
func (*UdpConnection) RunLoop ¶
func (c *UdpConnection) RunLoop(onRead OnReadUdpPacket) error
RunLoop *****************************************************
- @Description: 阻塞直至Read发生错误或上层回调函数返回false
- @receiver c
- @param onRead
- @return error 如果外部调用Dispose,会返回error *****************************************************
func (*UdpConnection) SetReadBuffer ¶
func (c *UdpConnection) SetReadBuffer(bufSize int) error
SetReadBuffer *****************************************************
- @Description:
- @receiver c
- @param bufSize
- @return error *****************************************************
func (*UdpConnection) SetRemoteAddr ¶
func (c *UdpConnection) SetRemoteAddr(rAddr string) error
SetRemoteAddr *****************************************************
- @Description:
- @receiver c
- @param rAddr
- @return error *****************************************************
func (*UdpConnection) SetWriteBuffer ¶
func (c *UdpConnection) SetWriteBuffer(bufSize int) error
SetWriteBuffer *****************************************************
- @Description:
- @receiver c
- @param bufSize
- @return error *****************************************************
func (*UdpConnection) Write ¶
func (c *UdpConnection) Write(b []byte) error
Write *****************************************************
- @Description: 发送数据
- @receiver c
- @param b
- @return error *****************************************************
func (*UdpConnection) WriteByAddr ¶
func (c *UdpConnection) WriteByAddr(b []byte, rAddr *net.UDPAddr) error
WriteByAddr *****************************************************
- @Description: 发送数据到指定的addr
- @receiver c
- @param b
- @param ruaddr
- @return error *****************************************************
type UdpConnectionOption ¶
type UdpConnectionOption struct { // Conn /** * @Description: 方式一:直接传入外部创建好的连接对象供内部使用 */ Conn *net.UDPConn // LAddr /** * @Description: 方式二:填入地址,内部创建连接对象, * 本地bind地址,如果设置为空,则自动选择可用端口 * 比如作为客户端时,如果不想特别指定本地端口,可以设置为空 */ LAddr string // RAddr /** * @Description: 对端地址,决定 UdpConnection.Write 函数的发送行为 */ RAddr string // MaxReadPacketSize /** * @Description: 读取数据时,内存块大小 */ MaxReadPacketSize int // AllocEachRead /** * @Description: 使用Read Loop时,是否每次读取都申请新的内存块,如果为false,则复用一块内存块 */ AllocEachRead bool }
UdpConnectionOption *****************************************************
- @Description: *****************************************************