server

package
v0.0.0-...-32ead41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageLenFieldLen = errors.New("invalid `lenFieldLen`")

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(*TCPSession, io.Reader) ([]byte, error)
}

type Encoder

type Encoder interface {
	Encode(*TCPSession, []byte) ([]byte, error)
}

type Handler

type Handler interface {
	Process(*TCPSession, []byte)
}

type LenFieldLen

type LenFieldLen int

LenFieldLen 消息长度字段的字节长度

const (
	LenFieldLenInt8  LenFieldLen = 1
	LenFieldLenInt16 LenFieldLen = 2
	LenFieldLenInt32 LenFieldLen = 4
)

func (LenFieldLen) IsValid

func (t LenFieldLen) IsValid() bool

IsValid 获取消息长度字段的字节长度是否有效

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

func (*TCPServer) Init

func (s *TCPServer) Init()

func (*TCPServer) Start

func (s *TCPServer) Start()

func (*TCPServer) Stop

func (s *TCPServer) Stop()

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL