network

package
v0.0.0-...-f305655 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PING_OP_TYPE_ADD_PING = iota
	PING_OP_TYPE_REMOVE_PING
)
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
)
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 (
	EnableKeepAlive       = true
	PINGTIME        int64 = 5 * 1000 //Millisecond
	PONGTIME        int64 = PINGTIME * 2
	CHECKTIME       int64 = 256 //Millisecond
)

Functions

func GetNowTick

func GetNowTick() int64

func RpcMarshal

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

func RpcUnMarshal

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

func Run

func Run()

func SetKeepAlive

func SetKeepAlive(open bool, pingTime int64)

Types

type Agent

type Agent = agent.Agent

type AgentID

type AgentID = agent.AgentID

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 int16)
}

type ITcpServerMgr

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

type Linker

type Linker interface {
	GetID() AgentID
	Ping() bool
}

type NetLinker

type NetLinker interface {
	GetID() AgentID
	Close()
	RemoteAddr() net.Addr
	WriteMsg(msg_id ProtoTypeID, b []byte) bool
	GetUserType() int16
	SetUserType(int16)
	Run()
}

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 TransportMaxCount

func TransportMaxCount(c int) Option

type PingEventMsg

type PingEventMsg struct {
	Sender Linker
	Op     int
}

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) 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 {
	OnLinkerConneted(AgentID, Agent)
	OnLinkerClosed(AgentID, Agent)
}

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 int16)

func (*TcpClientMgr) GetID

func (this *TcpClientMgr) GetID() ComponentID

func (*TcpClientMgr) GetType

func (this *TcpClientMgr) GetType() ComponentType

func (*TcpClientMgr) Start

func (this *TcpClientMgr) Start()

type TcpConn

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

func (*TcpConn) BeginPing

func (this *TcpConn) BeginPing()

func (*TcpConn) Close

func (this *TcpConn) Close()

func (*TcpConn) Destroy

func (this *TcpConn) Destroy()

func (*TcpConn) DoPing

func (this *TcpConn) DoPing()

func (*TcpConn) GetID

func (this *TcpConn) GetID() AgentID

func (*TcpConn) GetLastPingTime

func (this *TcpConn) GetLastPingTime() int64

func (*TcpConn) GetType

func (this *TcpConn) GetType() int16

func (*TcpConn) GetUserType

func (this *TcpConn) GetUserType() int16

func (*TcpConn) IsClosed

func (this *TcpConn) IsClosed() bool

func (*TcpConn) LocalAddr

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

func (*TcpConn) Ping

func (this *TcpConn) Ping() bool

func (*TcpConn) Pong

func (this *TcpConn) Pong(now_tick int64)

func (*TcpConn) ReadMsg

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

func (*TcpConn) RemoteAddr

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

func (*TcpConn) RpcCall

func (this *TcpConn) RpcCall(msg_id ProtoTypeID, b []byte) bool

func (*TcpConn) Run

func (this *TcpConn) Run()

func (*TcpConn) SetUserType

func (this *TcpConn) SetUserType(t int16)

func (*TcpConn) WriteMsg

func (this *TcpConn) WriteMsg(msg_id 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) GetType

func (this *TcpServerMgr) GetType() ComponentType

func (*TcpServerMgr) Start

func (this *TcpServerMgr) Start()

type TimerHandler

type TimerHandler = timer.TimerHandler

type TimerManager

type TimerManager = timer.TimerManager

type TransportOption

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

type WriteWrapper

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

Jump to

Keyboard shortcuts

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