| 2653 | } |
| 2654 | |
| 2655 | inline void SocketPool::ReturnSocket(Socket* sock) { |
| 2656 | // NOTE: save the gflag which may be reloaded at any time. |
| 2657 | const int connection_pool_size = FLAGS_max_connection_pool_size; |
| 2658 | |
| 2659 | // Check if the pool is full. |
| 2660 | if (_numfree.fetch_add(1, butil::memory_order_relaxed) < |
| 2661 | connection_pool_size) { |
| 2662 | const SocketId sid = sock->id(); |
| 2663 | BAIDU_SCOPED_LOCK(_mutex); |
| 2664 | _pool.push_back(sid); |
| 2665 | } else { |
| 2666 | // Cancel the addition and close the pooled socket. |
| 2667 | _numfree.fetch_sub(1, butil::memory_order_relaxed); |
| 2668 | sock->SetFailed(EUNUSED, "Close unused pooled socket"); |
| 2669 | } |
| 2670 | _numinflight.fetch_sub(1, butil::memory_order_relaxed); |
| 2671 | } |
| 2672 | |
| 2673 | inline void SocketPool::ListSockets(std::vector<SocketId>* out, size_t max_count) { |
| 2674 | out->clear(); |