Close BaseEndpointChannel once

Closing the bluetoth socket and streams more than once is wasteful and error prone.

PiperOrigin-RevId: 549964135
This commit is contained in:
Janusz Sobczak
2023-07-21 09:12:05 -07:00
committed by Copybara-Service
parent e0b9ad2c2d
commit 2c08cfc9e8
2 changed files with 6 additions and 0 deletions
@@ -265,6 +265,11 @@ void BaseEndpointChannel::Close() {
{
// In case channel is paused, resume it first thing.
MutexLock lock(&is_paused_mutex_);
if (is_closed_) {
NEARBY_LOGS(VERBOSE) << "EndpointChannel already closed";
return;
}
is_closed_ = true;
UnblockPausedWriter();
}
CloseIo();
@@ -130,6 +130,7 @@ class BaseEndpointChannel : public EndpointChannel {
ConditionVariable is_paused_cond_{&is_paused_mutex_};
// If true, writes should block until this has been set to false.
bool is_paused_ ABSL_GUARDED_BY(is_paused_mutex_) = false;
bool is_closed_ ABSL_GUARDED_BY(is_paused_mutex_) = false;
// The medium technology information of this endpoint channel.
location::nearby::proto::connections::ConnectionTechnology technology_;