1 Star 0 Fork 0

lichun-123/leaf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cluster.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
lichun-123 提交于 2023-10-05 17:04 . proto update
package cluster
import (
"gitee.com/lichun-123/leaf/conf"
"gitee.com/lichun-123/leaf/network"
"math"
"time"
)
var (
server *network.TCPServer
clients []*network.TCPClient
)
func Init() {
if conf.ListenAddr != "" {
server = new(network.TCPServer)
server.Addr = conf.ListenAddr
server.MaxConnNum = int(math.MaxInt32)
server.PendingWriteNum = conf.PendingWriteNum
server.LenMsgLen = 4
server.MaxMsgLen = math.MaxUint32
server.NewAgent = newAgent
server.Start()
}
for _, addr := range conf.ConnAddrs {
client := new(network.TCPClient)
client.Addr = addr
client.ConnNum = 1
client.ConnectInterval = 3 * time.Second
client.PendingWriteNum = conf.PendingWriteNum
client.LenMsgLen = 4
client.MaxMsgLen = math.MaxUint32
client.NewAgent = newAgent
client.Start()
clients = append(clients, client)
}
}
func Destroy() {
if server != nil {
server.Close()
}
for _, client := range clients {
client.Close()
}
}
type Agent struct {
conn *network.TCPConn
}
func newAgent(conn *network.TCPConn) network.Agent {
a := new(Agent)
a.conn = conn
return a
}
func (a *Agent) HandleMsg(data []byte) {}
func (a *Agent) OnClose() {}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lichun-123/leaf.git
git@gitee.com:lichun-123/leaf.git
lichun-123
leaf
leaf
v0.0.15

搜索帮助