MCPcopy Create free account
hub / github.com/apache/brpc / ReturnSocket

Method ReturnSocket

src/brpc/socket.cpp:2655–2671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2653}
2654
2655inline 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
2673inline void SocketPool::ListSockets(std::vector<SocketId>* out, size_t max_count) {
2674 out->clear();

Callers 1

ReturnToPoolMethod · 0.80

Calls 5

fetch_addMethod · 0.80
fetch_subMethod · 0.80
idMethod · 0.45
push_backMethod · 0.45
SetFailedMethod · 0.45

Tested by

no test coverage detected