app

package
v0.0.0-...-14a5b4d Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Evt_gap_time  = 16     // 心跳时间(毫秒)
	Evt_gap_bit   = 4      // 心跳时间对应得移位(快速运算使用)
	Evt_lay1_time = 160000 // 第一层事件池最大支持时间(毫秒)
)
View Source
const (
	LogDebugLevel = 0                // 日志等级 : 调试信息
	LogInfoLevel  = 1                // 日志等级 : 普通信息
	LogWarnLevel  = 2                // 日志等级 : 警告信息
	LogErrorLevel = 3                // 日志等级 : 错误信息
	LogFatalLevel = 4                // 日志等级 : 致命信息
	LogMaxLevel   = 5                // 日志最大等级
	LogLimitLevel = LogInfoLevel     // 显示这个等级之上的日志(控制台)
	LogBuffMax    = 20 * 1024 * 1024 // 日志缓冲
)
View Source
const (
	AppName     = "login"
	LogBuffSize = 10 * 1024 * 1024
	LogDir      = "../log"
	ProfFile    = AppName + "_prof.log"
	LogFileName = LogDir + "/" + AppName + ".log"
)
View Source
const (
	MaxDataLen     = 5080
	MaxSendDataLen = 4000
	MaxHeader      = 2
)
View Source
const (
	UpdateCurrTimeCount = 32 // 刷新时间戳变更上线
)

Variables

This section is empty.

Functions

func Main_go

func Main_go()

func OnListenRet

func OnListenRet(typ string, name string, id int, info string) bool

func RegLua_all_appBase

func RegLua_all_appBase(L *lua.LState) error

注册本包所有Lua接口结构

func RegMsgProc

func RegMsgProc()

Types

type AppBase

type AppBase struct {
	Listener     map[string]*ListenConn // 本地侦听端口
	RemoteSvr    map[string]*ClientConn // 远程服务连接
	Conns        map[int]*ClientConn    // 连接池
	ConnLast     int                    // 最后连接Id
	MsgProc      []MsgFunc              // 消息处理函数注册表
	MsgProcCount int                    // 消息函数数量
	// contains filtered or unexported fields
}

func GetApp

func GetApp() *AppBase

func (*AppBase) AddConn

func (this *AppBase) AddConn(c *ClientConn)

func (*AppBase) ConnProc

func (this *AppBase) ConnProc(c *ClientConn, onRet ConnRetFunc)

func (*AppBase) ConnProcEx

func (this *AppBase) ConnProcEx(c *ClientConn, onRet ConnRetFunc)

func (*AppBase) Connect

func (this *AppBase) Connect(name, net_type, address string, onRet ConnRetFunc)

func (*AppBase) DelConn

func (this *AppBase) DelConn(id int)

func (*AppBase) GetConnById

func (this *AppBase) GetConnById(id int) *ClientConn

func (*AppBase) GetConnByName

func (this *AppBase) GetConnByName(name string) *ClientConn

func (*AppBase) GetCurrTime

func (this *AppBase) GetCurrTime() int64

获取当前时间戳(毫秒)

func (*AppBase) GetEvent

func (this *AppBase) GetEvent(name string) help.IEvent

通过别名获取事件

func (*AppBase) GetLUserData

func (this *AppBase) GetLUserData(n string, a interface{}) *lua.LUserData

获取用Lua类型封装结构指针 *LUserData

func (*AppBase) GetLuaState

func (this *AppBase) GetLuaState() *lua.LState

!!!只能获取, 不准许保存指针, 获取LState

func (*AppBase) Listen

func (this *AppBase) Listen(name, net_type, address string, onRet ConnRetFunc)

func (*AppBase) LogBase

func (this *AppBase) LogBase(level int, info string)

线程日志 : 手动分级日志

func (*AppBase) LogDebug

func (this *AppBase) LogDebug(f string, v ...interface{})

线程日志 : 调试[D]级别日志

func (*AppBase) LogError

func (this *AppBase) LogError(f string, v ...interface{})

线程日志 : 错误[E]级别日志

func (*AppBase) LogFatal

func (this *AppBase) LogFatal(f string, v ...interface{})

线程日志 : 致命[F]级别日志

func (*AppBase) LogInfo

func (this *AppBase) LogInfo(f string, v ...interface{})

线程日志 : 信息[I]级别日志

func (*AppBase) LogWarn

func (this *AppBase) LogWarn(f string, v ...interface{})

线程日志 : 警告[W]级别日志

func (*AppBase) MakeLogHeader

func (this *AppBase) MakeLogHeader()

线程日志 : 生成日志头

func (*AppBase) PostEvent

