MCPcopy
hub / github.com/aceld/zinx / finalizer

Method finalizer

znet/ws_connection.go:513–563  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

511}
512
513func (c *WsConnection) finalizer() {
514 // If the user has registered a close callback for the connection, it should be called explicitly at this moment.
515 // (如果用户注册了该连接的 关闭回调业务,那么在此刻应该显示调用)
516 c.callOnConnStop()
517
518 c.msgLock.Lock()
519 defer c.msgLock.Unlock()
520
521 // If the current connection is already closed.
522 // (如果当前连接已经关闭)
523 if c.isClosed == true {
524 return
525 }
526
527 // Stop the heartbeat detector bound to the connection.
528 // (关闭连接绑定的心跳检测器)
529 if c.hc != nil {
530 c.hc.Stop()
531 }
532
533 // Close the socket connection.
534 // (关闭socket连接)
535 _ = c.conn.Close()
536
537 // Remove the connection from the connection manager.
538 // (将连接从连接管理器中删除)
539 if c.connManager != nil {
540 c.connManager.Remove(c)
541 }
542
543 // Close all channels associated with this connection.
544 // (关闭该连接全部管道)
545 if c.msgBuffChan != nil {
546 close(c.msgBuffChan)
547 }
548
549 // Set the flag to indicate that the connection is closed. (设置标志位)
550 c.isClosed = true
551
552 go func() {
553 defer func() {
554 if err := recover(); err != nil {
555 zlog.Ins().ErrorF("Conn finalizer panic: %v", err)
556 }
557 }()
558
559 c.InvokeCloseCallbacks()
560 }()
561
562 zlog.Ins().InfoF("Conn Stop()...ConnID = %d", c.connID)
563}
564
565func (c *WsConnection) callOnConnStart() {
566 if c.onConnStart != nil {

Callers 1

StartMethod · 0.95

Calls 8

callOnConnStopMethod · 0.95
InvokeCloseCallbacksMethod · 0.95
InsFunction · 0.92
CloseMethod · 0.80
StopMethod · 0.65
RemoveMethod · 0.65
ErrorFMethod · 0.65
InfoFMethod · 0.65

Tested by

no test coverage detected