kapp

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WM_THREAD_START uint32 = 1 << 28
	//线程退出消息
	WM_THREAD_EXIT = WM_THREAD_START + 99

	//=========================================================================
	WM_TCPSERVER_STARTED = WM_THREAD_START + 100

	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_TCPSERVER_STARTED
		WParam    uint64		server_id
		LParam    uint64		local_port
		WInfo     string
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_TCPSERVER_STOPPED = WM_THREAD_START + 110
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_TCPSERVER_STOPPED
		WParam    uint64		server_id
		LParam    uint64		local_port
		WInfo     string
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_TCPSERVER_CLIENT_CONNECTED = WM_THREAD_START + 120
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_TCPSERVER_CLIENT_CONNECTED
		WParam    uint64		server_id | client_id
		LParam    uint64		local_port | remote_port
		WInfo     string		remote_ip
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_TCPSERVER_CLIENT_DISCONNECTED = WM_THREAD_START + 130
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_TCPSERVER_CLIENT_DISCONNECTED
		WParam    uint64		server_id | client_id
		LParam    uint64		local_port | remote_port
		WInfo     string		remote_ip
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_TCPSERVER_CLIENT_RCV_DATA = WM_THREAD_START + 140

	WM_TCPCLIENT_CONNECTED = WM_THREAD_START + 220

	WM_TCPCLIENT_DISCONNECTED = WM_THREAD_START + 230
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_TCPCLIENT_CLIENT_DISCONNECTED
		WParam    uint64		client_id
		LParam    uint64		local_port | remote_port
		WInfo     string		remote_ip
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_TCPCLIENT_RCV_DATA = WM_THREAD_START + 240

	//=========================================================================
	WM_UDP_STARTED = WM_THREAD_START + 300
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_UDP_STARTED
		WParam    uint64		udp_id
		LParam    uint64		local_port
		WInfo     string
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_UDP_STOPPED = WM_THREAD_START + 310
	/*
		ClassId   uint32		发送消息的对象id
		MsgId     uint32		WM_UDP_STOPPED
		WParam    uint64		udp_id
		LParam    uint64		local_port
		WInfo     string
		LInfo     string		local_ip
		OtherInfo interface{}
	 * */
	WM_UDP_RCV_DATA = WM_THREAD_START + 340

	//============================================================
	WM_TIMER = WM_THREAD_START + 400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BSocketConnInfo

type BSocketConnInfo struct {
	ConnType     string //连接类型	upd  tcp
	ConnClassId  uint32 //归属kapp对象编号
	ConnServerId uint32 //归属服务器编号
	ConnId       uint32 //连接编号

	LocalIp    string //本地地址
	LocalPort  int    //本地端口
	RemoteIp   string //远端地址
	RemotePort int    //远端端口

	IsStart   bool      //是否处于启动状态
	EventTime time.Time //停止或者启动时间
}

func (*BSocketConnInfo) String

func (t *BSocketConnInfo) String() string

type BTcpClient

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

=================tcpclient节点

func NewBTcpClient

func NewBTcpClient(classid uint32) (*BTcpClient, error)

构造BTcpClient

func (*BTcpClient) FreeBs

func (t *BTcpClient) FreeBs(bs []byte) error

将申请通知使用的缓存还回缓冲池,提高使用率

func (*BTcpClient) GetId

func (t *BTcpClient) GetId() uint32

func (*BTcpClient) GetLocalAddr

func (t *BTcpClient) GetLocalAddr() (string, int)

func (*BTcpClient) GetPacketSize

func (t *BTcpClient) GetPacketSize() int

func (*BTcpClient) GetRemoteAddr

func (t *BTcpClient) GetRemoteAddr() (string, int)

func (*BTcpClient) GetStatus

func (t *BTcpClient) GetStatus() (bool, time.Time)

获取启动状态

func (*BTcpClient) SendData

func (t *BTcpClient) SendData(bs []byte) (int, error)

发送数据

func (*BTcpClient) SetFnTcpClientConn

func (t *BTcpClient) SetFnTcpClientConn(fnconn FnTcpClientConn) error

设置回调函数 - 启动通知

func (*BTcpClient) SetFnTcpClientDisConn

func (t *BTcpClient) SetFnTcpClientDisConn(fndisconn FnTcpClientDisConn) error

设置回调函数 - 停止通知

func (*BTcpClient) SetFnTcpClientRcvData

func (t *BTcpClient) SetFnTcpClientRcvData(fnrecv FnTcpClientRcvData) error

