network

package
v0.0.0-...-372ebbf Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PING_OP_TYPE_ADD_PING = iota
	PING_OP_TYPE_REMOVE_PING
	PING_OP_TYPE_DO_PONG
)
View Source
const (
	Linker_TCP_InComming = iota
	Linker_TCP_OutGoing
)
View Source
const (
	ConnType_TCP = iota
	ConnType_UDP
)
View Source
const (
	COMPONENT_TYPE_TCP_SERVER = component.COMPONENT_TYPE_TCP_SERVER
	COMPONENT_TYPE_TCP_CLIENT = component.COMPONENT_TYPE_TCP_CLIENT
)
View Source
const (
	MSG_KEY_LENGTH         = 32
	MSG_HEADER_LENGTH      = 4
	MSG_ID_LENGTH          = 4
	MSG_MAX_BODY_LENGTH    = 8096
	MSG_DEFAULT_BUF_LENGTH = 1024
	MSG_DEFAULT_COUNT      = 100
	MSG_COUNT_CHECK_TIME   = 3000
)
View Source
const BUFFER_BASE_SIZE = 1024
View Source
const KEEP_ALIVE_POLL_COUNT = 128
View Source
const TCP_ACCEPT_SLEEP = 150

Variables

View Source
var (
	//PINGTIME        int64 = 5 * 1000 //Millisecond
	//PONGTIME        int64 = PINGTIME * 2
	CHECKTIME int64 = 256 //Millisecond
)

Functions

func RpcMarshal

func RpcMarshal(b []byte, val interface{}) []byte

func RpcUnMarshal

func RpcUnMarshal(b []byte) (interface{}, []byte)

func Run

func Run()

func UnixTS

func UnixTS() int64

Types

type Agent

type Agent = agent.Agent

type AgentID

type AgentID = agent.AgentID

type BytesBuffer

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

func (*BytesBuffer) Count

func (b *BytesBuffer) Count() int

func (*BytesBuffer) Read

func (b *BytesBuffer) Read(n int)

func (*BytesBuffer) ReadBuf

func (b *BytesBuffer) ReadBuf(n int) []byte

func (*BytesBuffer) Reserve

func (b *BytesBuffer) Reserve(s int)

func (*BytesBuffer) Reset

func (b *BytesBuffer) Reset()

func (*BytesBuffer) Write

func (b *BytesBuffer) Write(n int)

func (*BytesBuffer) WriteBuf

func (b *BytesBuffer) WriteBuf() []byte

func (*BytesBuffer) WriteBytes

func (b *BytesBuffer) WriteBytes(m []byte) int

func (*BytesBuffer) WriteUint32

func (b *BytesBuffer) WriteUint32(i uint32) int

func (*BytesBuffer) WriteUint8

func (b *BytesBuffer) WriteUint8(m byte) int

type Component

type Component = component.Component

func NewTcpClientMgr

func NewTcpClientMgr(opts ...Option) Component

func NewTcpServerMgr

func NewTcpServerMgr(opts ...Option) Component

type ComponentID

type ComponentID = component.ComponentID

func GenComponentID

func GenComponentID() ComponentID

type ComponentType

type ComponentType = component.ComponentType

type ConnType

type ConnType uint16

type EventQueue

type EventQueue = event.EventQueue

type EventReceiver

type EventReceiver = event.EventReceiver

type ITcpClientMgr

type ITcpClientMgr interface {
	GetID() ComponentID
	GetType() ComponentType
	Connect(addr string, user_type interface{})
}

type ITcpServerMgr

type ITcpServerMgr interface {
	GetID() ComponentID
	GetType() ComponentType
	Address() net.Addr
}

type ITranMsgMultiple

type ITranMsgMultiple interface {
	WriteMsg(ProtoTypeID, []byte) bool
	RpcCall(ProtoTypeID, []byte) bool
	Done() bool
}

type ITransportMsg

type ITransportMsg interface {
	GetType() byte
	// contains filtered or unexported methods
}

type ITransporter

type ITransporter interface {
	IsClosed() bool
	// contains filtered or unexported methods
}

type Linker

type Linker interface {
	GetID() AgentID
	Ping() bool
	DoPong(int64)
	GetOption() *TransportOption
}

type NetLinker

type NetLinker interface {
	GetID() AgentID
	Close()
	RemoteAddr() net.Addr
	WriteMsg(ProtoTypeID, []byte) bool
	RpcCall(ProtoTypeID, []byte) bool
	MultipleMsg() ITranMsgMultiple
	GetUserType() interface{}
	SetUserType(interface{})
	Run() error
}

type Option

type Option = func(...interface{})

func ListenAddr

func ListenAddr(addr string) Option

func Module

func Module(m EventReceiver) Option

func Name

func Name(name string) Option

func ServeHandler

func ServeHandler(serve_handler SessionHandler) Option

func TransportKeepAlive

func TransportKeepAlive(e bool, c int64) Option

func TransportMaxCount

func TransportMaxCount(c int) Option

func TransportMaxLength

func TransportMaxLength(c int) Option

type OptionMgr

type OptionMgr interface {
	GetOption() *TransportOption
}

