diff --git a/include/ert/http2comm/Stream.hpp b/include/ert/http2comm/Stream.hpp index 9f943aa..4285063 100644 --- a/include/ert/http2comm/Stream.hpp +++ b/include/ert/http2comm/Stream.hpp @@ -40,6 +40,7 @@ SOFTWARE. #pragma once #include +#include #include #include #include @@ -80,7 +81,7 @@ class Stream : public std::enable_shared_from_this const nghttp2::asio_http2::server::response& res_; std::shared_ptr request_; Http2Server *server_; - bool closed_; + std::shared_ptr closed_; std::chrono::microseconds reception_us_{}; // timestamp in microsecods // Completes the nghttp2 transaction (res.end()) @@ -96,8 +97,9 @@ class Stream : public std::enable_shared_from_this Http2Server *server) : req_(req), res_(res), request_(request), - server_(server), - closed_(false) {} + server_(server) { + closed_ = std::make_shared (false); + } Stream(const Stream&) = delete; ~Stream() = default; Stream& operator=(const Stream&) = delete; diff --git a/src/Stream.cpp b/src/Stream.cpp index 1ccb1df..50038ce 100644 --- a/src/Stream.cpp +++ b/src/Stream.cpp @@ -181,7 +181,7 @@ void Stream::commit(unsigned int statusCode, self->res_.io_service().post([self, statusCode, headers, responseBody]() { std::lock_guard lg(self->mutex_); - if (self->closed_) + if (self->closed_->load()) { return; } @@ -197,8 +197,7 @@ void Stream::commit(unsigned int statusCode, void Stream::close() { - std::lock_guard guard(mutex_); - closed_ = true; + closed_->store(true); } }