-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
- Replace throwing/error_code overload pairs with system::result<void> - Replace multiple signal constructors with variadic template - Add error checking for signal() calls when restoring SIG_DFL - Fix signal validation to allow signal 0
📝 WalkthroughWalkthroughThis pull request refactors the signal_set API to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
|
An automated preview of the documentation is available at https://38.corosio.prtest3.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-01-20 23:12:54 UTC |
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/corosio/src/detail/posix/signals.cpp (1)
292-337: Alignremove_signalerror handling withclear_signalsto prevent resource leak.
remove_signalreturns early when SIG_DFL restore fails (line 318–320), leaving the registration undeleted and data structures in an incomplete state.clear_signalscaptures the error and continues cleanup, only returning the error afterward. This inconsistency causes a resource leak in the error path ofremove_signal.Capture the signal restoration error instead of returning early, proceed with cleanup (including deleting
reg), and return the error at the end to matchclear_signalsbehavior.♻️ Proposed adjustment
+ system::error_code first_error; if (state->registration_count[signal_number] == 1) { if (::signal(signal_number, SIG_DFL) == SIG_ERR) - return make_error_code(system::errc::invalid_argument); + first_error = make_error_code(system::errc::invalid_argument); } *deletion_point = reg->next_in_set; if (registrations_[signal_number] == reg) registrations_[signal_number] = reg->next_in_table; if (reg->prev_in_table) reg->prev_in_table->next_in_table = reg->next_in_table; if (reg->next_in_table) reg->next_in_table->prev_in_table = reg->prev_in_table; --state->registration_count[signal_number]; --registration_count_[signal_number]; delete reg; + if (first_error) + return first_error; return {};
🧹 Nitpick comments (1)
test/unit/signal_set.cpp (1)
116-138: Tests correctly updated for result-based API.The tests properly use
has_value()andhas_error()to verify the newsystem::result<void>return types. The coverage for add/duplicate/invalid scenarios is good.One observation: the PR mentions "Fix signal validation to allow signal 0", but there's no test case verifying that
add(0)now succeeds. Consider adding a test to confirm this fix:void testAddSignalZero() { io_context ioc; signal_set s(ioc); // Signal 0 should now be valid auto result = s.add(0); BOOST_TEST(result.has_value()); }
| corosio::tls::context ctx; | ||
| ctx.set_hostname(hostname); | ||
| ctx.set_default_verify_paths().value(); | ||
| ctx.set_verify_mode(corosio::tls::verify_mode::peer).value(); |
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
| int signal_number_2, | ||
| int signal_number_3); | ||
| int signal, | ||
| Signals... signals) |
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.
Why even keep this though? Do we like it?
| ::signal(signal_number, SIG_DFL); | ||
| { | ||
| if (::signal(signal_number, SIG_DFL) == SIG_ERR) | ||
| return make_error_code(system::errc::invalid_argument); |
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.
would this also work:
return system::errc::invalid_argument;
| ::signal(signal_number, SIG_DFL); | ||
| { | ||
| if (::signal(signal_number, SIG_DFL) == SIG_ERR && !first_error) | ||
| first_error = make_error_code(system::errc::invalid_argument); |
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.
would this work
first_error = system::errc::invalid_argument;
Resolves #28.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.