Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/brpc/builtin/connections_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void ConnectionsService::PrintConnections(
if (ret < 0) {
continue;
} else if (ret > 0) {
if (ptr->_health_check_interval_s <= 0) {
if (!ptr->HCEnabled()) {
// Sockets without HC will soon be destroyed
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ int Socket::SetFailed(int error_code, const char* error_fmt, ...) {
// Do health-checking even if we're not connected before, needed
// by Channel to revive never-connected socket when server side
// comes online.
if (_health_check_interval_s > 0) {
if (HCEnabled()) {
bool expect = false;
if (_hc_started.compare_exchange_strong(expect,
true,
Expand Down
6 changes: 5 additions & 1 deletion src/brpc/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,14 @@ friend class policy::H2GlobalStreamCreator;
// ip/port of the other end of the connection.
butil::EndPoint remote_side() const { return _remote_side; }

// Positive value enables health checking.
// Initialized by SocketOptions.health_check_interval_s.
int health_check_interval() const { return _health_check_interval_s; }

// True if health checking is enabled.
bool HCEnabled() const {
return _health_check_interval_s > 0 && _is_hc_related_ref_held;
}

// When someone holds a health-checking-related reference,
// this function need to be called to make health checking run normally.
void SetHCRelatedRefHeld() { _is_hc_related_ref_held = true; }
Expand Down
6 changes: 2 additions & 4 deletions src/brpc/socket_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ SocketMap::~SocketMap() {
for (Map::iterator it = _map.begin(); it != _map.end(); ++it) {
SingleConnection* sc = &it->second;
if ((!sc->socket->Failed() ||
sc->socket->health_check_interval() > 0/*HC enabled*/) &&
sc->socket->HCEnabled()) &&
sc->ref_count != 0) {
++nleft;
if (nleft == 0) {
Expand Down Expand Up @@ -216,9 +216,7 @@ int SocketMap::Insert(const SocketMapKey& key, SocketId* id,
std::unique_lock<butil::Mutex> mu(_mutex);
SingleConnection* sc = _map.seek(key);
if (sc) {
if (!sc->socket->Failed() ||
(sc->socket->health_check_interval() > 0 &&
sc->socket->IsHCRelatedRefHeld())/*HC enabled*/) {
if (!sc->socket->Failed() || sc->socket->HCEnabled()) {
++sc->ref_count;
*id = sc->socket->id();
return 0;
Expand Down