songgaoye opened a new pull request, #3656:
URL: https://github.com/apache/brpc/pull/3656
### What problem does this PR solve?
Issue Number: resolve #N/A
Problem Summary:
On Linux, each accepted connection currently uses `accept()` followed by
separate 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:
- Use `accept4()` with `SOCK_NONBLOCK | SOCK_CLOEXEC` for accepted sockets on
Linux.
- Fall back to `accept()` when `accept4()` is unavailable (`ENOSYS`).
- Skip redundant flag-setting calls when the accepted fd already has the
requested flags.
- Add a Linux-only regression test verifying accepted sockets have
`O_NONBLOCK` and `FD_CLOEXEC`.
Side effects:
- Performance effects: reduces syscall overhead while accepting connections
on
Linux.
- Breaking backward compatibility: No. Non-Linux platforms and Linux kernels
without `accept4()` retain the existing behavior.
---
### Check List:
- [x] Please make sure your changes are compilable.
- `cmake --build build --target brpc_socket_unittest -j4`
- [x] When providing us with a new feature, it is best to add related tests.
- [x] Please follow [Contributor Covenant Code of
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]