Skip to content

Commit f006fb9

Browse files
authored
Update the public comment for fd and simplify the fd module. (#1420)
Avoid redundantly listing the items of the `fd` module. And use the normal Windows function and type names when in Windows-specific code.
1 parent 1cd4f00 commit f006fb9

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

src/backend/libc/io/windows_syscalls.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::backend::c;
44
#[cfg(feature = "try_close")]
55
use crate::backend::conv::ret;
66
use crate::backend::conv::{borrowed_fd, ret_c_int, ret_send_recv, send_recv_len};
7-
use crate::backend::fd::LibcFd;
87
use crate::fd::{BorrowedFd, RawFd};
98
use crate::io;
109
use crate::ioctl::{IoctlOutput, Opcode};
@@ -32,12 +31,12 @@ pub(crate) fn write(fd: BorrowedFd<'_>, buf: &[u8]) -> io::Result<usize> {
3231
}
3332

3433
pub(crate) unsafe fn close(raw_fd: RawFd) {
35-
let _ = c::close(raw_fd as LibcFd);
34+
let _ = c::closesocket(raw_fd as c::SOCKET);
3635
}
3736

3837
#[cfg(feature = "try_close")]
3938
pub(crate) unsafe fn try_close(raw_fd: RawFd) -> io::Result<()> {
40-
ret(c::close(raw_fd as LibcFd))
39+
ret(c::closesocket(raw_fd as c::SOCKET))
4140
}
4241

4342
#[inline]

src/backend/libc/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ mod conv;
1515

1616
#[cfg(windows)]
1717
pub(crate) mod fd {
18+
// Re-export `AsSocket` etc. too, as users can't implement `AsFd` etc. on
19+
// Windows due to them having blanket impls on Windows, so users must
20+
// implement `AsSocket` etc.
1821
pub use crate::maybe_polyfill::os::windows::io::{
1922
AsRawSocket, AsSocket, BorrowedSocket as BorrowedFd, FromRawSocket, IntoRawSocket,
2023
OwnedSocket as OwnedFd, RawSocket as RawFd,
@@ -90,9 +93,7 @@ pub(crate) mod fd {
9093
}
9194
#[cfg(not(windows))]
9295
pub(crate) mod fd {
93-
pub use crate::maybe_polyfill::os::fd::{
94-
AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd,
95-
};
96+
pub use crate::maybe_polyfill::os::fd::*;
9697
#[allow(unused_imports)]
9798
pub(crate) use RawFd as LibcFd;
9899
}

src/backend/linux_raw/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ pub(crate) mod thread;
7878
#[cfg(feature = "time")]
7979
pub(crate) mod time;
8080

81-
pub(crate) mod fd {
82-
pub use crate::maybe_polyfill::os::fd::{
83-
AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd,
84-
};
85-
}
81+
// Re-export the maybe-polyfill `core::os::fd`.
82+
pub(crate) use crate::maybe_polyfill::os::fd;
8683

8784
// The linux_raw backend doesn't use actual libc, so we define selected
8885
// libc-like definitions in a module called `c`.

src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,19 @@ mod backend;
193193

194194
/// Export the `*Fd` types and traits that are used in rustix's public API.
195195
///
196-
/// Users can use this to avoid needing to import anything else to use the same
197-
/// versions of these types and traits.
196+
/// This module exports the types and traits from [`std::os::fd`], or polyills
197+
/// on Rust < 1.66 or on Windows.
198+
///
199+
/// On Windows, the polyfill consists of aliases of the socket types and
200+
/// traits, For example, [`OwnedSocket`] is aliased to `OwnedFd`, and so on,
201+
/// and there are blanket impls for `AsFd` etc. that map to `AsSocket` impls.
202+
/// These blanket impls suffice for using the traits, however not for
203+
/// implementing them, so this module also exports `AsSocket` and the other
204+
/// traits as-is so that users can implement them if needed.
205+
///
206+
/// [`OwnedSocket`]: https://doc.rust-lang.org/stable/std/os/windows/io/struct.OwnedSocket.html
198207
pub mod fd {
199-
use super::backend;
200-
201-
// Re-export `AsSocket` etc. too, as users can't implement `AsFd` etc. on
202-
// Windows due to them having blanket impls on Windows, so users must
203-
// implement `AsSocket` etc.
204-
#[cfg(windows)]
205-
pub use backend::fd::{AsRawSocket, AsSocket, FromRawSocket, IntoRawSocket};
206-
207-
pub use backend::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
208+
pub use super::backend::fd::*;
208209
}
209210

210211
// The public API modules.

src/maybe_polyfill/no_std/os/windows/io/socket.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
use super::raw::*;
99
use crate::backend::c;
10-
use crate::backend::fd::LibcFd as LibcSocket;
1110
use core::fmt;
1211
use core::marker::PhantomData;
1312
use core::mem::forget;
@@ -132,7 +131,7 @@ impl Drop for OwnedSocket {
132131
#[inline]
133132
fn drop(&mut self) {
134133
unsafe {
135-
let _ = c::closesocket(self.socket as LibcSocket);
134+
let _ = c::closesocket(self.socket as c::SOCKET);
136135
}
137136
}
138137
}

0 commit comments

Comments
 (0)