MCPcopy Create free account
hub / github.com/dadgar/onecache / clearConn

Method clearConn

onecache/pool.go:273–288  ·  view source on GitHub ↗

clearConn is used to clear any cached connection, potentially in response to an erro

(conn *conn)

Source from the content-addressed store, hash-verified

271
272// clearConn is used to clear any cached connection, potentially in response to an erro
273func (p *connPool) clearConn(conn *conn) {
274 // Ensure returned streams are closed
275 atomic.StoreInt32(&conn.shouldClose, 1)
276
277 // Clear from the cache
278 p.Lock()
279 if c, ok := p.pool[conn.addr.String()]; ok && c == conn {
280 delete(p.pool, conn.addr.String())
281 }
282 p.Unlock()
283
284 // Close down immediately if idle
285 if refCount := atomic.LoadInt32(&conn.refCount); refCount == 0 {
286 conn.Close()
287 }
288}
289
290// releaseConn is invoked when we are done with a conn to reduce the ref count
291func (p *connPool) releaseConn(conn *conn) {

Callers 1

getClientMethod · 0.95

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected