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

Method ReturnToPool

src/brpc/socket.cpp:2767–2797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2765}
2766
2767int Socket::ReturnToPool() {
2768 SharedPart* sp = _shared_part.exchange(NULL, butil::memory_order_acquire);
2769 if (sp == NULL) {
2770 LOG(ERROR) << "_shared_part is NULL";
2771 SetFailed(EINVAL, "_shared_part is NULL");
2772 return -1;
2773 }
2774 SocketPool* pool = sp->socket_pool.load(butil::memory_order_consume);
2775 if (pool == NULL) {
2776 LOG(ERROR) << "_shared_part->socket_pool is NULL";
2777 SetFailed(EINVAL, "_shared_part->socket_pool is NULL");
2778 sp->RemoveRefManually();
2779 return -1;
2780 }
2781 CHECK(parsing_context() == NULL)
2782 << "context=" << parsing_context() << " is not released when "
2783 << *this << " is returned to SocketPool, the protocol "
2784 "implementation is buggy";
2785 // NOTE: be careful with the sequence.
2786 // - related fields must be reset before returning to pool
2787 // - sp must be released after returning to pool because it owns pool
2788 _connection_type_for_progressive_read = CONNECTION_TYPE_UNKNOWN;
2789 _controller_released_socket.store(false, butil::memory_order_relaxed);
2790 // Reset the write timestamp to make the returned connection live (longer)
2791 // This is useful for using a fake Socket + SocketConnection impl. to integrate
2792 // 3rd-party client into bRPC (like MySQL Client).
2793 _last_writetime_us.store(butil::cpuwide_time_us(), butil::memory_order_relaxed);
2794 pool->ReturnSocket(this);
2795 sp->RemoveRefManually();
2796 return 0;
2797}
2798
2799bool Socket::HasSocketPool() const {
2800 SharedPart* sp = GetSharedPart();

Callers 2

TEST_FFunction · 0.80
OnCompleteMethod · 0.80

Calls 7

parsing_contextFunction · 0.85
cpuwide_time_usFunction · 0.85
ReturnSocketMethod · 0.80
exchangeMethod · 0.45
loadMethod · 0.45
RemoveRefManuallyMethod · 0.45
storeMethod · 0.45

Tested by 1

TEST_FFunction · 0.64