设置回调函数 - 收到数据通知

func (*BTcpClient) SetId

func (t *BTcpClient) SetId(classid uint32) error

设置ClassId

func (*BTcpClient) SetLocalAddr

func (t *BTcpClient) SetLocalAddr(localip string, localport int) error

设置本地地址信息

func (*BTcpClient) SetNotifyThread

func (t *BTcpClient) SetNotifyThread(notifythread IBaseThread) error

设置通知协程

func (*BTcpClient) SetPacketSize

func (t *BTcpClient) SetPacketSize(packetsize int) error

设置默认包大小

func (*BTcpClient) SetRemoteAddr

func (t *BTcpClient) SetRemoteAddr(remoteip string, remoteport int) error

设置远端地址信息

func (*BTcpClient) Start

func (t *BTcpClient) Start() error

启动TCPCLIENT

func (*BTcpClient) Stop

func (t *BTcpClient) Stop() error

停止btcpclient

type BTcpServer

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

==============================================================================

func NewBTcpServer

func NewBTcpServer(classid uint32) *BTcpServer

新构建一个NewBServer

func (*BTcpServer) CloseAllClient

func (t *BTcpServer) CloseAllClient() error

关闭所有TcpClient

func (*BTcpServer) CloseClient

func (t *BTcpServer) CloseClient(clientid uint32) error

关闭TcpClient

func (*BTcpServer) FreeBs

func (t *BTcpServer) FreeBs(bs []byte) error

将申请通知使用的缓存还回缓冲池,提高使用率

func (*BTcpServer) GetAllClient

func (t *BTcpServer) GetAllClient() *list.TList

获取所有客户端列表TcpClient

func (*BTcpServer) GetId

func (t *BTcpServer) GetId() uint32

func (*BTcpServer) GetLocalAddr

func (t *BTcpServer) GetLocalAddr() (string, int)

func (*BTcpServer) GetPacketSize

func (t *BTcpServer) GetPacketSize() int

func (*BTcpServer) GetStatus

func (t *BTcpServer) GetStatus() (bool, time.Time)

获取启动状态

func (*BTcpServer) SendData

func (t *BTcpServer) SendData(clientid uint32, bs []byte) (int, error)

发送数据

func (*BTcpServer) SetFnTcpServerConn

func (t *BTcpServer) SetFnTcpServerConn(fnconn FnTcpServerConn) error

设置回调函数 - 客户端连接通知

func (*BTcpServer) SetFnTcpServerDisConn

func (t *BTcpServer) SetFnTcpServerDisConn(fndisconn FnTcpServerDisConn) error

设置回调函数 - 客户端断开连接通知

func (*BTcpServer) SetFnTcpServerRcvData

func (t *BTcpServer) SetFnTcpServerRcvData(fnrecv FnTcpServerRcvData) error

设置回调函数 - 收到数据通知

func (*BTcpServer) SetFnTcpServerStart

func (t *BTcpServer) SetFnTcpServerStart(fnstart FnTcpServerStart) error

设置回调函数 - 启动通知

func (*BTcpServer) SetFnUdpStop

func (t *BTcpServer) SetFnUdpStop(fnstop FnTcpServerStop) error

设置回调函数 - 停止通知

func (*BTcpServer) SetId

func (t *BTcpServer) SetId(classid uint32) error

设置ClassId

func (*BTcpServer) SetLocalAddr

func (t *BTcpServer) SetLocalAddr(localip string, localport int) error

设置本地地址信息

func (*BTcpServer) SetNotifyThread

func (t *BTcpServer) SetNotifyThread(notifythread IBaseThread) error

设置通知协程

func (*BTcpServer) SetPacketSize

func (t *BTcpServer) SetPacketSize(packetsize int) error

设置默认包大小

func (*BTcpServer) Start

func (t *BTcpServer) Start() error

启动BServer

func (*BTcpServer) Stop

func (t *BTcpServer) Stop() error

停止BServer

type BUdp

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

=================udp节点

func NewBUdp

func NewBUdp(classid uint32) (*BUdp, error)

构造BUdp

func (*BUdp) FreeBs

func (t *BUdp) FreeBs(bs []byte) error

将申请通知使用的缓存还回缓冲池,提高使用率

func (*BUdp) GetId

func (t *BUdp) GetId() uint32

func (*BUdp) GetLocalAddr

func (t *BUdp) GetLocalAddr() (string, int)

func (*BUdp) GetPacketSize

func (t *BUdp) GetPacketSize() int

