Documentation ¶
Index ¶
- Constants
- Variables
- type RingBuffer
- func (rb *RingBuffer) ByteBuffer() *bbPool.ByteBuffer
- func (rb *RingBuffer) Cap() int
- func (rb *RingBuffer) CopyFromSocket(fd int) (n int, err error)
- func (rb *RingBuffer) Discard(n int)
- func (rb *RingBuffer) Free() int
- func (rb *RingBuffer) IsEmpty() bool
- func (rb *RingBuffer) IsFull() bool
- func (rb *RingBuffer) Len() int
- func (rb *RingBuffer) Length() int
- func (rb *RingBuffer) Peek(n int) (head []byte, tail []byte)
- func (rb *RingBuffer) PeekAll() (head []byte, tail []byte)
- func (rb *RingBuffer) Read(p []byte) (n int, err error)
- func (rb *RingBuffer) ReadByte() (b byte, err error)
- func (rb *RingBuffer) Reset()
- func (rb *RingBuffer) Rewind() (n int)
- func (rb *RingBuffer) WithByteBuffer(b []byte) *bbPool.ByteBuffer
- func (rb *RingBuffer) Write(p []byte) (n int, err error)
- func (rb *RingBuffer) WriteByte(c byte) error
- func (rb *RingBuffer) WriteString(s string) (int, error)
Constants ¶
const ( // DefaultBufferSize is the first-time allocation on a ring-buffer. DefaultBufferSize = 1024 // 1KB )
Variables ¶
var EmptyRingBuffer = New(0)
EmptyRingBuffer can be used as a placeholder for those closed connections.
var ErrIsEmpty = errors.New("ring-buffer is empty")
ErrIsEmpty will be returned when trying to read an empty ring-buffer.
var MaxStreamBufferCap = 64 * 1024 // 64KB
MaxStreamBufferCap is the default buffer size for each stream-oriented connection(TCP/Unix).
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a circular buffer that implement io.ReaderWriter interface.
func New ¶
func New(size int) *RingBuffer
New returns a new RingBuffer whose buffer has the given size.
func (*RingBuffer) ByteBuffer ¶
func (rb *RingBuffer) ByteBuffer() *bbPool.ByteBuffer
ByteBuffer returns all available read bytes. It does not move the read pointer and only copy the available data.
func (*RingBuffer) Cap ¶
func (rb *RingBuffer) Cap() int
Cap returns the size of the underlying buffer.
func (*RingBuffer) CopyFromSocket ¶
func (rb *RingBuffer) CopyFromSocket(fd int) (n int, err error)
CopyFromSocket copies data from a socket fd into ring-buffer.
func (*RingBuffer) Discard ¶
func (rb *RingBuffer) Discard(n int)
Discard skips the next n bytes by advancing the read pointer.
func (*RingBuffer) Free ¶
func (rb *RingBuffer) Free() int
Free returns the length of available bytes to write.
func (*RingBuffer) IsEmpty ¶
func (rb *RingBuffer) IsEmpty() bool
IsEmpty tells if this ring-buffer is empty.
func (*RingBuffer) IsFull ¶
func (rb *RingBuffer) IsFull() bool
IsFull tells if this ring-buffer is full.
func (*RingBuffer) Len ¶
func (rb *RingBuffer) Len() int
Len returns the length of the underlying buffer.
func (*RingBuffer) Length ¶
func (rb *RingBuffer) Length() int
Length returns the length of available bytes to read.
func (*RingBuffer) Peek ¶
func (rb *RingBuffer) Peek(n int) (head []byte, tail []byte)
Peek returns the next n bytes without advancing the read pointer.
func (*RingBuffer) PeekAll ¶
func (rb *RingBuffer) PeekAll() (head []byte, tail []byte)
PeekAll returns all bytes without advancing the read pointer.
func (*RingBuffer) Read ¶
func (rb *RingBuffer) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if Read returns n < len(p), it may use all of p as scratch space during the call. If some data is available but not len(p) bytes, Read conventionally returns what is available instead of waiting for more. When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. Callers should always process the n > 0 bytes returned before considering the error err. Doing so correctly handles I/O errors that happen after reading some bytes and also both of the allowed EOF behaviors.
func (*RingBuffer) ReadByte ¶
func (rb *RingBuffer) ReadByte() (b byte, err error)
ReadByte reads and returns the next byte from the input or ErrIsEmpty.
func (*RingBuffer) Reset ¶
func (rb *RingBuffer) Reset()
Reset the read pointer and write pointer to zero.
func (*RingBuffer) Rewind ¶
func (rb *RingBuffer) Rewind() (n int)
Rewind moves the data from its tail to head and rewind its pointers of read and write.
func (*RingBuffer) WithByteBuffer ¶
func (rb *RingBuffer) WithByteBuffer(b []byte) *bbPool.ByteBuffer
WithByteBuffer combines the available read bytes and the given bytes. It does not move the read pointer and only copy the available data.
func (*RingBuffer) Write ¶
func (rb *RingBuffer) Write(p []byte) (n int, err error)
Write writes len(p) bytes from p to the underlying buf. It returns the number of bytes written from p (n == len(p) > 0) and any error encountered that caused the write to stop early. If the length of p is greater than the writable capacity of this ring-buffer, it will allocate more memory to this ring-buffer. Write must not modify the slice data, even temporarily.
func (*RingBuffer) WriteByte ¶
func (rb *RingBuffer) WriteByte(c byte) error
WriteByte writes one byte into buffer.
func (*RingBuffer) WriteString ¶
func (rb *RingBuffer) WriteString(s string) (int, error)
WriteString writes the contents of the string s to buffer, which accepts a slice of bytes.