Documentation ¶
Index ¶
- type Buffer
- func (mb *Buffer) Buffered() int
- func (mb *Buffer) Discard(n int) (discarded int, err error)
- func (mb *Buffer) IsEmpty() bool
- func (mb *Buffer) Peek(n int) [][]byte
- func (mb *Buffer) Read(p []byte) (n int, err error)
- func (mb *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (mb *Buffer) Release()
- func (mb *Buffer) Reset(maxStaticBytes int)
- func (mb *Buffer) Write(p []byte) (n int, err error)
- func (mb *Buffer) WriteTo(w io.Writer) (n int64, err error)
- func (mb *Buffer) Writev(bs [][]byte) (int, error)
- type RingBuffer
- func (b *RingBuffer) Available() int
- func (b *RingBuffer) Buffered() int
- func (b *RingBuffer) Bytes() []byte
- func (b *RingBuffer) Cap() int
- func (b *RingBuffer) Discard(n int) (int, error)
- func (b *RingBuffer) Done()
- func (b *RingBuffer) IsEmpty() bool
- func (b *RingBuffer) IsFull() bool
- func (b *RingBuffer) Len() int
- func (b *RingBuffer) Peek(n int) (head []byte, tail []byte)
- func (b *RingBuffer) Read(p []byte) (int, error)
- func (b *RingBuffer) ReadByte() (byte, error)
- func (b *RingBuffer) ReadFrom(r io.Reader) (int64, error)
- func (b *RingBuffer) Reset()
- func (b *RingBuffer) Write(p []byte) (int, error)
- func (b *RingBuffer) WriteByte(c byte) error
- func (b *RingBuffer) WriteString(s string) (int, error)
- func (b *RingBuffer) WriteTo(w io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer combines ring-buffer and list-buffer. Ring-buffer is the top-priority buffer to store response data, gnet will only switch to list-buffer if the data size of ring-buffer reaches the maximum(MaxStackingBytes), list-buffer is more flexible and scalable, which helps the application reduce memory footprint.
func (*Buffer) Buffered ¶
Buffered returns the number of bytes that can be read from the current buffer.
func (*Buffer) Peek ¶
Peek returns n bytes as [][]byte, these bytes won't be discarded until Buffer.Discard() is called.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is the elastic wrapper of ring.Buffer.
func (*RingBuffer) Available ¶
func (b *RingBuffer) Available() int
Available returns the length of available bytes to write.
func (*RingBuffer) Buffered ¶
func (b *RingBuffer) Buffered() int
Buffered returns the length of available bytes to read.
func (*RingBuffer) Bytes ¶
func (b *RingBuffer) Bytes() []byte
Bytes returns all available read bytes. It does not move the read pointer and only copy the available data.
func (*RingBuffer) Cap ¶
func (b *RingBuffer) Cap() int
Cap returns the size of the underlying buffer.
func (*RingBuffer) Discard ¶
func (b *RingBuffer) Discard(n int) (int, error)
Discard skips the next n bytes by advancing the read pointer.
func (*RingBuffer) Done ¶
func (b *RingBuffer) Done()
Done checks and returns the internal ring-buffer to pool.
func (*RingBuffer) IsEmpty ¶
func (b *RingBuffer) IsEmpty() bool
IsEmpty tells if this ring-buffer is empty.
func (*RingBuffer) IsFull ¶
func (b *RingBuffer) IsFull() bool
IsFull tells if this ring-buffer is full.
func (*RingBuffer) Len ¶
func (b *RingBuffer) Len() int
Len returns the length of the underlying buffer.
func (*RingBuffer) Peek ¶
func (b *RingBuffer) Peek(n int) (head []byte, tail []byte)
Peek returns the next n bytes without advancing the read pointer, it returns all bytes when n <= 0.
func (*RingBuffer) Read ¶
func (b *RingBuffer) Read(p []byte) (int, 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 (b *RingBuffer) ReadByte() (byte, error)
ReadByte reads and returns the next byte from the input or ErrIsEmpty.
func (*RingBuffer) ReadFrom ¶
func (b *RingBuffer) ReadFrom(r io.Reader) (int64, error)
ReadFrom implements io.ReaderFrom.
func (*RingBuffer) Reset ¶
func (b *RingBuffer) Reset()
Reset the read pointer and write pointer to zero.
func (*RingBuffer) Write ¶
func (b *RingBuffer) Write(p []byte) (int, 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 (b *RingBuffer) WriteByte(c byte) error
WriteByte writes one byte into buffer.
func (*RingBuffer) WriteString ¶
func (b *RingBuffer) WriteString(s string) (int, error)
WriteString writes the contents of the string s to buffer, which accepts a slice of bytes.