func (this *AppBase) PostEvent(a help.IEvent) bool

投递定时器事件

func (*AppBase) PostEventFromLua

func (this *AppBase) PostEventFromLua(m string, f string, t uint64, p lua.LValue) bool

lua投递事件

func (*AppBase) RegMsgFunc

func (this *AppBase) RegMsgFunc(id int, f MsgFunc)

func (*AppBase) RemoveEvent

func (this *AppBase) RemoveEvent(e help.IEvent)

func (*AppBase) Start

func (this *AppBase) Start(heart_time int64) bool

程序开启

func (*AppBase) Tolua_Common

func (this *AppBase) Tolua_Common(m string, f string)

调用Lua函数 : 没有参数, 没有返回值

func (*AppBase) Tolua_Common_Param

func (this *AppBase) Tolua_Common_Param(m string, f string, t lua.LValue)

调用Lua函数 : 只有参数

func (*AppBase) Tolua_Common_Param_Ret

func (this *AppBase) Tolua_Common_Param_Ret(m string, f string, t lua.LValue) (ret lua.LValue)

调用Lua函数 : 有参数, 有返回值

func (*AppBase) WaitExit

func (this *AppBase) WaitExit()

等待协程结束

type ClientConn

type ClientConn struct {
	Name    string
	Type    string
	Address string
	Id      int
	Sid     int
	Msg     Ty_net_msg
	Stream  Ty_msg_stream
	Conn    *net.TCPConn
}

客户端连接

func (*ClientConn) InitClient

func (c *ClientConn) InitClient(id int, con *net.TCPConn)

func (*ClientConn) IsNull

func (c *ClientConn) IsNull() bool

type ConnRetFunc

type ConnRetFunc func(string, string, int, string) bool

type Event_from_lua

type Event_from_lua struct {
	help.Evt_base
	// contains filtered or unexported fields
}

事件 : lua使用的通用事件

func (*Event_from_lua) Exec

func (this *Event_from_lua) Exec() bool

事件执行

type ListenConn

type ListenConn struct {
	Name    string
	Type    string
	Address string
	Conn    *net.TCPListener
}

侦听服务

func (*ListenConn) InitListen

func (c *ListenConn) InitListen(name, net_type, address string, con *net.TCPListener)

type MsgFunc

type MsgFunc func(*ClientConn)

消息函数类型

type Msg_node

type Msg_node struct {
	Len   uint32 // 包长度
	Token uint32 // 包令牌
	Count uint32 // 包内消息数
	Data  []byte // 数据
}

消息节点(list节点)

func ReadConnData

func ReadConnData(conn *net.TCPConn) (msg Msg_node, ret error)

读取网络消息

type Ty_msg_stream

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

网络消息体读写

func (*Ty_msg_stream) InitMsgStream

func (t *Ty_msg_stream) InitMsgStream(msg *Ty_net_msg)

func (*Ty_msg_stream) PrintData

func (t *Ty_msg_stream) PrintData()

func (*Ty_msg_stream) ReadStr

func (t *Ty_msg_stream) ReadStr() string

func (*Ty_msg_stream) ReadU1

func (t *Ty_msg_stream) ReadU1() int

func (*Ty_msg_stream) ReadU2

func (t *Ty_msg_stream) ReadU2() int

func (*Ty_msg_stream) ReadU4

func (t *Ty_msg_stream) ReadU4() int

func (*Ty_msg_stream) Seek

func (t *Ty_msg_stream) Seek(pos int)

func (*Ty_msg_stream) WriteString

func (t *Ty_msg_stream) WriteString(d *string) bool

func (*Ty_msg_stream) WriteU1

func (t *Ty_msg_stream) WriteU1(d int) bool

func (*Ty_msg_stream) WriteU2

func (t *Ty_msg_stream) WriteU2(d int) bool

func (*Ty_msg_stream) WriteU4

func (t *Ty_msg_stream) WriteU4(d int) bool

type Ty_net_msg

type Ty_net_msg struct {
	Data []byte
	Len  int
}

网络消息体

func (*Ty_net_msg) InitNetMsg

func (t *Ty_net_msg) InitNetMsg()

func (*Ty_net_msg) PrintData

func (t *Ty_net_msg) PrintData()

func (*Ty_net_msg) ReadBody

func (t *Ty_net_msg) ReadBody(conn *net.TCPConn) error

func (*Ty_net_msg) ReadData

func (t *Ty_net_msg) ReadData(conn *net.TCPConn) error

func (*Ty_net_msg) Send

func (t *Ty_net_msg) Send(conn *net.TCPConn) error

Jump to

Keyboard shortcuts

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