Documentation ¶
Overview ¶
Package udp provides a connection-oriented listener over a UDP PacketConn
Index ¶
- Variables
- func Listen(network string, laddr *net.UDPAddr) (net.Listener, error)
- type BatchConn
- type BatchIOConfig
- type BatchPacketConn
- type BatchReader
- type BatchWriter
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(p []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(p []byte) (n int, err error)
- type ListenConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosedListener = errors.New("udp: listener closed") ErrListenQueueExceeded = errors.New("udp: listen queue exceeded") ErrInvalidBatchConfig = errors.New("udp: invalid batch config") )
Typed errors
Functions ¶
Types ¶
type BatchConn ¶ added in v2.2.2
type BatchConn struct { net.PacketConn // contains filtered or unexported fields }
BatchConn uses ipv4/v6.NewPacketConn to wrap a net.PacketConn to write/read messages in batch, only available in linux. In other platform, it will use single Write/Read as same as net.Conn.
func NewBatchConn ¶ added in v2.2.2
func NewBatchConn(conn net.PacketConn, batchWriteSize int, batchWriteInterval time.Duration) *BatchConn
NewBatchConn creates a *BatchConn from net.PacketConn with batch configs.
type BatchIOConfig ¶ added in v2.2.2
type BatchIOConfig struct { Enable bool // ReadBatchSize indicates the maximum number of packets to be read in one batch, a batch size less than 2 means // disable read batch. ReadBatchSize int // WriteBatchSize indicates the maximum number of packets to be written in one batch WriteBatchSize int // WriteBatchInterval indicates the maximum interval to wait before writing packets in one batch // small interval will reduce latency/jitter, but increase the io count. WriteBatchInterval time.Duration }
BatchIOConfig indicates config to batch read/write packets, it will use ReadBatch/WriteBatch to improve throughput for UDP.
type BatchPacketConn ¶ added in v2.2.2
type BatchPacketConn interface { BatchWriter BatchReader io.Closer }
BatchPacketConn represents conn can read/write messages in batch
type BatchReader ¶ added in v2.2.2
BatchReader represents conn can read messages in batch
type BatchWriter ¶ added in v2.2.2
BatchWriter represents conn can write messages in batch
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn augments a connection-oriented connection over a UDP PacketConn
func (*Conn) RemoteAddr ¶
RemoteAddr implements net.Conn.RemoteAddr
func (*Conn) SetDeadline ¶
SetDeadline implements net.Conn.SetDeadline
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements net.Conn.SetDeadline
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.SetDeadline
type ListenConfig ¶
type ListenConfig struct { // Backlog defines the maximum length of the queue of pending // connections. It is equivalent of the backlog argument of // POSIX listen function. // If a connection request arrives when the queue is full, // the request will be silently discarded, unlike TCP. // Set zero to use default value 128 which is same as Linux default. Backlog int // AcceptFilter determines whether the new conn should be made for // the incoming packet. If not set, any packet creates new conn. AcceptFilter func([]byte) bool // ReadBufferSize sets the size of the operating system's // receive buffer associated with the listener. ReadBufferSize int // WriteBufferSize sets the size of the operating system's // send buffer associated with the connection. WriteBufferSize int Batch BatchIOConfig LoggerFactory logging.LoggerFactory }
ListenConfig stores options for listening to an address.