func (*BUdp) GetRemoteAddr

func (t *BUdp) GetRemoteAddr() (string, int)

func (*BUdp) GetStatus

func (t *BUdp) GetStatus() (bool, time.Time)

获取启动状态

func (*BUdp) SendData

func (t *BUdp) SendData(bs []byte) (int, error)

发送数据

func (*BUdp) SendDataTo

func (t *BUdp) SendDataTo(remoteip string, remoteport int, bs []byte) (int, error)

func (*BUdp) SetFnUdpRcvData

func (t *BUdp) SetFnUdpRcvData(fnrecv FnUdpRcvData) error

设置回调函数 - 收到数据通知

func (*BUdp) SetFnUdpStart

func (t *BUdp) SetFnUdpStart(fnstart FnUdpStart) error

设置回调函数 - 启动通知

func (*BUdp) SetFnUdpStop

func (t *BUdp) SetFnUdpStop(fnstop FnUdpStop) error

设置回调函数 - 停止通知

func (*BUdp) SetId

func (t *BUdp) SetId(classid uint32) error

设置ClassId

func (*BUdp) SetLocalAddr

func (t *BUdp) SetLocalAddr(localip string, localport int) error

设置本地地址信息

func (*BUdp) SetNotifyThread

func (t *BUdp) SetNotifyThread(notifythread IBaseThread) error

设置通知协程

func (*BUdp) SetPacketSize

func (t *BUdp) SetPacketSize(packetsize int) error

设置默认包大小

func (*BUdp) SetRemoteAddr

func (t *BUdp) SetRemoteAddr(remoteip string, remoteport int) error

设置远端地址信息

func (*BUdp) Start

func (t *BUdp) Start() error

启动UDP

func (*BUdp) Stop

func (t *BUdp) Stop() error

停止UDP

type BaseTcpClient

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

func NewBaseTcpClient

func NewBaseTcpClient(classid uint32, packetsize int) *BaseTcpClient

新构建一个TcpClient

func (*BaseTcpClient) AddTcpClient

func (t *BaseTcpClient) AddTcpClient(clientid uint32, localip string, localport int, remoteip string, remoteport int) error

添加一个UDP

func (*BaseTcpClient) AddTcpClientWithCallback

func (t *BaseTcpClient) AddTcpClientWithCallback(clientid uint32, localip string, localport int, remoteip string, remoteport int, notifythread IBaseThread, fnconn FnTcpClientConn, fndisconn FnTcpClientDisConn, fnrcvdata FnTcpClientRcvData) error

func (*BaseTcpClient) ClearTcpClient

func (t *BaseTcpClient) ClearTcpClient() error

清空所有UDP

func (*BaseTcpClient) DelTcpClient

func (t *BaseTcpClient) DelTcpClient(clientid uint32) error

删除一个UDP

func (*BaseTcpClient) FreeBs

func (t *BaseTcpClient) FreeBs(bs []byte) error

将申请通知使用的缓存还回缓冲池,提高使用率

func (*BaseTcpClient) GetTcpClientInfo

func (t *BaseTcpClient) GetTcpClientInfo(clientid uint32) (bool, *time.Time, string, int, string, int, error)

获取指定编号tcpclient是否已经启动,以及本地地址和端口

func (*BaseTcpClient) SendData

func (t *BaseTcpClient) SendData(clientid uint32, bs []byte) (int, error)

发送数据

func (*BaseTcpClient) SetFnTcpClientConn

func (t *BaseTcpClient) SetFnTcpClientConn(fntcpclientconn FnTcpClientConn) error

设置默认回调-启动 对于已经启动的TcpClient,不受影响

func (*BaseTcpClient) SetFnTcpClientDisConn

func (t *BaseTcpClient) SetFnTcpClientDisConn(fntcpclientdisconn FnTcpClientDisConn) error

设置默认回调-停止 对于已经启动的TcpClient,不受影响

func (*BaseTcpClient) SetFnTcpClientRcvData

func (t *BaseTcpClient) SetFnTcpClientRcvData(fntcpclientrcvdata FnTcpClientRcvData) error

设置默认回调-收到数据 对于已经启动的TcpClient,不受影响

func (*BaseTcpClient) SetNotifyThread

func (t *BaseTcpClient) SetNotifyThread(notifythread IBaseThread) error

设置默认通知线程 对于已经启动的TcpClient,不受影响

func (*BaseTcpClient) StartTcpClient

func (t *BaseTcpClient) StartTcpClient(clientid uint32) error

