feat(socket): 优化TCP连接处理逻辑并引入批量读取机制

- 在 `ServerEvent.go` 中调整了 `OnTraffic` 方法的处理逻辑,
  避免不必要的循环,确保跨域请求优先处理。
- 新增 `batchRead` 配置项,用于控制单次处理的最大数据包数量,
 默认值设为 10。
- 修复 `OnClose` 方法中可能存在的执行顺序问题,并显式关闭 Lockfree 资源。
- 在 `ClientData` 初始化时,将 Lockfree 的阻塞策略从 Sleep 策略
  替换为 ConditionBlock 策略,提升并发处理性能。
- 微调玩家登录完成时的地图ID判断条件,由 1000
This commit is contained in:
2025-10-29 03:19:32 +08:00
parent c0f22cb208
commit f06638d6b6
3 changed files with 15 additions and 10 deletions

View File

@@ -24,6 +24,7 @@ type Server struct {
handler Handler
discorse bool
quit bool
batchRead int
}
type Option func(*Server)
@@ -37,6 +38,7 @@ func NewServer(options ...Option) *Server {
workerPool: goroutine.Default(),
bufferSize: 4096, //默认缓冲区大小
multicore: true,
batchRead: 10,
//discorse: true,
}
for _, option := range options {