Documentation ¶
Overview ¶
Package packetio provides packet buffer
Index ¶
- Variables
- type Buffer
- func (b *Buffer) Close() (err error)
- func (b *Buffer) Count() int
- func (b *Buffer) Read(packet []byte) (n int, err error)
- func (b *Buffer) SetLimitCount(limit int)
- func (b *Buffer) SetLimitSize(limit int)
- func (b *Buffer) SetReadDeadline(t time.Time) error
- func (b *Buffer) Size() int
- func (b *Buffer) Write(packet []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ErrFull = errors.New("packetio.Buffer is full, discarding write")
ErrFull is returned when the buffer has hit the configured limits.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer allows writing packets to an intermediate buffer, which can then be read form. This is verify similar to bytes.Buffer but avoids combining multiple writes into a single read.
func (*Buffer) Close ¶
Close the buffer, unblocking any pending reads. Data in the buffer can still be read, Read will return io.EOF only when empty.
func (*Buffer) Read ¶
Read populates the given byte slice, returning the number of bytes read. Blocks until data is available or the buffer is closed. Returns io.ErrShortBuffer is the packet is too small to copy the Write. Returns io.EOF if the buffer is closed.
func (*Buffer) SetLimitCount ¶
SetLimitCount controls the maximum number of packets that can be buffered. Causes Write to return ErrFull when this limit is reached. A zero value will disable this limit.
func (*Buffer) SetLimitSize ¶
SetLimitSize controls the maximum number of bytes that can be buffered. Causes Write to return ErrFull when this limit is reached. A zero value means 4MB since v0.11.0.
User can set packetioSizeHardlimit build tag to enable 4MB hardlimit. When packetioSizeHardlimit build tag is set, SetLimitSize exceeding the hardlimit will be silently discarded.
func (*Buffer) SetReadDeadline ¶ added in v0.10.0
SetReadDeadline sets the deadline for the Read operation. Setting to zero means no deadline.