This commit is contained in:
laodaming 2023-11-02 15:00:37 +08:00
parent ba9cb470a6
commit 855189b565
5 changed files with 10 additions and 41 deletions

View File

@ -49,18 +49,12 @@ func popCommonNotifyCache() (data commonConnectionNotFoundDataCacheChanItem) {
}
// 消费公共通知未处理的消息(目前是轮巡方式,待优化)
func ConsumeCommonCacheData(ctx context.Context) {
func ConsumeCommonCacheData() {
defer func() {
if err := recover(); err != nil {
logx.Error("consumeCommonCacheData panic :", err)
}
}()
go func() {
select {
case <-ctx.Done():
panic("consumeCommonCacheData ctx deadline")
}
}()
for {
time.Sleep(time.Millisecond * 200)
info := popCommonNotifyCache()

View File

@ -1,7 +1,6 @@
package logic
import (
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
@ -50,14 +49,14 @@ func sendCancelRenderMsgToUnity(wid string, deadlineTime int64) {
}
// 拨号udp
func DialUdp(ctx context.Context, config config.Config) error {
func DialUdp(config config.Config) error {
localAddr := &net.UDPAddr{IP: net.ParseIP(config.Unity.Udp.LocalAddr), Port: config.Unity.Udp.LocalPort}
remoteAddr := &net.UDPAddr{IP: net.ParseIP(config.Unity.Udp.RemoteAddr), Port: config.Unity.Udp.RemotePort}
conn, err := net.DialUDP("udp", localAddr, remoteAddr)
if err != nil {
return err
}
go ConsumeCancelUnityChanMessage(ctx, conn)
go ConsumeCancelUnityChanMessage(conn)
return nil
}
@ -69,18 +68,12 @@ func signMessage(wid string, deadlineTime int64) string {
}
// 消费数据
func ConsumeCancelUnityChanMessage(ctx context.Context, conn *net.UDPConn) {
func ConsumeCancelUnityChanMessage(conn *net.UDPConn) {
defer func() {
if err := recover(); err != nil {
logx.Error("ConsumeCancelUnityChanMessage 异常:", err)
}
}()
go func() {
select {
case <-ctx.Done():
panic(any("ConsumeCancelUnityChanMessage ctx deadline"))
}
}()
defer conn.Close()
for {
select {

View File

@ -1,7 +1,6 @@
package logic
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"sync"
@ -206,18 +205,12 @@ func increaseUnityErrorCount(userId, guestId int64) {
}
// 消费数据
func ConsumeWebsocketStatData(ctx context.Context) {
func ConsumeWebsocketStatData() {
defer func() {
if err := recover(); err != nil {
logx.Error("ConsumeWebsocketStatData panic:", err)
}
}()
go func() {
select {
case <-ctx.Done():
panic(any("ConsumeWebsocketStatData ctx deadline"))
}
}()
for {
select {
case data := <-websocketStat:

View File

@ -1,7 +1,6 @@
package logic
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
)
@ -56,18 +55,12 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
}
// 消费用户索引创建/删除/发送消息中的任务数据
func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
func ConsumeUserConnPoolCtlChanData() {
defer func() {
if err := recover(); err != nil {
logx.Error("ConsumeUserConnPoolCtlChanData panic:", err)
}
}()
go func() {
select {
case <-ctx.Done():
panic(any("ConsumeUserConnPoolCtlChanData ctx deadline"))
}
}()
var (
data userConnPoolCtlChanItem
userKey string

View File

@ -1,7 +1,6 @@
package main
import (
"context"
"flag"
"fmt"
"fusenapi/server/websocket/internal/logic"
@ -30,17 +29,14 @@ func main() {
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
ctx1 := context.Background()
ctx1, cancel := context.WithCancel(ctx1)
defer cancel()
//消费公共通知队列的数据
go logic.ConsumeCommonCacheData(ctx1)
go logic.ConsumeCommonCacheData()
//消费用户索引创建/删除/发送消息中的任务数据
go logic.ConsumeUserConnPoolCtlChanData(ctx1)
go logic.ConsumeUserConnPoolCtlChanData()
//消费连接统计信息
go logic.ConsumeWebsocketStatData(ctx1)
go logic.ConsumeWebsocketStatData()
//拨号udp消费控制unity取消僵尸任务的消息
if err := logic.DialUdp(ctx1, c); err != nil {
if err := logic.DialUdp(c); err != nil {
logx.Error("dail udp err:", err)
return
}