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

Method finalizer

znet/kcp_connection.go:502–549  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

500}
501
502func (c *KcpConnection) finalizer() {
503 // If the connection has already been closed
504 if c.isClosed() == true {
505 return
506 }
507
508 //set closed
509 if !c.setClose() {
510 return
511 }
512
513 // Call the callback function registered by the user when closing the connection if it exists
514 //(如果用户注册了该连接的 关闭回调业务,那么在此刻应该显示调用)
515 c.callOnConnStop()
516
517 c.msgLock.Lock()
518 defer c.msgLock.Unlock()
519
520 // Stop the heartbeat detector associated with the connection
521 if c.hc != nil {
522 c.hc.Stop()
523 }
524
525 // Close the socket connection
526 _ = c.conn.Close()
527
528 // Remove the connection from the connection manager
529 if c.connManager != nil {
530 c.connManager.Remove(c)
531 }
532
533 // Close all channels associated with the connection
534 if c.msgBuffChan != nil {
535 close(c.msgBuffChan)
536 }
537
538 go func() {
539 defer func() {
540 if err := recover(); err != nil {
541 zlog.Ins().ErrorF("Conn finalizer panic: %v", err)
542 }
543 }()
544
545 c.InvokeCloseCallbacks()
546 }()
547
548 zlog.Ins().DebugF("Conn Stop()...ConnID = %d", c.connID)
549}
550
551func (c *KcpConnection) callOnConnStart() {
552 if c.onConnStart != nil {

Callers 1

StartMethod · 0.95

Calls 10

isClosedMethod · 0.95
setCloseMethod · 0.95
callOnConnStopMethod · 0.95
InvokeCloseCallbacksMethod · 0.95
InsFunction · 0.92
CloseMethod · 0.80
StopMethod · 0.65
RemoveMethod · 0.65
ErrorFMethod · 0.65
DebugFMethod · 0.65

Tested by

no test coverage detected