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) Write(b []byte) error
- func (c *UdpConnection) Write2Addr(b []byte, ruaddr *net.UDPAddr) error
- type UdpConnectionOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNazaNet = errors.New("nazanet: fxxk")
Functions ¶
This section is empty.
Types ¶
type AvailUdpConnPool ¶ added in v0.19.0
type AvailUdpConnPool struct {
// contains filtered or unexported fields
}
从指定的UDP端口范围内,寻找可绑定监听的端口,绑定监听并返回 Pool只提供Acquire获取接口,不提供释放接口,连接资源是标准*net.UDPConn对象,需要释放时,外部直接Close即可
func NewAvailUdpConnPool ¶ added in v0.19.0
func NewAvailUdpConnPool(minPort uint16, maxPort uint16) *AvailUdpConnPool
func (*AvailUdpConnPool) Acquire ¶ added in v0.19.0
func (a *AvailUdpConnPool) Acquire() (*net.UDPConn, uint16, error)
func (*AvailUdpConnPool) Acquire2 ¶ added in v0.19.0
有的业务场景,需要返回两个可用的端口,并且必须是连续的 @return 前面的是端口小的,后面的是端口+1的
func (*AvailUdpConnPool) Peek ¶ added in v0.19.0
func (a *AvailUdpConnPool) Peek() (uint16, error)
通过Acquire获取到可用net.UDPConn对象后,将对象关闭,只返回可用的端口
type ModUdpConnectionOption ¶ added in v0.19.0
type ModUdpConnectionOption func(option *UdpConnectionOption)
type OnReadUdpPacket ¶ added in v0.19.0
@return 上层回调返回false,则关闭UdpConnection
type UdpConnection ¶ added in v0.19.0
type UdpConnection struct {
// contains filtered or unexported fields
}
func NewUdpConnection ¶ added in v0.19.0
func NewUdpConnection(modOptions ...ModUdpConnectionOption) (*UdpConnection, error)
func (*UdpConnection) Dispose ¶ added in v0.19.0
func (c *UdpConnection) Dispose() error
func (*UdpConnection) ReadWithTimeout ¶ added in v0.19.0
直接读取数据,不使用RunLoop
func (*UdpConnection) RunLoop ¶ added in v0.19.0
func (c *UdpConnection) RunLoop(onRead OnReadUdpPacket) error
阻塞直至Read发生错误或上层回调函数返回false
@return error: 如果外部调用Dispose,会返回error
func (*UdpConnection) Write ¶ added in v0.19.0
func (c *UdpConnection) Write(b []byte) error
func (*UdpConnection) Write2Addr ¶ added in v0.19.0
func (c *UdpConnection) Write2Addr(b []byte, ruaddr *net.UDPAddr) error
type UdpConnectionOption ¶ added in v0.19.0
type UdpConnectionOption struct { // 两种初始化方式: // 方式一:直接传入外部创建好的连接对象供内部使用 Conn *net.UDPConn // 方式二:填入地址,内部创建连接对象 // LAddr: 本地bind地址,如果设置为空,则自动选择可用端口 // 比如作为客户端时,如果不想特别指定本地端口,可以设置为空 // // RAddr: 如果为空,则只能使用func Write2Addr携带对端地址进行发送,不能使用func Write // 不为空的作用:作为客户端时,对端地址通常只有一个,在构造函数中指定,后续就不用每次发送都指定 // 注意,对端地址需显式填写IP // 注意,即使使用方式一,也可以设置Rddr // LAddr string RAddr string MaxReadPacketSize int // 读取数据时,内存块大小 AllocEachRead bool // 使用Read Loop时,是否每次读取都申请新的内存块,如果为false,则复用一块内存块 }
Click to show internal directories.
Click to hide internal directories.