@@ -66,9 +66,9 @@ class stream_service
6666
6767// ------------------------------------------------------------------------------
6868
69- struct stream_read_op_base
69+ struct stream_op_base
7070{
71- virtual ~stream_read_op_base () = default ;
71+ virtual ~stream_op_base () = default ;
7272 virtual void operator ()(system::error_code ec) = 0;
7373};
7474
@@ -89,8 +89,9 @@ struct stream_state
8989 std::mutex m;
9090 std::string storage;
9191 buffers::string_buffer b;
92- std::condition_variable cv;
93- std::unique_ptr<stream_read_op_base> op;
92+ // std::condition_variable cv;
93+ std::unique_ptr<stream_op_base> rop;
94+ std::unique_ptr<stream_op_base> wop;
9495 stream_status code = stream_status::ok;
9596 fail_count* fc = nullptr ;
9697 std::size_t nread = 0 ;
@@ -133,14 +134,17 @@ void
133134stream_service::
134135shutdown ()
135136{
136- std::vector<std::unique_ptr<detail::stream_read_op_base>> v;
137- std::lock_guard<std::mutex> g1 (sp_->m_ );
138- v.reserve (sp_->v_ .size ());
139- for (auto p : sp_->v_ )
137+ std::vector<std::unique_ptr<detail::stream_op_base>> v;
140138 {
141- std::lock_guard<std::mutex> g2 (p->m );
142- v.emplace_back (std::move (p->op ));
143- p->code = detail::stream_status::eof;
139+ std::lock_guard<std::mutex> g1 (sp_->m_ );
140+ v.reserve (2 * sp_->v_ .size ());
141+ for (auto p : sp_->v_ )
142+ {
143+ std::lock_guard<std::mutex> g2 (p->m );
144+ v.emplace_back (std::move (p->rop ));
145+ v.emplace_back (std::move (p->wop ));
146+ p->code = detail::stream_status::eof;
147+ }
144148 }
145149}
146150
@@ -200,8 +204,11 @@ stream_state::
200204~stream_state ()
201205{
202206 // cancel outstanding read
203- if (op != nullptr )
204- (*op)(asio::error::operation_aborted);
207+ if (rop != nullptr )
208+ (*rop)(asio::error::operation_aborted);
209+ // cancel outstanding write
210+ if (wop != nullptr )
211+ (*wop)(asio::error::operation_aborted);
205212}
206213
207214inline
@@ -223,16 +230,13 @@ void
223230stream_state::
224231notify_read ()
225232{
226- if (op )
233+ if (rop )
227234 {
228- auto op_ = std::move (op );
235+ auto op_ = std::move (rop );
229236 op_->operator ()(system::error_code{});
230237 }
231- else
232- {
233- cv.notify_all ();
234- }
235238}
239+
236240} // detail
237241} // test
238242} // beast2
0 commit comments