network

package
v1.1.18 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const STREAM_HEADLEN = 4

Variables

View Source
var ErrRecvLen = errors.New("data is too long")
View Source
var GenNetSessionId = _gen_net_session_id()

Functions

func Byte4ToUint32

func Byte4ToUint32(data []byte) (result uint32)

func CombineMsgWithId

func CombineMsgWithId(msgId int32, data []byte) []byte

func Uint32ToByte4

func Uint32ToByte4(data uint32) (result []byte)

Types

type EchoCodec

type EchoCodec struct {
	MaxDecode int
	// contains filtered or unexported fields
}

func (*EchoCodec) Decode

func (s *EchoCodec) Decode(data []byte) ([][]byte, error)

func (*EchoCodec) Encode

func (s *EchoCodec) Encode(data []byte) []byte

func (*EchoCodec) MaxDec

func (s *EchoCodec) MaxDec() int

type ICodec

type ICodec interface {
	Decode([]byte) ([][]byte, error)
	Encode(data []byte) []byte
	MaxDec() int
}

type INetClient

type INetClient interface {
	SendMsg([]byte) error
	AddLast(hander func() INetHandler)
	Start(reconect bool) error
	Stop()
}

func NewTcpClient

func NewTcpClient(addr string, newCodec func() ICodec, op ...OptionClient) INetClient

type INetHandler

type INetHandler interface {
	OnSessionCreated(INetSession)
	OnSessionClosed()
	OnRecv([]byte)
}

type INetListener

type INetListener interface {
	Start() error
	Stop()
}

func StartTcpListen

func StartTcpListen(addr string, newCodec func() ICodec, newHanlder func() INetHandler, op ...OptionListen) INetListener

type INetSession

type INetSession interface {
	Id() uint32
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	RemoteIP() string
	SendMsg([]byte) error
	Stop()
	StoreKV(interface{}, interface{})
	DeleteKV(interface{})
	Load(interface{}) (interface{}, bool)
	Type() SessionType
}

type Message

type Message struct {
	// contains filtered or unexported fields
}

func NewBytesMessageParse

func NewBytesMessageParse(data []byte, mm *tools.ProtoParser) *Message

远端actor通信主要使用接口

func NewPbMessage

func NewPbMessage(pb proto.Message, msgId int32) *Message

业务逻辑层主要使用接口

func (*Message) Buffer

func (s *Message) Buffer() []byte

func (*Message) MsgId

func (s *Message) MsgId() int32

func (*Message) Proto

func (s *Message) Proto() proto.Message

type OptionClient

type OptionClient func(l *TcpClient)

type OptionListen

type OptionListen func(l *TcpListener)

type SessionType

type SessionType int
const (
	TYPE_TCP SessionType = 1
	TYPE_UDP SessionType = 2
	TYPE_WS  SessionType = 3
)

type StreamCodec

type StreamCodec struct {
	MaxDecode int
	// contains filtered or unexported fields
}
	├──── 4bytes ─────┼────────────── body size ─────────────────┤
	┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
	┃ head(body size) ┃               body (data)                ┃
	┗━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    ├──────────── MAX Size:StreamCodec.MaxDecode ────────────────┤

func (*StreamCodec) Decode

func (s *StreamCodec) Decode(data []byte) ([][]byte, error)

func (*StreamCodec) Encode

func (s *StreamCodec) Encode(data []byte) []byte

func (*StreamCodec) MaxDec

func (s *StreamCodec) MaxDec() int

type TcpClient

type TcpClient struct {
	// contains filtered or unexported fields
}

func (*TcpClient) AddLast

func (s *TcpClient) AddLast(hander func() INetHandler)

add handler to last of list

func (*TcpClient) SendMsg

func (s *TcpClient) SendMsg(data []byte) error

func (*TcpClient) Start

func (s *TcpClient) Start(reconnect bool) error

func (*TcpClient) Stop

func (s *TcpClient) Stop()

type TcpListener

type TcpListener struct {
	// contains filtered or unexported fields
}

func (*TcpListener) Start

func (s *TcpListener) Start() error

func (*TcpListener) Stop

func (s *TcpListener) Stop()

type TcpSession

type TcpSession struct {
	// contains filtered or unexported fields
}

func (*TcpSession) DeleteKV

func (s *TcpSession) DeleteKV(key interface{})

func (*TcpSession) Id

func (s *TcpSession) Id() uint32

func (*TcpSession) Load

func (s *TcpSession) Load(key interface{}) (value interface{}, ok bool)

func (*TcpSession) LocalAddr

func (s *TcpSession) LocalAddr() net.Addr

func (*TcpSession) RemoteAddr

func (s *TcpSession) RemoteAddr() net.Addr

func (*TcpSession) RemoteIP

func (s *TcpSession) RemoteIP() string

func (*TcpSession) SendMsg

func (s *TcpSession) SendMsg(msg []byte) error

func (*TcpSession) Stop

func (s *TcpSession) Stop()

func (*TcpSession) StoreKV

func (s *TcpSession) StoreKV(key, value interface{})

func (*TcpSession) Type

func (s *TcpSession) Type() SessionType

Jump to

Keyboard shortcuts

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