```
feat(socket): 添加服务器优雅退出机制 在 Server 结构体中新增 quit 字段,并在 OnTick 方法中检查该字段, 若为 true 则调用 os.Exit(0) 实现程序正常退出。同时清理了 controller 中 冗余的导入和无用逻辑,优化 server 启动流程并修复 RPC 客户端传递错误问题。 ```
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -60,6 +61,10 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
||||
}
|
||||
func (s *Server) OnTick() (delay time.Duration, action gnet.Action) {
|
||||
cool.Loger.Infof(context.Background(), "[connected-count=%v]", atomic.LoadInt64(&s.connected))
|
||||
if s.quit {
|
||||
//执行正常退出逻辑
|
||||
os.Exit(0)
|
||||
}
|
||||
return 10 * time.Second, gnet.None
|
||||
}
|
||||
func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
|
||||
|
||||
Reference in New Issue
Block a user