-
Notifications
You must be signed in to change notification settings - Fork 7
Simplify signal_set API with result-based error handling #38
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ | |
| #include <boost/capy/concept/io_awaitable.hpp> | ||
| #include <boost/capy/concept/executor.hpp> | ||
| #include <boost/system/error_code.hpp> | ||
| #include <boost/system/result.hpp> | ||
|
|
||
| #include <concepts> | ||
| #include <coroutine> | ||
| #include <stop_token> | ||
|
|
||
|
|
@@ -73,15 +75,6 @@ class BOOST_COROSIO_DECL signal_set : public io_object | |
| return {ec_, signal_number_}; | ||
| } | ||
|
|
||
| template<typename Ex> | ||
| auto await_suspend( | ||
| std::coroutine_handle<> h, | ||
| Ex const& ex) -> std::coroutine_handle<> | ||
| { | ||
| s_.get().wait(h, ex, token_, &ec_, &signal_number_); | ||
| return std::noop_coroutine(); | ||
| } | ||
|
|
||
| template<typename Ex> | ||
| auto await_suspend( | ||
| std::coroutine_handle<> h, | ||
|
|
@@ -104,61 +97,42 @@ class BOOST_COROSIO_DECL signal_set : public io_object | |
| system::error_code*, | ||
| int*) = 0; | ||
|
|
||
| virtual system::error_code add(int signal_number) = 0; | ||
| virtual system::error_code remove(int signal_number) = 0; | ||
| virtual system::error_code clear() = 0; | ||
| virtual system::result<void> add(int signal_number) = 0; | ||
| virtual system::result<void> remove(int signal_number) = 0; | ||
| virtual system::result<void> clear() = 0; | ||
| virtual void cancel() = 0; | ||
| }; | ||
|
|
||
| public: | ||
| /** Destructor. | ||
|
|
||
| Cancels any pending operations and releases signal resources. | ||
| */ | ||
| ~signal_set(); | ||
|
|
||
| /** Construct a signal set without adding any signals. | ||
| /** Construct an empty signal set. | ||
|
|
||
| @param ctx The execution context that will own this signal set. | ||
| */ | ||
| explicit signal_set(capy::execution_context& ctx); | ||
|
|
||
| /** Construct a signal set and add one signal. | ||
|
|
||
| @param ctx The execution context that will own this signal set. | ||
| @param signal_number_1 The signal number to be added. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| */ | ||
| signal_set(capy::execution_context& ctx, int signal_number_1); | ||
|
|
||
| /** Construct a signal set and add two signals. | ||
| /** Construct a signal set with initial signals. | ||
|
|
||
| @param ctx The execution context that will own this signal set. | ||
| @param signal_number_1 The first signal number to be added. | ||
| @param signal_number_2 The second signal number to be added. | ||
| @param signal First signal number to add. | ||
| @param signals Additional signal numbers to add. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| */ | ||
| template<std::convertible_to<int>... Signals> | ||
| signal_set( | ||
| capy::execution_context& ctx, | ||
| int signal_number_1, | ||
| int signal_number_2); | ||
|
|
||
| /** Construct a signal set and add three signals. | ||
|
|
||
| @param ctx The execution context that will own this signal set. | ||
| @param signal_number_1 The first signal number to be added. | ||
| @param signal_number_2 The second signal number to be added. | ||
| @param signal_number_3 The third signal number to be added. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| */ | ||
| signal_set( | ||
| capy::execution_context& ctx, | ||
| int signal_number_1, | ||
| int signal_number_2, | ||
| int signal_number_3); | ||
| int signal, | ||
| Signals... signals) | ||
|
Member
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. Why even keep this though? Do we like it? |
||
| : signal_set(ctx) | ||
| { | ||
| add(signal).value(); | ||
| (add(signals).value(), ...); | ||
| } | ||
|
|
||
| /** Move constructor. | ||
|
|
||
|
|
@@ -192,19 +166,9 @@ class BOOST_COROSIO_DECL signal_set : public io_object | |
|
|
||
| @param signal_number The signal to be added to the set. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| @return Success, or an error if the signal could not be added. | ||
| */ | ||
| void add(int signal_number); | ||
|
|
||
| /** Add a signal to the signal set. | ||
|
|
||
| This function adds the specified signal to the set. It has no | ||
| effect if the signal is already in the set. | ||
|
|
||
| @param signal_number The signal to be added to the set. | ||
| @param ec Set to indicate what error occurred, if any. | ||
| */ | ||
| void add(int signal_number, system::error_code& ec); | ||
| system::result<void> add(int signal_number); | ||
|
|
||
| /** Remove a signal from the signal set. | ||
|
|
||
|
|
@@ -213,37 +177,18 @@ class BOOST_COROSIO_DECL signal_set : public io_object | |
|
|
||
| @param signal_number The signal to be removed from the set. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| */ | ||
| void remove(int signal_number); | ||
|
|
||
| /** Remove a signal from the signal set. | ||
|
|
||
| This function removes the specified signal from the set. It has | ||
| no effect if the signal is not in the set. | ||
|
|
||
| @param signal_number The signal to be removed from the set. | ||
| @param ec Set to indicate what error occurred, if any. | ||
| */ | ||
| void remove(int signal_number, system::error_code& ec); | ||
|
|
||
| /** Remove all signals from the signal set. | ||
|
|
||
| This function removes all signals from the set. It has no effect | ||
| if the set is already empty. | ||
|
|
||
| @throws boost::system::system_error Thrown on failure. | ||
| @return Success, or an error if the signal could not be removed. | ||
| */ | ||
| void clear(); | ||
| system::result<void> remove(int signal_number); | ||
|
|
||
| /** Remove all signals from the signal set. | ||
|
|
||
| This function removes all signals from the set. It has no effect | ||
| if the set is already empty. | ||
|
|
||
| @param ec Set to indicate what error occurred, if any. | ||
| @return Success, or an error if resetting any signal handler fails. | ||
| */ | ||
| void clear(system::error_code& ec); | ||
| system::result<void> clear(); | ||
|
|
||
| /** Cancel all operations associated with the signal set. | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is really cool