MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / CloseIPConns

Method CloseIPConns

internal/conns/map.go:75–105  ·  view source on GitHub ↗
(ip string)

Source from the content-addressed store, hash-verified

73}
74
75func (this *Map) CloseIPConns(ip string) {
76 var conns = []net.Conn{}
77
78 this.locker.RLock()
79 connMap, ok := this.m[ip]
80
81 // 复制,防止在Close时产生并发冲突
82 if ok {
83 for _, conn := range connMap {
84 conns = append(conns, conn)
85 }
86 }
87
88 // 需要在Close之前结束,防止死循环
89 this.locker.RUnlock()
90
91 if ok {
92 for _, conn := range conns {
93 // 设置Linger
94 lingerConn, isLingerConn := conn.(LingerConn)
95 if isLingerConn {
96 _ = lingerConn.SetLinger(0)
97 }
98
99 // 关闭
100 _ = conn.Close()
101 }
102
103 // 这里不需要从 m 中删除,因为关闭时会自然触发回调
104 }
105}
106
107func (this *Map) AllConns() []net.Conn {
108 this.locker.RLock()

Callers 5

listenSockMethod · 0.80
initMethod · 0.80
DropSourceIPMethod · 0.80
DropSourceIPMethod · 0.80
RecordIPMethod · 0.80

Calls 4

RLockMethod · 0.80
RUnlockMethod · 0.80
SetLingerMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected