-
Notifications
You must be signed in to change notification settings - Fork 260
Use OwnedFd/OwnedSocket in Socket #600
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
Unfortunately Windows uses std::os::windows::io::RawSocket (u64), which is different from the RawSocket that we define that uses windows_sys::Win32::Networking::WinSock::SOCKET (usize). So the std lib version gets ranamed to StdRawSocket.
// something we don't want. So check for that we have this | ||
// `assert!`. | ||
#[cfg(unix)] | ||
assert!(raw >= 0, "tried to create a `Socket` with an invalid fd"); |
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.
Looks like there is a test for this assertion.
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.
Updated the test with the error message from std lib, don't think there is value is checking it twice.
Instead of the workaround where we use std::net::TcpStream.
Panic message is different in 1.70 vs. current stable 🤦 I'll just change it to only check for the panic |
It changed between 1.70 and current stable. Checking if the function panics should be good enough.
// potentially close a fd it doesn't own. All of that isn't memory | ||
// unsafe, so it's not desired but never memory unsafe or causes UB. |
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.
It's not immediate UB, but we consider it library UB because downstream effects can cause memory unsafety, e.g. by incorrectly touching mmap'ed fds.
Instead of the workaround where we use std::net::TcpStream.