Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking issues in flag propagation, fallback handling, or the regression test; tests were not executed during review.
No open issues 🎉
What changed in this PR
This PR reduces Linux connection-accept overhead by setting socket flags through accept4(), while preserving existing behavior on other platforms and older Linux kernels.
Changes:
- Use
accept4()with non-blocking and close-on-exec flags, falling back toaccept()onENOSYS. - Pass known descriptor flags through socket initialization to avoid redundant flag-setting calls.
- Add a Linux-only regression test for accepted socket flags.
| File | Description |
|---|---|
test/brpc_socket_unittest.cpp |
Verify accepted sockets have both required flags on Linux. |
src/brpc/socket.h |
Declare flag-aware socket initialization interfaces. |
src/brpc/socket.cpp |
Skip flag-setting calls when flags are already set. |
src/brpc/acceptor.cpp |
Use accept4() on Linux with an accept() fallback. |
Review effort: Balanced
Contributor
|
I don't think this is necessary. Connection-accept is not hot path in most scenarios. |
Contributor
Author
|
close it |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
On Linux, each accepted connection currently uses
accept()followed byseparate calls to set non-blocking and close-on-exec flags. This adds
unnecessary syscalls on the connection-accept hot path.
What is changed and the side effects?
Changed:
accept4()withSOCK_NONBLOCK | SOCK_CLOEXECfor accepted sockets onLinux.
accept()whenaccept4()is unavailable (ENOSYS).requested flags.
O_NONBLOCKandFD_CLOEXEC.Side effects:
Linux.
without
accept4()retain the existing behavior.Check List:
cmake --build build --target brpc_socket_unittest -j4