(dst []Connection)
| 314 | } |
| 315 | |
| 316 | func (pool *Pool) getOldIdleConnections(dst []Connection) []Connection { |
| 317 | dst = dst[:0] |
| 318 | |
| 319 | pool.synchro.Lock() |
| 320 | |
| 321 | synchro := &pool.synchro |
| 322 | |
| 323 | idleCnt := len(synchro.idleConnections) |
| 324 | checkBefore := pool.nowTs() - pool.idlePingTimeout |
| 325 | |
| 326 | for i := idleCnt - 1; i >= 0; i-- { |
| 327 | if synchro.idleConnections[i].lastUseAt > checkBefore { |
| 328 | continue |
| 329 | } |
| 330 | |
| 331 | dst = append(dst, synchro.idleConnections[i]) |
| 332 | |
| 333 | last := idleCnt - 1 |
| 334 | if i < last { |
| 335 | // Removing an item from the middle of a slice |
| 336 | synchro.idleConnections[i], synchro.idleConnections[last] = synchro.idleConnections[last], synchro.idleConnections[i] |
| 337 | } |
| 338 | |
| 339 | synchro.idleConnections[last].conn = nil |
| 340 | synchro.idleConnections = synchro.idleConnections[:last] |
| 341 | idleCnt-- |
| 342 | } |
| 343 | |
| 344 | pool.synchro.Unlock() |
| 345 | |
| 346 | return dst |
| 347 | } |
| 348 | |
| 349 | func (pool *Pool) recheckConnections(connections []Connection) { |
| 350 | const workerCnt = 2 // Heuristic :) |
no test coverage detected