Documentation ¶
Index ¶
- func NewSessionReadError(ctx context.Context, err error) *sessionError
- func NewSessionWriteError(ctx context.Context, err error, msg sessionMessage) *sessionError
- type ContentTyper
- type HandleFunc
- type Options
- type Packer
- type Payloader
- type SessionOptions
- type SessionProperty
- type SimpleConnHandle
- type SimpleConnHandleOption
- type TcpConnHandler
- type TcpConnSession
- type TcpConnSessionFactorier
- type TcpConnSessionFactory
- type TcpServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSessionReadError ¶ added in v0.0.9
func NewSessionWriteError ¶ added in v0.0.9
Types ¶
type ContentTyper ¶
type HandleFunc ¶
type Options ¶
type Options func(s *serverOptions)
func WithConnHandle ¶
func WithConnHandle(handle TcpConnHandler) Options
func WithDaemon ¶
func WithDaemon() Options
func WithListenAddr ¶
type Packer ¶
type Packer interface { // Pack(ctx context.Context, rw io.Writer, payload Payloader) error // UnPack(ctx context.Context, r io.Reader) (Payloader, error) Crypto(cryptoer xxcrypto.Cryptoer) }
消息编解码器
type Payloader ¶
type Payloader interface { // 数据类型 Type() ContentTyper // 数据 head Head() []byte // 数据 Payload() []byte // 整个payload的总长度 TotalLen() int64 fmt.Stringer }
编解码包,根据 reader和writer来实现.,网络层面可以实现 使用超时机制控制的,和结束字符控制的,和长度控制的
type SessionOptions ¶
type SessionOptions struct {
// contains filtered or unexported fields
}
type SessionProperty ¶ added in v0.0.9
type SessionProperty struct { RemoteAddr net.Addr SessionId int64 // contains filtered or unexported fields }
func ObtainSession ¶ added in v0.0.9
func ObtainSession(ctx context.Context) *SessionProperty
func (*SessionProperty) Get ¶ added in v0.0.9
func (p *SessionProperty) Get(key string) interface{}
func (*SessionProperty) Put ¶ added in v0.0.9
func (p *SessionProperty) Put(key string, value interface{}) error
type SimpleConnHandle ¶
type SimpleConnHandle struct {
// contains filtered or unexported fields
}
func NewSimpleConnHandle ¶
func NewSimpleConnHandle(opts ...SimpleConnHandleOption) *SimpleConnHandle
func (*SimpleConnHandle) Close ¶
func (sh *SimpleConnHandle) Close() error
func (*SimpleConnHandle) Context ¶
func (sh *SimpleConnHandle) Context(ctx context.Context)
func (*SimpleConnHandle) Valid ¶
func (sh *SimpleConnHandle) Valid() error
type SimpleConnHandleOption ¶
type SimpleConnHandleOption func(opts *simpleConnHandleOptions) error
func WithContext ¶
func WithContext(rootctx context.Context) SimpleConnHandleOption
func WithReadTimeout ¶
func WithReadTimeout(timeout time.Duration) SimpleConnHandleOption
func WithSessionFactory ¶
func WithSessionFactory(factory TcpConnSessionFactorier) SimpleConnHandleOption
func WithWriteTimeout ¶
func WithWriteTimeout(timeout time.Duration) SimpleConnHandleOption
type TcpConnHandler ¶
type TcpConnHandler interface { Valid() error Context(ctx context.Context) // Handle(ctx context.Context, conn *net.TCPConn) error Handle(conn *net.TCPConn) error }
需要是并发安全的.
type TcpConnSession ¶
type TcpConnSessionFactorier ¶
type TcpConnSessionFactorier interface {
CreateSession(conn *net.TCPConn, opts *SessionOptions) TcpConnSession
}
type TcpConnSessionFactory ¶
type TcpConnSessionFactory struct { Pack Packer HandleFunc HandleFunc PushFunc func(ctx context.Context, writeQueue chan<- Payloader) HandleError func(ctx context.Context, err error) (payload Payloader, close bool) // 全局错误处理器,如果返回false,将会关闭该连接,返回true则继续处理该连接的请求 }
func (*TcpConnSessionFactory) CreateSession ¶
func (f *TcpConnSessionFactory) CreateSession(conn *net.TCPConn, opts *SessionOptions) TcpConnSession
type TcpServer ¶
type TcpServer struct {
// contains filtered or unexported fields
}
func (*TcpServer) ListenAddrs ¶ added in v0.0.6
Click to show internal directories.
Click to hide internal directories.