clearConn is used to clear any cached connection, potentially in response to an erro
(conn *conn)
| 271 | |
| 272 | // clearConn is used to clear any cached connection, potentially in response to an erro |
| 273 | func (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 |
| 291 | func (p *connPool) releaseConn(conn *conn) { |