Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseWithError(err error) error
- func (c *Conn) Execute(f func()) bool
- func (c *Conn) ExecuteLen() int
- func (c *Conn) Hash() int
- func (c *Conn) IsClosed() (bool, error)
- func (c *Conn) IsTCP() bool
- func (c *Conn) IsUDP() bool
- func (c *Conn) IsUnix() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Lock()
- func (c *Conn) MustExecute(f func())
- func (c *Conn) OnData(h func(conn *Conn, data []byte))
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) ReadAndGetConn(b []byte) (*Conn, int, error)
- func (c *Conn) ReadUDP(b []byte) (*Conn, int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) ResetPollerEvent()
- func (c *Conn) Session() interface{}
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetKeepAlive(keepalive bool) error
- func (c *Conn) SetKeepAlivePeriod(d time.Duration) error
- func (c *Conn) SetLinger(onoff int32, linger int32) error
- func (c *Conn) SetNoDelay(nodelay bool) error
- func (c *Conn) SetReadBuffer(bytes int) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetSession(session interface{})
- func (c *Conn) SetWriteBuffer(bytes int) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Type() ConnType
- func (c *Conn) Unlock()
- func (c *Conn) Write(b []byte) (int, error)
- func (c *Conn) Writev(in [][]byte) (int, error)
- type ConnType
- type Engine
- func (g *Engine) AddConn(conn net.Conn) (*Conn, error)
- func (g *Engine) AfterRead(h func(c *Conn))
- func (g *Engine) BeforeRead(h func(c *Conn))
- func (g *Engine) BeforeWrite(h func(c *Conn))
- func (g *Engine) OnClose(h func(c *Conn, err error))
- func (g *Engine) OnData(h func(c *Conn, data []byte))
- func (g *Engine) OnOpen(h func(c *Conn))
- func (g *Engine) OnRead(h func(c *Conn))
- func (g *Engine) OnReadBufferAlloc(h func(c *Conn) []byte)
- func (g *Engine) OnReadBufferFree(h func(c *Conn, b []byte))
- func (g *Engine) OnStop(h func())
- func (g *Engine) PollerBuffer(c *Conn) []byte
- func (g *Engine) Shutdown(ctx context.Context) error
- func (g *Engine) Start() error
- func (g *Engine) Stop()
- type Gopher
Constants ¶
const ( // DefaultReadBufferSize . DefaultReadBufferSize = 1024 * 64 // DefaultMaxWriteBufferSize . DefaultMaxWriteBufferSize = 1024 * 1024 // DefaultMaxConnReadTimesPerEventLoop . DefaultMaxConnReadTimesPerEventLoop = 3 // DefaultUDPReadTimeout . DefaultUDPReadTimeout = 120 * time.Second )
const ( // EPOLLLT . EPOLLLT = 0 // EPOLLET . EPOLLET = 0x80000000 // EPOLLONESHOT . EPOLLONESHOT = syscall.EPOLLONESHOT )
const ( IPPROTO_TCP = syscall.IPPROTO_TCP TCP_KEEPINTVL = syscall.TCP_KEEPINTVL TCP_KEEPIDLE = syscall.TCP_KEEPIDLE )
Variables ¶
var (
// MaxOpenFiles .
MaxOpenFiles = 1024 * 1024 * 2
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Name string
// Network is the listening protocol, used with Addrs together.
// tcp* supported only by now, there's no plan for other protocol such as udp,
// because it's too easy to write udp server/client.
Network string
// if it is empty, no listener created, then the Engine is used for client by default.
Addrs []string
// NPoller represents poller goroutine num, it's set to runtime.NumCPU() by default.
NPoller int
// ReadBufferSize represents buffer size for reading, it's set to 16k by default.
ReadBufferSize int
// MaxWriteBufferSize represents max write buffer size for Conn, it's set to 1m by default.
MaxWriteBufferSize int
// MaxConnReadTimesPerEventLoop represents max read times in one poller loop for one fd
MaxConnReadTimesPerEventLoop int
// LockListener represents listener's goroutine to lock thread or not, it's set to false by default.
LockListener bool
// LockPoller represents poller's goroutine to lock thread or not, it's set to false by default.
LockPoller bool
// EpollMod sets the epoll mod, EPOLLLT by default.
EpollMod uint32
// EPOLLONESHOT .
EPOLLONESHOT uint32
// UDPReadTimeout sets the timeout for udp sessions.
UDPReadTimeout time.Duration
// TimerExecute sets the executor for timer callbacks.
TimerExecute func(f func())
// Listen is used to create listener for Engine.
Listen func(network, addr string) (net.Listener, error)
// ListenUDP is used to create udp listener for Engine.
ListenUDP func(network string, laddr *net.UDPAddr) (*net.UDPConn, error)
}
Config Of Engine.
type Conn ¶
type Conn struct {
ReadBuffer []byte
DataHandler func(c *Conn, data []byte)
// contains filtered or unexported fields
}
Conn implements net.Conn.
func DialTimeout ¶
DialTimeout wraps net.DialTimeout.
func (*Conn) ReadAndGetConn ¶
ReadAndGetConn .
func (*Conn) ResetPollerEvent ¶
func (c *Conn) ResetPollerEvent()
func (*Conn) SetDeadline ¶
SetDeadline implements SetDeadline.
func (*Conn) SetKeepAlive ¶
SetKeepAlive implements SetKeepAlive.
func (*Conn) SetKeepAlivePeriod ¶
SetKeepAlivePeriod implements SetKeepAlivePeriod.
func (*Conn) SetNoDelay ¶
SetNoDelay implements SetNoDelay.
func (*Conn) SetReadBuffer ¶
SetReadBuffer implements SetReadBuffer.
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements SetReadDeadline.
func (*Conn) SetSession ¶
func (c *Conn) SetSession(session interface{})
SetSession sets user session.
func (*Conn) SetWriteBuffer ¶
SetWriteBuffer implements SetWriteBuffer.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements SetWriteDeadline.
type Engine ¶
type Engine struct {
*timer.Timer
sync.WaitGroup
Name string
Execute func(f func())
TimerExecute func(f func())
// contains filtered or unexported fields
}
Engine is a manager of poller.
func (*Engine) AfterRead ¶
AfterRead registers callback after syscall.Read the handler would be called on *nix.
func (*Engine) BeforeRead ¶
BeforeRead registers callback before syscall.Read the handler would be called on windows.
func (*Engine) BeforeWrite ¶
BeforeWrite registers callback befor syscall.Write and syscall.Writev the handler would be called on windows.
func (*Engine) OnReadBufferAlloc ¶
OnReadBufferAlloc registers callback for memory allocating.
func (*Engine) OnReadBufferFree ¶
OnReadBufferFree registers callback for memory release.
func (*Engine) OnStop ¶
func (g *Engine) OnStop(h func())
OnStop registers callback before Engine is stopped.
func (*Engine) PollerBuffer ¶
PollerBuffer returns Poller's buffer by Conn, can be used on linux/bsd.