type PingEventMsg

type PingEventMsg struct {
	Sender Linker
	Op     int
	Tick   int64
}

func (*PingEventMsg) GetSender

func (this *PingEventMsg) GetSender() Agent

func (*PingEventMsg) GetType

func (this *PingEventMsg) GetType() event.EventType

func (*PingEventMsg) Reset

func (this *PingEventMsg) Reset()

type PingMgr

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

func (*PingMgr) AddPing

func (p *PingMgr) AddPing(linker Linker)

func (*PingMgr) DoPong

func (p *PingMgr) DoPong(linker Linker, tick int64)

func (*PingMgr) OnPing

func (p *PingMgr) OnPing(args []interface{})

func (*PingMgr) RemovePing

func (p *PingMgr) RemovePing(linker Linker)

func (*PingMgr) Run

func (p *PingMgr) Run()

type ProtoTypeID

type ProtoTypeID = uint32

type ServerType

type ServerType uint32

type SessionHandler

type SessionHandler interface {
	ServeHandler(Agent, ProtoTypeID, []byte)
	ServeRpc(Agent, ProtoTypeID, []byte)
}

type SessionMgr

type SessionMgr interface {
	OnLinkerConnected(AgentID, Agent)
	OnLinkerClosed(AgentID, Agent, error)
}

type TcpClientMgr

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

func (*TcpClientMgr) Close

func (this *TcpClientMgr) Close()

func (*TcpClientMgr) Connect

func (this *TcpClientMgr) Connect(addr string, user_type interface{})

func (*TcpClientMgr) GetID

func (this *TcpClientMgr) GetID() ComponentID

func (*TcpClientMgr) GetOption

func (this *TcpClientMgr) GetOption() *TransportOption

func (*TcpClientMgr) GetType

func (this *TcpClientMgr) GetType() ComponentType

func (*TcpClientMgr) Start

func (this *TcpClientMgr) Start() bool

type TcpConn

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

func (*TcpConn) Close

func (n *TcpConn) Close()

func (*TcpConn) Destroy

func (n *TcpConn) Destroy()

func (*TcpConn) DoPing

func (n *TcpConn) DoPing()

func (*TcpConn) DoPong

func (n *TcpConn) DoPong(nowTick int64)

func (*TcpConn) GetID

func (n *TcpConn) GetID() AgentID

func (*TcpConn) GetOption

func (n *TcpConn) GetOption() *TransportOption

func (*TcpConn) GetType

func (n *TcpConn) GetType() int16

func (*TcpConn) GetUserType

func (n *TcpConn) GetUserType() interface{}

func (*TcpConn) IsClosed

func (n *TcpConn) IsClosed() bool

func (*TcpConn) LocalAddr

func (n *TcpConn) LocalAddr() net.Addr

func (*TcpConn) MultipleMsg

func (n *TcpConn) MultipleMsg() ITranMsgMultiple

func (*TcpConn) Ping

func (n *TcpConn) Ping() bool

func (*TcpConn) Pong

func (n *TcpConn) Pong(nowTick int64)

func (*TcpConn) ReadMsg

func (n *TcpConn) ReadMsg() ([]byte, error)

func (*TcpConn) RemoteAddr

func (n *TcpConn) RemoteAddr() net.Addr

func (*TcpConn) RpcCall

func (n *TcpConn) RpcCall(msgID ProtoTypeID, b []byte) bool

func (*TcpConn) Run

func (n *TcpConn) Run() error

func (*TcpConn) SetUserType

func (n *TcpConn) SetUserType(t interface{})

func (*TcpConn) WriteMsg

func (n *TcpConn) WriteMsg(msgID ProtoTypeID, b []byte) bool

type TcpServerMgr

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

func (*TcpServerMgr) Address

func (this *TcpServerMgr) Address() net.Addr

func (*TcpServerMgr) Close

func (this *TcpServerMgr) Close()

func (*TcpServerMgr) GetID

func (this *TcpServerMgr) GetID() ComponentID

func (*TcpServerMgr) GetOption

func (this *TcpServerMgr) GetOption() *TransportOption

func (*TcpServerMgr) GetType

func (this *TcpServerMgr) GetType() ComponentType

func (*TcpServerMgr) Start

func (this *TcpServerMgr) Start() bool

type TimerHandler

type TimerHandler = timer.TimerHandler

type TimerManager

type TimerManager = timer.TimerManager

type TransportMsgPack

type TransportMsgPack struct {
	Buf []byte
	// contains filtered or unexported fields
}

func (*TransportMsgPack) GetType

func (m *TransportMsgPack) GetType() byte

type TransportMultiple

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

func (*TransportMultiple) Done

func (m *TransportMultiple) Done() bool

func (*TransportMultiple) GetType

func (m *TransportMultiple) GetType() byte

func (*TransportMultiple) RpcCall

func (m *TransportMultiple) RpcCall(msgiD ProtoTypeID, b []byte) bool

func (*TransportMultiple) WriteMsg

func (m *TransportMultiple) WriteMsg(msgID ProtoTypeID, b []byte) bool

type TransportOption

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

Jump to

Keyboard shortcuts

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