启动一个UDP

func (*BaseTcpClient) StopTcpClient

func (t *BaseTcpClient) StopTcpClient(clientid uint32) error

停止一个UDP

type BaseThread

type BaseThread struct {
	ClassId uint32
	Name    string
	// contains filtered or unexported fields
}

=======================================================================================

func (*BaseThread) DoWithMsg

func (t *BaseThread) DoWithMsg(classId uint32, msgId uint32, wParam uint64, lParam uint64, wInfo string, lInfo string, otherInfo interface{}) int

func (*BaseThread) Init

func (t *BaseThread) Init() int

func (*BaseThread) InitilizeThread

func (t *BaseThread) InitilizeThread(classId uint32, name string, fnInit FnInit, fnUnInit FnUnInit, fnDoWithMsg FnDoWithMsg) error

* 新创建一个线程对象

func (*BaseThread) IsStart

func (t *BaseThread) IsStart() bool

func (*BaseThread) PostComplexMsg

func (t *BaseThread) PostComplexMsg(classId uint32, msgId uint32, wParam uint64, lParam uint64, wInfo string, lInfo string, otherInfo interface{}) error

func (*BaseThread) PostMsg

func (t *BaseThread) PostMsg(msgId uint32, wParam uint64, lParam uint64) error

func (*BaseThread) Start

func (t *BaseThread) Start() error

func (*BaseThread) Stop

func (t *BaseThread) Stop() error

func (*BaseThread) UnInit

func (t *BaseThread) UnInit() int

func (*BaseThread) WaitExit

func (t *BaseThread) WaitExit() error

type BaseTimer

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

基本定时器

func NewBaseTimer

func NewBaseTimer(classid uint32) *BaseTimer

初始化定时器

func (*BaseTimer) AddCronTimer

func (t *BaseTimer) AddCronTimer(timerid uint32, cron string, param uint64, info string, notifythread IBaseThread, fnontimer FnOnTimer) error

添加CRON定时器 cron (second,1)|second|minute|hour|day|month|year|week

func (*BaseTimer) AddCycleTimer

func (t *BaseTimer) AddCycleTimer(timerid uint32, timerlen int, param uint64, info string, notifythread IBaseThread, fnontimer FnOnTimer) error

添加循环定时器

func (*BaseTimer) AddOnceTimer

func (t *BaseTimer) AddOnceTimer(timerid uint32, timerlen int, param uint64, info string, notifythread IBaseThread, fnontimer FnOnTimer) error

添加单次定时器

func (*BaseTimer) ClearTimer

func (t *BaseTimer) ClearTimer() error

清空定时器

func (*BaseTimer) DelTimer

func (t *BaseTimer) DelTimer(timerid uint32) error

删除定时器

func (*BaseTimer) StartTimer

func (t *BaseTimer) StartTimer() error

启动定时器

func (*BaseTimer) StopTimer

func (t *BaseTimer) StopTimer() error

停止定时器

type BaseUdp

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

func NewBaseUdp

func NewBaseUdp(classid uint32, packetsize int) *BaseUdp

新构建一个BaseUdp

func (*BaseUdp) AddUdp

func (t *BaseUdp) AddUdp(udpid uint32, localip string, localport int) error

添加一个UDP

func (*BaseUdp) AddUdpWithCallback

func (t *BaseUdp) AddUdpWithCallback(udpid uint32, localip string, localport int, notifythread IBaseThread, fnstart FnUdpStart, fnstop FnUdpStop, fnrcvdata FnUdpRcvData) error

func (*BaseUdp) ClearUdp

func (t *BaseUdp) ClearUdp() error

清空所有UDP

func (*BaseUdp) DelUdp

func (t *BaseUdp) DelUdp(udpid uint32) error

删除一个UDP

func (*BaseUdp) FreeBs

func (t *BaseUdp) FreeBs(bs []byte) error

将申请通知使用的缓存还回缓冲池,提高使用率

func (*BaseUdp) GetUdpInfo

func (t *BaseUdp) GetUdpInfo(udpid uint32) (bool, *time.Time, string, int, error)

获取指定编号udp是否已经启动,以及本地地址和端口

func (*BaseUdp) SendData

func (t *BaseUdp) SendData(udpid uint32, remoteip string, remoteport int, bs []byte) (int, error)

通过一个UDP发送数据

func (*BaseUdp) SetFnUdpRcvData

func (t *BaseUdp) SetFnUdpRcvData(fnduprcvdata FnUdpRcvData) error

