Skip to content

Commit

Permalink
Lock around disconnected_.
Browse files Browse the repository at this point in the history
Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch committed May 15, 2018
1 parent 943aa29 commit 3d5a5f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ std::string FakeRawConnection::waitForData(uint64_t num_bytes) {
}

void FakeRawConnection::write(const std::string& data, bool end_stream) {
std::unique_lock<std::mutex> lock(lock_);
ASSERT_FALSE(disconnected_);
connection_.dispatcher().post([data, end_stream, this]() -> void {
std::unique_lock<std::mutex> lock(lock_);
ASSERT_FALSE(disconnected_);
Buffer::OwnedImpl to_write(data);
connection_.write(to_write, end_stream);
Expand Down
7 changes: 5 additions & 2 deletions test/integration/fake_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,18 @@ class FakeConnectionBase : public Network::ConnectionCallbacks {
connection_.dispatcher().post([this]() -> void { connection_.addConnectionCallbacks(*this); });
}
void enableHalfClose(bool enabled);
bool connected() const { return !disconnected_; }
bool connected() const {
std::unique_lock<std::mutex> lock(lock_);
return !disconnected_;
}

protected:
FakeConnectionBase(QueuedConnectionWrapperPtr connection_wrapper)
: connection_(connection_wrapper->connection()),
connection_wrapper_(std::move(connection_wrapper)) {}

Network::Connection& connection_;
std::mutex lock_;
mutable std::mutex lock_;
std::condition_variable connection_event_;
bool disconnected_{};
bool half_closed_{};
Expand Down

0 comments on commit 3d5a5f5

Please sign in to comment.