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