设置默认回调-收到数据 对于已经启动的UDP,不受影响

func (*BaseUdp) SetFnUdpStart

func (t *BaseUdp) SetFnUdpStart(fnudpstart FnUdpStart) error

设置默认回调-启动 对于已经启动的UDP,不受影响

func (*BaseUdp) SetFnUdpStop

func (t *BaseUdp) SetFnUdpStop(fnudpstop FnUdpStop) error

设置默认回调-停止 对于已经启动的UDP,不受影响

func (*BaseUdp) SetNotifyThread

func (t *BaseUdp) SetNotifyThread(notifythread IBaseThread) error

设置默认通知线程 对于已经启动的UDP,不受影响

func (*BaseUdp) StartUdp

func (t *BaseUdp) StartUdp(udpid uint32) error

启动一个UDP

func (*BaseUdp) StopUdp

func (t *BaseUdp) StopUdp(udpid uint32) error

停止一个UDP

type BytebufferPool

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

=====================================================================================

func NewBytebufferPool

func NewBytebufferPool(size int) *BytebufferPool

func (*BytebufferPool) GetBytebuffer

func (t *BytebufferPool) GetBytebuffer() []byte

func (*BytebufferPool) PutBytebuffer

func (t *BytebufferPool) PutBytebuffer(b []byte)

type FnDoWithMsg

type FnDoWithMsg func(classId uint32, msgId uint32, wParam uint64, lParam uint64, wInfo string, lInfo string, otherInfo interface{}) int

线程消息处理函数,返回0退出线程

type FnInit

type FnInit func() int

线程启动初始化,返回0退出线程,不启动消息循环

type FnOnTimer

type FnOnTimer func(classid uint32, timerId uint32, param uint64, info string)

type FnTcpClientConn

type FnTcpClientConn func(classId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int)

tcpclient

type FnTcpClientDisConn

type FnTcpClientDisConn func(classId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int)

type FnTcpClientRcvData

type FnTcpClientRcvData func(conn *net.TCPConn, classId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int, bs []byte)

type FnTcpServerConn

type FnTcpServerConn func(classId uint32, serverId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int)

type FnTcpServerDisConn

type FnTcpServerDisConn func(classId uint32, serverId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int)

type FnTcpServerRcvData

type FnTcpServerRcvData func(conn *net.TCPConn, classId uint32, serverId uint32, clientId uint32, localIp string, localPort int, remoteIp string, remotePort int, bs []byte)

type FnTcpServerStart

type FnTcpServerStart func(classId uint32, serverId uint32, localIp string, localPort int)

tcpserver

type FnTcpServerStop

type FnTcpServerStop func(classId uint32, serverId uint32, localIp string, localPort int)

type FnUdpRcvData

type FnUdpRcvData func(udpconn *net.UDPConn, classId uint32, udpId uint32, remoteIP string, remotePort int, bs []byte)

type FnUdpStart

type FnUdpStart func(classId uint32, udpId uint32, localIp string, localPort int)

UDP处理回调函数

type FnUdpStop

type FnUdpStop func(classId uint32, udpId uint32, localIp string, localPort int)

type FnUnInit

type FnUnInit func() int

线程退出自动执行

type IBaseThread

type IBaseThread interface {
	//初始化线程
	InitilizeThread(classId uint32, name string, fnInit FnInit, fnUnInit FnUnInit, fnDoWithMsg FnDoWithMsg) error
	//查看线程是否已经启动
	IsStart() bool
	//启动线程
	Start() error
	//停止线程
	Stop() error
	//等待线程退出
	WaitExit() error
	//Post一个简单消息
	PostMsg(msgId uint32, wParam uint64, lParam uint64) error
	//post一个带参数的消息
	PostComplexMsg(classId uint32, msgId uint32, wParam uint64, lParam uint64, wInfo string, lInfo string, otherInfo interface{}) error

	//线程启动初始化
	Init() int
	//线程退出自动执行
	UnInit() int
	//线程消息处理函数
	DoWithMsg(classId uint32, msgId uint32, wParam uint64, lParam uint64, wInfo string, lInfo string, otherInfo interface{}) int
}

type TMemStream

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

func (*TMemStream) Append

func (t *TMemStream) Append(bs []byte)

func (*TMemStream) Clear

func (t *TMemStream) Clear()

func (*TMemStream) GetAndRemove

func (t *TMemStream) GetAndRemove(l int) []byte

func (*TMemStream) GetHead

func (t *TMemStream) GetHead(l int) []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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