socket: change accept to return an OwnedFd#2780
Merged
Merged
Conversation
8dd280c to
c667ee6
Compare
xtqqczze
reviewed
Apr 23, 2026
xtqqczze
reviewed
Apr 25, 2026
SteveLauC
approved these changes
May 11, 2026
Member
SteveLauC
left a comment
There was a problem hiding this comment.
LGTM, thanks for the patch!
I think we could take this a step further and make the sockfd argument I/O-safe as well:
fn accept<Fd: AsFd>(sockfd: Fd) -> Result<OwnedFd>Are you interested in doing it in this PR
Member
|
CI failures are unrelated and fixed, you can rebase your branch. |
There was a problem hiding this comment.
Pull request overview
This PR updates nix::sys::socket::accept to return an owning file-descriptor type (OwnedFd) rather than a RawFd, aligning the API with Rust I/O-safety patterns and avoiding call-site unsafe wrappers.
Changes:
- Change
sys::socket::acceptto returnResult<OwnedFd>and wrap the returned fd inOwnedFd. - Update socket-related tests to use the returned
OwnedFddirectly (removingBorrowedFd::borrow_rawworkarounds). - Add a changelog entry documenting the API change.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/sys/socket/mod.rs |
Changes accept to return OwnedFd and wraps the returned fd. |
test/sys/test_socket.rs |
Removes raw-borrow workarounds and uses &OwnedFd with read/fcntl. |
test/sys/test_sockopt.rs |
Adjusts imports and removes an unnecessary manual OwnedFd::from_raw_fd wrapping after accept. |
changelog/2780.changed.md |
Documents the public API change for accept. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
accept(2) returns on success a new file descriptor that is not coupled with the listened socket. Thus it is safe to wrap it into an OwnedFd, which will close the socket on cleanup.
Contributor
Author
|
changed |
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.
accept(2) returns on success a new file descriptor that is not coupled with the listened socket. Thus it is safe to wrap it into an OwnedFd, which will close the socket on cleanup.
What does this PR do
Checklist:
CONTRIBUTING.md