Documentation
¶
Index ¶
- Variables
- type Decoder
- type Encoder
- type Handler
- type LenFieldLen
- type LengthFieldBasedFrameDecoder
- type LengthFieldPrepender
- type SessionManager
- type TCPServer
- type TCPServerConfigurator
- type TCPSession
- func (s *TCPSession) Close() error
- func (s *TCPSession) GetConn() any
- func (s *TCPSession) GetID() uint64
- func (s *TCPSession) GetLocalAddr() string
- func (s *TCPSession) GetRemoteAddr() string
- func (s *TCPSession) GetServer() *TCPServer
- func (s *TCPSession) HandleRead()
- func (s *TCPSession) HandleWrite()
- func (s *TCPSession) Open()
- func (s *TCPSession) Send(picket []byte)
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMessageLenFieldLen = errors.New("invalid `lenFieldLen`")
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
Process(*TCPSession, []byte)
}
type LenFieldLen ¶
type LenFieldLen int
LenFieldLen 消息长度字段的字节长度
const ( LenFieldLenInt8 LenFieldLen = 1 LenFieldLenInt16 LenFieldLen = 2 LenFieldLenInt32 LenFieldLen = 4 )
type LengthFieldBasedFrameDecoder ¶
type LengthFieldBasedFrameDecoder struct {
// contains filtered or unexported fields
}
func NewLengthFieldBasedFrameDecoder ¶
func NewLengthFieldBasedFrameDecoder(lenFieldLen int, maxFrameLen int) (*LengthFieldBasedFrameDecoder, error)
func (*LengthFieldBasedFrameDecoder) Decode ¶
func (d *LengthFieldBasedFrameDecoder) Decode(_ *TCPSession, reader io.Reader) ([]byte, error)
type LengthFieldPrepender ¶
type LengthFieldPrepender struct {
// contains filtered or unexported fields
}
func NewLengthFieldPrepender ¶
func NewLengthFieldPrepender(lenFieldLen int) (*LengthFieldPrepender, error)
func (*LengthFieldPrepender) Encode ¶
func (p *LengthFieldPrepender) Encode(_ *TCPSession, msgData []byte) ([]byte, error)
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func (*SessionManager) Close ¶
func (m *SessionManager) Close()
func (*SessionManager) GetSession ¶
func (m *SessionManager) GetSession(ssid uint64) (*TCPSession, bool)
func (*SessionManager) Init ¶
func (m *SessionManager) Init()
func (*SessionManager) SessionCount ¶
func (m *SessionManager) SessionCount() int64
func (*SessionManager) SessionMap ¶
func (m *SessionManager) SessionMap() map[uint64]*TCPSession
type TCPServer ¶
type TCPServer struct { SessionMgr *SessionManager Encoder func() Encoder Decoder func() Decoder Handler func() Handler OnSessionOpen func(*TCPSession) OnSessionClose func(*TCPSession) // contains filtered or unexported fields }
func NewTCPServer ¶
func NewTCPServer(addr string, config TCPServerConfigurator) *TCPServer
type TCPServerConfigurator ¶
type TCPServerConfigurator struct { NoDelay bool KeepAlive bool KeepAlivePeriodSec int MaxConnectionNum int ReadTimeOutSec int SendBufferSize int }
func DefaultTCPServerConfigurator ¶
func DefaultTCPServerConfigurator() TCPServerConfigurator
type TCPSession ¶
type TCPSession struct { // 读超时时间 ReadTimeOut time.Duration // 业务消息发送缓冲区大小 SendBufferSize int // 自定义属性 Attributes map[string]any // contains filtered or unexported fields }
func NewTCPSession ¶
func NewTCPSession(conn net.Conn, server *TCPServer) *TCPSession
func (*TCPSession) Close ¶
func (s *TCPSession) Close() error
func (*TCPSession) GetConn ¶
func (s *TCPSession) GetConn() any
func (*TCPSession) GetID ¶
func (s *TCPSession) GetID() uint64
func (*TCPSession) GetLocalAddr ¶
func (s *TCPSession) GetLocalAddr() string
func (*TCPSession) GetRemoteAddr ¶
func (s *TCPSession) GetRemoteAddr() string
func (*TCPSession) GetServer ¶
func (s *TCPSession) GetServer() *TCPServer
func (*TCPSession) HandleRead ¶
func (s *TCPSession) HandleRead()
func (*TCPSession) HandleWrite ¶
func (s *TCPSession) HandleWrite()
func (*TCPSession) Open ¶
func (s *TCPSession) Open()
func (*TCPSession) Send ¶
func (s *TCPSession) Send(picket []byte)
Click to show internal directories.
Click to hide internal directories.