保证重复调用Stop不会导致panic
()
| 274 | |
| 275 | // 保证重复调用Stop不会导致panic |
| 276 | func (c *Client) Stop() { |
| 277 | c.Lock() |
| 278 | defer c.Unlock() |
| 279 | if !c.started { |
| 280 | return |
| 281 | } |
| 282 | c.started = false |
| 283 | |
| 284 | con := c.Conn() |
| 285 | if con != nil { |
| 286 | zlog.Ins().InfoF("[STOP] Zinx Client LocalAddr: %s, RemoteAddr: %s\n", con.LocalAddr(), con.RemoteAddr()) |
| 287 | con.Stop() |
| 288 | } |
| 289 | |
| 290 | // c.exitChan <- struct{}{} |
| 291 | // close(c.exitChan) |
| 292 | // close(c.ErrChan) |
| 293 | if c.cancel != nil { |
| 294 | c.cancel() |
| 295 | } |
| 296 | c.Wait() |
| 297 | } |
| 298 | |
| 299 | func (c *Client) AddRouter(msgID uint32, router ziface.IRouter) { |
| 300 | c.msgHandler.AddRouter(msgID, router) |
no test coverage detected