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

Method ListSockets

src/brpc/socket.cpp:2673–2695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2671}
2672
2673inline void SocketPool::ListSockets(std::vector<SocketId>* out, size_t max_count) {
2674 out->clear();
2675 // NOTE: size() of vector is thread-unsafe and may return a very
2676 // large value during resizing.
2677 _mutex.lock();
2678 size_t expected_size = _pool.size();
2679 if (max_count > 0 && max_count < _pool.size()) {
2680 expected_size = max_count;
2681 }
2682 if (out->capacity() < expected_size) {
2683 _mutex.unlock();
2684 out->reserve(expected_size + 4); // pool may add sockets.
2685 _mutex.lock();
2686 }
2687 if (max_count == 0) {
2688 out->insert(out->end(), _pool.begin(), _pool.end());
2689 } else {
2690 for (size_t i = 0; i < expected_size; ++i) {
2691 out->push_back(_pool[i]);
2692 }
2693 }
2694 _mutex.unlock();
2695}
2696
2697Socket::SharedPart* Socket::GetOrNewSharedPartSlower() {
2698 // Create _shared_part optimistically.

Callers 2

DebugSocketMethod · 0.80
ListPooledSocketsMethod · 0.80

Calls 10

clearMethod · 0.45
lockMethod · 0.45
sizeMethod · 0.45
capacityMethod · 0.45
unlockMethod · 0.45
reserveMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected