Documentation ¶
Index ¶
- Constants
- Variables
- func EpollCtl(epfd int, op int, fd int, event *epollevent) (err error)
- func EpollWait(epfd int, events []epollevent, msec int) (n int, err error)
- func GetSysFdPairs() (r, w int)
- func Init(numLoops int)
- func SetKeepAlive(fd, secs int) error
- type CloseCallback
- type Conn
- type EpollEvent
- type EventHandler
- type EventLoop
- type FDConn
- type FDOperator
- type LinkBuffer
- func (b *LinkBuffer) Append(w Writer) (err error)
- func (b *LinkBuffer) Bytes() []byte
- func (b *LinkBuffer) Close() (err error)
- func (b *LinkBuffer) Flush() (err error)
- func (b *LinkBuffer) GetBytes(p [][]byte) (vs [][]byte)
- func (b *LinkBuffer) IsEmpty() (ok bool)
- func (b *LinkBuffer) Len() int
- func (b *LinkBuffer) Malloc(n int) (buf []byte, err error)
- func (b *LinkBuffer) MallocAck(n int) (err error)
- func (b *LinkBuffer) MallocLen() (length int)
- func (b *LinkBuffer) Next(n int) (p []byte, err error)
- func (b *LinkBuffer) Peek(n int) (p []byte, err error)
- func (b *LinkBuffer) ReadBinary(n int) (p []byte, err error)
- func (b *LinkBuffer) ReadByte() (p byte, err error)
- func (b *LinkBuffer) ReadBytes(n int) (p []byte, err error)
- func (b *LinkBuffer) ReadSlice(delim byte) (line []byte, err error)
- func (b *LinkBuffer) ReadString(n int) (s string, err error)
- func (b *LinkBuffer) Release() (err error)
- func (b *LinkBuffer) Skip(n int) (err error)
- func (b *LinkBuffer) Slice(n int) (r Reader, err error)
- func (b *LinkBuffer) Until(delim byte) (line []byte, err error)
- func (b *LinkBuffer) WriteBinary(p []byte) (n int, err error)
- func (b *LinkBuffer) WriteBuffer(buf *LinkBuffer) (err error)
- func (b *LinkBuffer) WriteByte(p byte) (err error)
- func (b *LinkBuffer) WriteBytes(p []byte) (n int, err error)
- func (b *LinkBuffer) WriteDirect(p []byte, remainLen int) error
- func (b *LinkBuffer) WriteString(s string) (n int, err error)
- type Listener
- type LoadBalance
- type OnConnect
- type OnRead
- type Option
- type Poller
- type Reader
- type Writer
Constants ¶
const ( SO_ZEROCOPY = 60 SO_ZEROBLOCKTIMEO = 69 MSG_ZEROCOPY = 0x4000000 )
const BinaryInplaceThreshold = block4k
BinaryInplaceThreshold marks the minimum value of the nocopy slice length, which is the threshold to use copy to minimize overhead.
const EPOLLET = -syscall.EPOLLET
Variables ¶
var LinkBufferCap = block4k
LinkBufferCap that can be modified marks the minimum value of each node of LinkBuffer.
Functions ¶
func GetSysFdPairs ¶
func GetSysFdPairs() (r, w int)
GetSysFdPairs creates and returns the fds of a pair of sockets.
func SetKeepAlive ¶
Types ¶
type CloseCallback ¶
type CloseCallback func(c *connection) error
type EpollEvent ¶
type EpollEvent int8
const ( EpollRead EpollEvent = 0x1 EpollWrite EpollEvent = 0x2 EpollDetach EpollEvent = 0x3 EpollModRead EpollEvent = 0x4 EpollR2RW EpollEvent = 0x5 EpollRW2R EpollEvent = 0x6 )
type EventHandler ¶
type EventLoop ¶
func NewEventLoop ¶
func NewEventLoop(eh EventHandler, opts ...Option) EventLoop
type FDOperator ¶
type FDOperator struct { FD int OnAccept func() error OnHup func(Poller) error // The following is the required fn, which must exist when used, or directly panic. // Fns are only called by the poll when handles connection events. Inputs func(vs [][]byte) (rs [][]byte) InputAck func(n int) (err error) // Outputs will locked if len(rs) > 0, which need unlocked by OutputAck. Outputs func(vs [][]byte) (rs [][]byte, supportZeroCopy bool) OutputAck func(n int) (err error) // contains filtered or unexported fields }
func (*FDOperator) Control ¶
func (o *FDOperator) Control(event EpollEvent) error
type LinkBuffer ¶
type LinkBuffer struct {
// contains filtered or unexported fields
}
LinkBuffer implements ReadWriter.
func NewLinkBuffer ¶
func NewLinkBuffer(size ...int) *LinkBuffer
NewLinkBuffer size defines the initial capacity, but there is no readable data.
func (*LinkBuffer) Append ¶
func (b *LinkBuffer) Append(w Writer) (err error)
Append implements Writer.
func (*LinkBuffer) Bytes ¶
func (b *LinkBuffer) Bytes() []byte
Bytes returns all the readable bytes of this LinkBuffer.
func (*LinkBuffer) Flush ¶
func (b *LinkBuffer) Flush() (err error)
Flush will submit all malloc data and must confirm that the allocated bytes have been correctly assigned.
func (*LinkBuffer) GetBytes ¶
func (b *LinkBuffer) GetBytes(p [][]byte) (vs [][]byte)
GetBytes will read and fill the slice p as much as possible.
func (*LinkBuffer) IsEmpty ¶
func (b *LinkBuffer) IsEmpty() (ok bool)
IsEmpty check if this LinkBuffer is empty.
func (*LinkBuffer) Malloc ¶
func (b *LinkBuffer) Malloc(n int) (buf []byte, err error)
Malloc pre-allocates memory, which is not readable, and becomes readable data after submission(e.g. Flush).
func (*LinkBuffer) MallocAck ¶
func (b *LinkBuffer) MallocAck(n int) (err error)
MallocAck will keep the first n malloc bytes and discard the rest.
func (*LinkBuffer) MallocLen ¶
func (b *LinkBuffer) MallocLen() (length int)
MallocLen implements Writer.
func (*LinkBuffer) Next ¶
func (b *LinkBuffer) Next(n int) (p []byte, err error)
Next implements Reader.
func (*LinkBuffer) Peek ¶
func (b *LinkBuffer) Peek(n int) (p []byte, err error)
Peek does not have an independent lifecycle, and there is no signal to indicate that Peek content can be released, so Peek will not introduce mcache for now.
func (*LinkBuffer) ReadBinary ¶
func (b *LinkBuffer) ReadBinary(n int) (p []byte, err error)
ReadBinary implements Reader.
func (*LinkBuffer) ReadByte ¶
func (b *LinkBuffer) ReadByte() (p byte, err error)
ReadByte implements Reader.
func (*LinkBuffer) ReadString ¶
func (b *LinkBuffer) ReadString(n int) (s string, err error)
ReadString implements Reader.
func (*LinkBuffer) Release ¶
func (b *LinkBuffer) Release() (err error)
Release the node that has been read. b.flush == nil indicates that this LinkBuffer is created by LinkBuffer.Slice
func (*LinkBuffer) Slice ¶
func (b *LinkBuffer) Slice(n int) (r Reader, err error)
Slice returns a new LinkBuffer, which is a zero-copy slice of this LinkBuffer, and only holds the ability of Reader.
Slice will automatically execute a Release.
func (*LinkBuffer) Until ¶
func (b *LinkBuffer) Until(delim byte) (line []byte, err error)
Until returns a slice ends with the delim in the buffer.
func (*LinkBuffer) WriteBinary ¶
func (b *LinkBuffer) WriteBinary(p []byte) (n int, err error)
WriteBinary implements Writer.
func (*LinkBuffer) WriteBuffer ¶
func (b *LinkBuffer) WriteBuffer(buf *LinkBuffer) (err error)
WriteBuffer will not submit(e.g. Flush) data to ensure normal use of MallocLen. you must actively submit before read the data. The argument buf can't be used after calling WriteBuffer. (set it to nil)
func (*LinkBuffer) WriteByte ¶
func (b *LinkBuffer) WriteByte(p byte) (err error)
WriteByte implements Writer.
func (*LinkBuffer) WriteBytes ¶
func (b *LinkBuffer) WriteBytes(p []byte) (n int, err error)
func (*LinkBuffer) WriteDirect ¶
func (b *LinkBuffer) WriteDirect(p []byte, remainLen int) error
WriteDirect cannot be mixed with WriteString or WriteBinary functions.
func (*LinkBuffer) WriteString ¶
func (b *LinkBuffer) WriteString(s string) (n int, err error)
WriteString implements Writer.
type Poller ¶
type Poller interface { Poll() error Close() error Control(operator *FDOperator, event EpollEvent) error }
type Reader ¶
type Reader interface { Next(n int) (p []byte, err error) Peek(n int) (buf []byte, err error) Skip(n int) (err error) ReadSlice(delim byte) (line []byte, err error) ReadString(n int) (s string, err error) ReadBytes(n int) (p []byte, err error) ReadByte() (b byte, err error) Slice(n int) (r Reader, err error) Release() (err error) Len() (length int) }
type Writer ¶
type Writer interface { Malloc(n int) (buf []byte, err error) WriteString(s string) (n int, err error) WriteBytes(b []byte) (n int, err error) WriteByte(b byte) (err error) WriteDirect(p []byte, remainCap int) error MallocAck(n int) (err error) Append(w Writer) (err error) Flush() (err error) MallocLen() (length int) }
Source Files ¶
- connection.go
- connection_lock.go
- connection_onevent.go
- event_handler.go
- event_loop.go
- fd_operator.go
- fd_operator_cache.go
- init.go
- listener.go
- net_fd.go
- net_polldesc.go
- nocopy.go
- nocopy_linkbuffer.go
- options.go
- poller.go
- poller_loadbalancer.go
- poller_manager.go
- server.go
- sock.go
- sys_epoll.go
- sys_exec.go
- sys_keepalive.go
- sys_sendmsg.go
- sys_zerocopy.go