()
| 508 | } |
| 509 | |
| 510 | func (c *Connection) finalizer() { |
| 511 | // Call the callback function registered by the user when closing the connection if it exists |
| 512 | // (如果用户注册了该连接的 关闭回调业务,那么在此刻应该显示调用) |
| 513 | c.callOnConnStop() |
| 514 | |
| 515 | // Stop the heartbeat detector associated with the connection |
| 516 | if c.hc != nil { |
| 517 | c.hc.Stop() |
| 518 | } |
| 519 | |
| 520 | // Close the socket connection |
| 521 | _ = c.conn.Close() |
| 522 | |
| 523 | // Remove the connection from the connection manager |
| 524 | if c.connManager != nil { |
| 525 | c.connManager.Remove(c) |
| 526 | } |
| 527 | |
| 528 | go func() { |
| 529 | defer func() { |
| 530 | if err := recover(); err != nil { |
| 531 | zlog.Ins().ErrorF("Conn finalizer panic: %v", err) |
| 532 | } |
| 533 | }() |
| 534 | |
| 535 | c.InvokeCloseCallbacks() |
| 536 | }() |
| 537 | |
| 538 | zlog.Ins().InfoF("Conn Stop()...ConnID = %d", c.connID) |
| 539 | } |
| 540 | |
| 541 | func (c *Connection) callOnConnStart() { |
| 542 | if c.onConnStart != nil { |
no test coverage detected