Documentation
¶
Index ¶
- Variables
- type AppOption
- func WithAppHandleSessionFunc(value func(IOSession) error) AppOption
- func WithAppLogger(logger *zap.Logger) AppOption
- func WithAppSessionAware(value IOSessionAware) AppOption
- func WithAppSessionBucketSize(value uint64) AppOption
- func WithAppSessionOptions(options ...Option) AppOption
- func WithAppTLS(tlsCfg *tls.Config) AppOption
- func WithAppTLSFromCertAndKey(certFile string, keyFile string, caFile string, insecureSkipVerify bool) AppOption
- type BufferedIOSession
- type IOSession
- type IOSessionAware
- type NetApplication
- func NewApplication(address string, handleFunc func(IOSession, any, uint64) error, ...) (NetApplication, error)
- func NewApplicationWithListenAddress(addresses []string, handleFunc func(IOSession, any, uint64) error, ...) (NetApplication, error)
- func NewApplicationWithListeners(listeners []net.Listener, handleFunc func(IOSession, any, uint64) error, ...) (NetApplication, error)
- type Option
- func WithSessionAllocator(allocator buf.Allocator) Option
- func WithSessionAware(value IOSessionAware) Option
- func WithSessionCodec(codec codec.Codec) Option
- func WithSessionConn(id uint64, conn net.Conn) Option
- func WithSessionDisableAutoResetInBuffer() Option
- func WithSessionDisableCompactAfterGrow() Option
- func WithSessionLogger(logger *zap.Logger) Option
- func WithSessionRWBUfferSize(read, write int) Option
- func WithSessionReleaseMsgFunc(value func(any)) Option
- func WithSessionTLS(tlsConfig *tls.Config) Option
- func WithSessionTLSFromCertAndKeys(certFile, keyFile, caFile string, insecureSkipVerify bool) Option
- type Proxy
- type ReadOptions
- type WriteOptions
Constants ¶
This section is empty.
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 ¶
type AppOption func(*server)
AppOption application option
func WithAppHandleSessionFunc ¶
WithAppHandleSessionFunc set the app handle session funcpl
func WithAppLogger ¶
WithAppLogger set logger for application
func WithAppSessionAware ¶
func WithAppSessionAware(value IOSessionAware) AppOption
WithAppSessionBucketSize set the app session aware
func WithAppSessionBucketSize ¶
WithAppSessionBucketSize set the number of maps to store session
func WithAppSessionOptions ¶
WithAppSessionOptions set options to create new connection
func WithAppTLS ¶
WithAppTLS set tls config for application
type BufferedIOSession ¶
type BufferedIOSession interface { // BufferedConn returns a wrapped net.Conn that read from IOSession's in-buffer first BufferedConn() net.Conn // InBuf returns inbuf which used to decode bytes to message InBuf() *buf.ByteBuf }
BufferedIOSession is a IOSession that can read from the in-buffer first
type IOSession ¶
type IOSession interface { // ID session id ID() uint64 // Connect connect to address, only used at client-side Connect(addr string, timeout time.Duration) error // Connected returns true if connection is ok Connected() bool // Disconnect disconnect the connection Disconnect() error // Close close the session, the read and write buffer will closed, and cannot Connect // again. IOSession reference count minus 1. Close() error // Ref for IOSessions, held by several goroutines, several references are needed. Each // concurrent process holding an IOSession can Close the IOSession and release the resource // when the reference count reaches 0. Ref() // Read read packet from connection Read(option ReadOptions) (any, error) // Write encodes the msg into a []byte into the buffer according to the codec.Encode. // If flush is set to flase, the data will not be written to the underlying socket. Write(msg any, options WriteOptions) error // Flush flush the out buffer Flush(timeout time.Duration) error // RemoteAddress returns remote address, include ip and port RemoteAddress() string // RawConn return raw tcp conn, RawConn should only be used to access the underlying // attributes of the tcp conn, e.g. set keepalive attributes. Read from RawConn directly // may lose data since the bytes might have been copied to the InBuf. // To perform read/write operation on the underlying tcp conn, use BufferedConn instead. RawConn() net.Conn // UseConn use the specified conn to handle reads and writes. Note that conn reads and // writes cannot be handled in other goroutines until UseConn is called. UseConn(net.Conn) // OutBuf returns bytebuf which used to encode message into bytes OutBuf() *buf.ByteBuf }
IOSession internally holds a raw net.Conn on which to provide read and write operations
func NewIOSession ¶
NewIOSession create a new io session
type IOSessionAware ¶
type IOSessionAware interface { // Created session created Created(IOSession) //Closed session closed Closed(IOSession) }
IOSessionAware io session aware
type NetApplication ¶
type NetApplication interface { // Start start the transport server Start() error // Stop stop the transport server Stop() error // GetSession get session GetSession(uint64) (IOSession, error) }
NetApplication is a network based application
func NewApplication ¶
func NewApplication(address string, handleFunc func(IOSession, any, uint64) error, opts ...AppOption) (NetApplication, error)
NewApplication returns a application
func NewApplicationWithListenAddress ¶
func NewApplicationWithListenAddress(addresses []string, handleFunc func(IOSession, any, uint64) error, opts ...AppOption) (NetApplication, error)
NewApplicationWithListenAddress create a net application with listen multi addresses
type Option ¶
type Option func(*baseIO)
Option option to create IOSession
func WithSessionAllocator ¶
WithSessionAllocator set mem allocator to build in and out ByteBuf
func WithSessionAware ¶
func WithSessionAware(value IOSessionAware) Option
WithSessionAware set IOSession's session aware
func WithSessionCodec ¶
WithSessionCodec set codec for IOSession
func WithSessionConn ¶
WithSessionConn set IOSession's net.Conn
func WithSessionDisableAutoResetInBuffer ¶
func WithSessionDisableAutoResetInBuffer() Option
WithSessionDisableAutoResetInBuffer set disable auto reset in buffer. If disabled, the application must reset in buffer in the read loop, otherwise there will be a memory leak.
func WithSessionDisableCompactAfterGrow ¶
func WithSessionDisableCompactAfterGrow() Option
WithSessionDisableCompactAfterGrow set Set whether the buffer should be compressed, if it is, it will reset the reader and writer index. Default is true.
func WithSessionLogger ¶
WithSessionLogger set logger for IOSession
func WithSessionRWBUfferSize ¶
WithSessionRWBUfferSize set read/write buf size for IOSession
func WithSessionReleaseMsgFunc ¶
WithSessionReleaseMsgFunc set a func to release message once the message encode into the write buf
func WithSessionTLS ¶
WithSessionTLS set tls for client
func WithSessionTLSFromCertAndKeys ¶
func WithSessionTLSFromCertAndKeys(certFile, keyFile, caFile string, insecureSkipVerify bool) Option
WithSessionTLSFromCertAndKeys set tls for client
type Proxy ¶
type Proxy interface { // Start start the proxy Start() error // Stop stop the proxy Stop() error // AddUpStream add upstream AddUpStream(address string, connectTimeout time.Duration) }
Proxy simple reverse proxy
type ReadOptions ¶
ReadOptions read options
type WriteOptions ¶
type WriteOptions struct { // Timeout deadline for write Timeout time.Duration // Flush flush data to net.Conn Flush bool }
WriteOptions write options