Documentation ¶
Index ¶
- Constants
- Variables
- type BuiltInFrameCodec
- type Config
- type Conn
- func (c *Conn) Cache() *[]byte
- func (c *Conn) Close() error
- func (c *Conn) CloseWithError(err error) error
- func (c *Conn) Execute(f func())
- func (c *Conn) ExecuteLen() int
- func (c *Conn) Hash() int
- func (c *Conn) IsClosed() (bool, error)
- 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) RemoteAddr() net.Addr
- func (c *Conn) Session() interface{}
- func (c *Conn) SetCodec(codec ICodec)
- 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) Unlock()
- func (c *Conn) Write(b []byte) (int, error)
- func (c *Conn) Writev(in [][]byte) (int, error)
- type DecoderConfig
- type DelimiterBasedFrameCodec
- type EncoderConfig
- type FixedLengthFrameCodec
- type Gopher
- func (g *Gopher) AddConn(conn net.Conn) (*Conn, error)
- func (g *Gopher) After(timeout time.Duration) <-chan time.Time
- func (g *Gopher) AfterFunc(timeout time.Duration, f func()) *Timer
- func (g *Gopher) AfterRead(h func(c *Conn))
- func (g *Gopher) BeforeRead(h func(c *Conn))
- func (g *Gopher) BeforeWrite(h func(c *Conn))
- func (g *Gopher) OnClose(h func(c *Conn, err error))
- func (g *Gopher) OnData(h func(c *Conn, data []byte))
- func (g *Gopher) OnOpen(h func(c *Conn))
- func (g *Gopher) OnRead(h func(c *Conn))
- func (g *Gopher) OnReadBufferAlloc(h func(c *Conn) []byte)
- func (g *Gopher) OnReadBufferFree(h func(c *Conn, b []byte))
- func (g *Gopher) OnStop(h func())
- func (g *Gopher) OnWriteBufferRelease(h func(c *Conn, b []byte))
- func (g *Gopher) PollerBuffer(c *Conn) []byte
- func (g *Gopher) Start() error
- func (g *Gopher) Stop()
- type ICodec
- type LengthFieldBasedFrameCodec
- type LineBasedFrameCodec
- type Timer
Constants ¶
const ( // DefaultReadBufferSize . DefaultReadBufferSize = 1024 * 32 // DefaultMaxWriteBufferSize . DefaultMaxWriteBufferSize = 1024 * 1024 // DefaultMaxReadTimesPerEventLoop . DefaultMaxReadTimesPerEventLoop = 3 // DefaultMinConnCacheSize . DefaultMinConnCacheSize = 1024 * 2 )
const ( // EPOLLLT . EPOLLLT = 0 // EPOLLET . EPOLLET = 0x80000000 )
Variables ¶
var CRLFByte = byte('\n')
CRLFByte represents a byte of CRLF.
var (
// MaxOpenFiles .
MaxOpenFiles = 1024 * 1024
)
Functions ¶
This section is empty.
Types ¶
type BuiltInFrameCodec ¶ added in v0.0.4
type BuiltInFrameCodec struct { }
BuiltInFrameCodec is the built-in codec which will be assigned to gnet server when customized codec is not set up.
type Config ¶
type Config struct { // Name describes your gopher name for logging, it's set to "NB" by default. Name string // Network is the listening protocol, used with Addrs toghter. // 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 // Addrs is the listening addr list for a easyNet server. // if it is empty, no listener created, then the Gopher is used for client by default. Addrs []string // NPoller represents poller goroutine num, it's set to runtime.NumCPU() by default. NPoller int // NListener represents poller goroutine num, it's set to runtime.NumCPU() by default. NListener int // Backlog represents backlog arg for syscall.Listen Backlog int // ReadBufferSize represents buffer size for reading, it's set to 16k by default. ReadBufferSize int // MinConnCacheSize represents application layer's Conn write cache buffer size when the kernel sendQ is full MinConnCacheSize int // MaxWriteBufferSize represents max write buffer size for Conn, it's set to 1m by default. // if the connection's Send-Q is full and the data cached by easyNet is // more than MaxWriteBufferSize, the connection would be closed by easyNet. MaxWriteBufferSize int // MaxReadTimesPerEventLoop represents max read times in one poller loop for one fd MaxReadTimesPerEventLoop 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 int }
Config Of Gopher.
type Conn ¶
type Conn struct { ReadBuffer []byte CacheBuffer []byte DataHandler func(c *Conn, data []byte) // contains filtered or unexported fields }
Conn implements net.Conn.
func DialTimeout ¶ added in v0.0.3
DialTimeout wraps net.DialTimeout.
func (*Conn) CloseWithError ¶ added in v0.0.3
CloseWithError .
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 DecoderConfig ¶ added in v0.0.4
type DecoderConfig struct { // ByteOrder is the ByteOrder of the length field. ByteOrder binary.ByteOrder // LengthFieldOffset is the offset of the length field LengthFieldOffset int // LengthFieldLength is the length of the length field LengthFieldLength int // LengthAdjustment is the compensation value to add to the value of the length field LengthAdjustment int // InitialBytesToStrip is the number of first bytes to strip out from the decoded frame InitialBytesToStrip int }
DecoderConfig config for decoder.
type DelimiterBasedFrameCodec ¶ added in v0.0.4
type DelimiterBasedFrameCodec struct {
// contains filtered or unexported fields
}
DelimiterBasedFrameCodec encodes/decodes specific-delimiter-separated frames into/from TCP stream.
type EncoderConfig ¶ added in v0.0.4
type EncoderConfig struct { // ByteOrder is the ByteOrder of the length field. ByteOrder binary.ByteOrder // LengthFieldLength is the length of the length field. LengthFieldLength int // LengthAdjustment is the compensation value to add to the value of the length field LengthAdjustment int // LengthIncludesLengthFieldLength is true, the length of the prepended length field is added to the value of // the prepended length field LengthIncludesLengthFieldLength bool }
type FixedLengthFrameCodec ¶ added in v0.0.4
type FixedLengthFrameCodec struct {
// contains filtered or unexported fields
}
FixedLengthFrameCodec encodes/decodes fixed-length-separated frames into/from TCP stream.
func NewFixedLengthFrameCodec ¶ added in v0.0.4
func NewFixedLengthFrameCodec(frameLength int) *FixedLengthFrameCodec
NewFixedLengthFrameCodec instantiates and returns a codec with fixed length.
type Gopher ¶
type Gopher struct { sync.WaitGroup Name string Execute func(f func()) // contains filtered or unexported fields }
Gopher is a manager of poller.
func (*Gopher) AfterRead ¶
AfterRead registers callback after syscall.Read the handler would be called only on *nix.
func (*Gopher) BeforeRead ¶
BeforeRead registers callback before syscall.Read the handler would be called only on windows.
func (*Gopher) BeforeWrite ¶
BeforeWrite registers callback befor syscall.Write and syscall.Writev
func (*Gopher) OnReadBufferAlloc ¶ added in v0.0.3
OnReadBufferAlloc registers callback for memory allocating.
func (*Gopher) OnReadBufferFree ¶ added in v0.0.3
OnReadBufferFree registers callback for memory release.
func (*Gopher) OnStop ¶ added in v0.0.3
func (g *Gopher) OnStop(h func())
OnStop registers callback before Gopher is stopped.
func (*Gopher) OnWriteBufferRelease ¶ added in v0.0.3
OnWriteBufferRelease registers callback for write buffer memory release.
func (*Gopher) PollerBuffer ¶
PollerBuffer returns Poller's buffer by Conn, can be used on linux/bsd.
type LengthFieldBasedFrameCodec ¶ added in v0.0.4
type LengthFieldBasedFrameCodec struct {
// contains filtered or unexported fields
}
LengthFieldBasedFrameCodec is the refactoring from https://github.com/smallnest/goframe/blob/master/length_field_based_frameconn.go, licensed by Apache License 2.0. It encodes/decodes frames into/from TCP stream with value of the length field in the message.
func NewLengthFieldBasedFrameCodec ¶ added in v0.0.4
func NewLengthFieldBasedFrameCodec(ec EncoderConfig, dc DecoderConfig) *LengthFieldBasedFrameCodec
type LineBasedFrameCodec ¶ added in v0.0.4
type LineBasedFrameCodec struct { }
LineBasedFrameCodec encodes/decodes line-separated frames into/from TCP stream.