Documentation
¶
Index ¶
- Constants
- Variables
- type AppOption
- func WithAppErrorMsgFactory(value func(IOSession, interface{}, error) interface{}) AppOption
- func WithAppLogger(logger *zap.Logger) AppOption
- func WithAppSessionAware(aware IOSessionAware) AppOption
- func WithAppSessionBucketSize(value uint64) AppOption
- func WithAppSessionOptions(value ...Option) AppOption
- type IOSession
- type IOSessionAware
- type NetApplication
- type Option
- func WithBufSize(read, write int) Option
- func WithCodec(encoder codec.Encoder, decoder codec.Decoder) Option
- func WithConnOptionFunc(connOptionFunc func(net.Conn)) Option
- func WithEnableAsyncWrite(asyncFlushBatch int64) Option
- func WithLogger(value *zap.Logger) Option
- func WithReleaseMsgFunc(value func(interface{})) Option
- func WithTimeout(read, write time.Duration) Option
Constants ¶
const ( // DefaultSessionBucketSize default bucket size of session map DefaultSessionBucketSize = uint64(64) // DefaultReadBuf read buf size DefaultReadBuf = 256 // DefaultWriteBuf write buf size DefaultWriteBuf = 256 )
Variables ¶
var ( // ErrIllegalState illegal state error ErrIllegalState = errors.New("illegal state") // ErrDisableConnect disable to connect ErrDisableConnect = errors.New("io session is disable to connect") )
Functions ¶
This section is empty.
Types ¶
type AppOption ¶ added in v1.8.0
type AppOption func(*appOptions)
AppOption application option
func WithAppErrorMsgFactory ¶ added in v1.8.0
WithAppErrorMsgFactory set function to process error, closed the client session if this field not set
func WithAppLogger ¶ added in v1.11.2
WithAppLogger set logger for application
func WithAppSessionAware ¶ added in v1.10.0
func WithAppSessionAware(aware IOSessionAware) AppOption
WithAppSessionBucketSize set the app session aware
func WithAppSessionBucketSize ¶ added in v1.8.0
WithAppSessionBucketSize set the number of maps to store session
func WithAppSessionOptions ¶ added in v1.8.0
WithAppSessionOptions set the number of maps to store session
type IOSession ¶
type IOSession interface {
// ID sessino id
ID() uint64
// Connect connect to address, only used at client-side
Connect(addr string, timeout time.Duration) (bool, error)
// Close close the session
Close() error
// Connected returns true if connection is ok
Connected() bool
// Read read packet from connection
Read() (interface{}, error)
// Write write packet to connection out buffer
Write(msg interface{}) error
// WriteAndFlush write packet to connection out buffer and flush the out buffer
WriteAndFlush(msg interface{}) error
// Flush flush the out buffer
Flush() error
// InBuf connection read buffer
InBuf() *buf.ByteBuf
// OutBuf connection out buffer
OutBuf() *buf.ByteBuf
// SetAttr set attr
SetAttr(key string, value interface{})
// GetAttr read attr
GetAttr(key string) interface{}
// RemoteAddr returns remote address, include ip and port
RemoteAddr() string
// RemoteIP returns remote address, only ip
RemoteIP() string
// RawConn returns the raw connection
RawConn() (net.Conn, error)
}
IOSession session
func NewIOSession ¶ added in v1.8.0
NewIOSession create a new io session
type IOSessionAware ¶ added in v1.10.0
type IOSessionAware interface {
// Created session created
Created(IOSession)
//Closed session closed
Closed(IOSession)
}
IOSessionAware io session aware
type NetApplication ¶ added in v1.8.0
type NetApplication interface {
// Start start the transport server
Start() error
// Stop stop the transport server
Stop() error
// GetSession get session
GetSession(uint64) (IOSession, error)
// Broadcast broadcast msg to all sessions
Broadcast(msg interface{}) error
}
NetApplication is a network based application
func NewApplication ¶ added in v1.8.0
func NewApplication(address string, handleFunc func(IOSession, interface{}, uint64) error, opts ...AppOption) (NetApplication, error)
NewApplication returns a application
func NewApplicationWithListener ¶ added in v1.14.0
func NewApplicationWithListener(listener net.Listener, handleFunc func(IOSession, interface{}, uint64) error, opts ...AppOption) (NetApplication, error)
NewApplicationWithListener returns a net application with listener
type Option ¶ added in v1.0.0
type Option func(*options)
Option transport option
func WithBufSize ¶ added in v1.8.0
WithBufSize set read/write buf size
func WithConnOptionFunc ¶ added in v1.8.0
WithConnOptionFunc set conn options func
func WithEnableAsyncWrite ¶ added in v1.8.0
WithEnableAsyncWrite enable async write
func WithReleaseMsgFunc ¶ added in v1.8.0
func WithReleaseMsgFunc(value func(interface{})) Option
WithReleaseMsgFunc set the number of maps to store session
func WithTimeout ¶ added in v1.8.0
WithTimeout set read/write timeout