-
Notifications
You must be signed in to change notification settings - Fork 9
test stream write cancellation support and beast2::write tests #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,9 @@ class write_some_op | |
|
|
||
| BOOST_ASIO_CORO_REENTER(*this) | ||
| { | ||
| self.reset_cancellation_state( | ||
| asio::enable_total_cancellation()); | ||
|
|
||
| rv = sr_.prepare(); | ||
| if(! rv) | ||
| { | ||
|
|
@@ -82,6 +85,9 @@ class write_some_op | |
| } | ||
| sr_.consume(bytes_transferred); | ||
|
|
||
| if(!!self.cancelled() && !sr_.is_done()) | ||
| ec = asio::error::operation_aborted; | ||
|
|
||
| upcall: | ||
| self.complete( | ||
| ec, bytes_transferred ); | ||
|
|
@@ -128,6 +134,10 @@ class write_op | |
| dest_, sr_, std::move(self)); | ||
| } | ||
| n_ += bytes_transferred; | ||
|
|
||
| if(!!self.cancelled() && ! sr_.is_done()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this condition should go before
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point about the network errors, thank you.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| ec = asio::error::operation_aborted; | ||
|
|
||
| if(ec.failed()) | ||
| break; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,15 @@ struct stream_read_op_base | |
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
||
| struct stream_write_op_base | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this change to |
||
| { | ||
| virtual ~stream_write_op_base() = default; | ||
| virtual void | ||
| operator()(system::error_code ec) = 0; | ||
| }; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
||
| enum class stream_status | ||
| { | ||
| ok, | ||
|
|
@@ -89,8 +98,9 @@ struct stream_state | |
| std::mutex m; | ||
| std::string storage; | ||
| buffers::string_buffer b; | ||
| std::condition_variable cv; | ||
| std::unique_ptr<stream_read_op_base> op; | ||
| //std::condition_variable cv; | ||
| std::unique_ptr<stream_read_op_base> rop; | ||
| std::unique_ptr<stream_write_op_base> wop; | ||
| stream_status code = stream_status::ok; | ||
| fail_count* fc = nullptr; | ||
| std::size_t nread = 0; | ||
|
|
@@ -139,7 +149,7 @@ shutdown() | |
| for(auto p : sp_->v_) | ||
| { | ||
| std::lock_guard<std::mutex> g2(p->m); | ||
| v.emplace_back(std::move(p->op)); | ||
| v.emplace_back(std::move(p->rop)); | ||
| p->code = detail::stream_status::eof; | ||
| } | ||
| } | ||
|
|
@@ -200,8 +210,11 @@ stream_state:: | |
| ~stream_state() | ||
| { | ||
| // cancel outstanding read | ||
| if(op != nullptr) | ||
| (*op)(asio::error::operation_aborted); | ||
| if(rop != nullptr) | ||
| (*rop)(asio::error::operation_aborted); | ||
| // cancel outstanding write | ||
| if(wop != nullptr) | ||
| (*wop)(asio::error::operation_aborted); | ||
| } | ||
|
|
||
| inline | ||
|
|
@@ -223,16 +236,13 @@ void | |
| stream_state:: | ||
| notify_read() | ||
| { | ||
| if(op) | ||
| if(rop) | ||
| { | ||
| auto op_ = std::move(op); | ||
| auto op_ = std::move(rop); | ||
| op_->operator()(system::error_code{}); | ||
| } | ||
| else | ||
| { | ||
| cv.notify_all(); | ||
| } | ||
| } | ||
|
|
||
| } // detail | ||
| } // test | ||
| } // beast2 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition seems unnecessary, since we are not looping for another write, it doesn't matter whether
async_write_somecompletes after the cancellation or before it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it because, without this check, the following test does not produce the expected value of ec:
https://github.com/cppalliance/beast2/pull/102/files#diff-13a376592ec7d2e701ab2d597d68a2344c77761e8020e060f4eafdc2a1b39ea1R166-R200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link doesn’t work (it doesn’t point to a line number), but I guess the issue is related to the fact that
async_write_someontest::streamcompletes immediately and there’s currently no way to prevent that. If that’s the case, we need a mechanism intest::streamto limit the read buffer so that even the firstasync_write_somedoesn’t complete immediately.