name5566 / leaf

A game server framework in Go (golang)
Apache License 2.0
5.26k stars 1.31k forks source link

关闭回调太慢问题? #169

Closed android-coco closed 4 years ago

name5566 commented 4 years ago

关闭慢是有原因的,具体原因具体分析,但不是框架的原因,而是业务逻辑的需要。比如说,有一些情况下需要等待消息发送成功后才断了网络,这可能会比较慢,当然可以选择强制断开而不等待数据成功发送(这比较快)。如果你说的关闭是服务器关闭,那么服务器还需要等待数据入库等操作完成(否则数据会丢失),这都是比较慢的。

android-coco commented 4 years ago

我可能描述的有问题,我重新加一个说明: 1,我先定义了注册了一个关闭的回调,或者是所谓的RPC函数 skeleton.RegisterChanRPC("CloseAgent", rpcCloseAgent)

func rpcCloseAgent(args []interface{}) { fmt.Print("======rpcCloseAgent1=====") }

2, 当我调用 oldAgent.Close() rpcCloseAgent函数有执行,但是是在Close之后的逻辑执行完之后 例如: oldAgent.Close() fmt.Println("======rpcCloseAgent2=====") 运行结果输出: ======rpcCloseAgent2===== ======rpcCloseAgent1===== 想输出 ======rpcCloseAgent1===== ======rpcCloseAgent2=====

3,通过对源码的查看Close()实现为:

func (a agent) Close() { a.conn.Close() } rpc调用的实现为: func (a agent) OnClose() { if a.gate.AgentChanRPC != nil { err := a.gate.AgentChanRPC.Call0("CloseAgent", a) if err != nil { .... } } } 看到这个我想把OnClose() ,Close()调用修如下(发现会卡死): func (a *agent) Close() { a.OnClose() //新加 a.conn.Close() } 4,所以请问怎么样让rpcCloseAgent函数和Close方法同步执行达到 ======rpcCloseAgent1===== ======rpcCloseAgent2===== 的效果

name5566 commented 4 years ago

按需要增加 myOnClose

android-coco commented 4 years ago

按需要增加 myOnClose

搞定了,谢谢