Skip to content

Commit 5ad2946

Browse files
authored
Remove the port_ and Inotify prefixes. (#1284)
* Remove the `port_` and `Inotify` prefixes. `port_*` and `Inotify*` are in public modules named `port` and `inotify` so remove their prefixes to make them less redundant. * Name the `Examples` section in docs consistently. * Add a simple usage example for the port API. * Fix test output for inotify. * Add doc aliases for the port API. * Fix io_uring naming inconsistency.
1 parent 7202da6 commit 5ad2946

6 files changed

Lines changed: 62 additions & 34 deletions

File tree

src/backend/linux_raw/conv.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,9 @@ pub(super) unsafe fn raw_fd<'a, Num: ArgNumber>(fd: RawFd) -> ArgReg<'a, Num> {
164164
#[cfg(feature = "fs")]
165165
debug_assert!(fd == crate::fs::CWD.as_raw_fd() || fd == crate::fs::ABS.as_raw_fd() || fd >= 0);
166166

167-
// Don't pass the `IO_URING_REGISTER_FILES_SKIP` sentry value this way.
167+
// Don't pass the `IORING_REGISTER_FILES_SKIP` sentry value this way.
168168
#[cfg(feature = "io_uring")]
169-
debug_assert_ne!(
170-
fd,
171-
crate::io_uring::IO_URING_REGISTER_FILES_SKIP.as_raw_fd()
172-
);
169+
debug_assert_ne!(fd, crate::io_uring::IORING_REGISTER_FILES_SKIP.as_raw_fd());
173170

174171
// Linux doesn't look at the high bits beyond the `c_int`, so use
175172
// zero-extension rather than sign-extension because it's a smaller

src/event/port.rs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
//! Solaris/illumos event ports.
2+
//!
3+
//! # Examples
4+
//!
5+
//! ```
6+
//! # fn test() -> std::io::Result<()> {
7+
//! use rustix::event::port;
8+
//! use rustix::stdio::stdout;
9+
//! use std::io;
10+
//!
11+
//! let some_fd = stdout();
12+
//! let some_userdata = 7 as *mut _;
13+
//!
14+
//! // Create a port.
15+
//! let port = port::create()?;
16+
//!
17+
//! // Associate `some_fd` with the port.
18+
//! unsafe {
19+
//! port::associate_fd(&port, some_fd, port::PollFlags::IN, some_userdata)?;
20+
//! }
21+
//!
22+
//! // Get a single event.
23+
//! let event = port::get(&port, None)?;
24+
//!
25+
//! assert_eq!(event.userdata(), some_userdata);
26+
//! # Ok(())
27+
//! # }
28+
//! ```
229
330
use crate::backend::c;
431
use crate::backend::event::syscalls;
532
use crate::fd::{AsFd, AsRawFd, OwnedFd};
633
use crate::ffi;
734
use crate::io;
835

9-
use super::PollFlags;
10-
1136
use core::time::Duration;
1237

38+
pub use super::PollFlags;
39+
1340
/// The structure representing a port event.
1441
#[repr(transparent)]
42+
#[doc(alias = "port_event")]
1543
pub struct Event(pub(crate) c::port_event);
1644

1745
impl Event {
@@ -39,7 +67,8 @@ impl Event {
3967
///
4068
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_create/
4169
/// [illumos]: https://illumos.org/man/3C/port_create
42-
pub fn port_create() -> io::Result<OwnedFd> {
70+
#[doc(alias = "port_create")]
71+
pub fn create() -> io::Result<OwnedFd> {
4372
syscalls::port_create()
4473
}
4574

@@ -50,15 +79,16 @@ pub fn port_create() -> io::Result<OwnedFd> {
5079
///
5180
/// Any `object`s passed into the `port` must be valid for the lifetime of the
5281
/// `port`. Logically, `port` keeps a borrowed reference to the `object` until
53-
/// it is removed via `port_dissociate_fd`.
82+
/// it is removed via [`dissociate_fd`].
5483
///
5584
/// # References
5685
/// - [OpenSolaris]
5786
/// - [illumos]
5887
///
5988
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_associate/
6089
/// [illumos]: https://illumos.org/man/3C/port_associate
61-
pub unsafe fn port_associate_fd<Fd: AsFd, RawFd: AsRawFd>(
90+
#[doc(alias = "port_associate")]
91+
pub unsafe fn associate_fd<Fd: AsFd, RawFd: AsRawFd>(
6292
port: Fd,
6393
object: RawFd,
6494
events: PollFlags,
@@ -79,18 +109,16 @@ pub unsafe fn port_associate_fd<Fd: AsFd, RawFd: AsRawFd>(
79109
/// # Safety
80110
///
81111
/// The file descriptor passed into this function must have been previously
82-
/// associated with the port via [`port_associate_fd`].
112+
/// associated with the port via [`associate_fd`].
83113
///
84114
/// # References
85115
/// - [OpenSolaris]
86116
/// - [illumos]
87117
///
88118
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_dissociate
89119
/// [illumos]: https://illumos.org/man/3C/port_dissociate
90-
pub unsafe fn port_dissociate_fd<Fd: AsFd, RawFd: AsRawFd>(
91-
port: Fd,
92-
object: RawFd,
93-
) -> io::Result<()> {
120+
#[doc(alias = "port_dissociate")]
121+
pub unsafe fn dissociate_fd<Fd: AsFd, RawFd: AsRawFd>(port: Fd, object: RawFd) -> io::Result<()> {
94122
syscalls::port_dissociate(port.as_fd(), c::PORT_SOURCE_FD, object.as_raw_fd() as _)
95123
}
96124

@@ -102,7 +130,8 @@ pub unsafe fn port_dissociate_fd<Fd: AsFd, RawFd: AsRawFd>(
102130
///
103131
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_get/
104132
/// [illumos]: https://illumos.org/man/3C/port_get
105-
pub fn port_get<Fd: AsFd>(port: Fd, timeout: Option<Duration>) -> io::Result<Event> {
133+
#[doc(alias = "port_get")]
134+
pub fn get<Fd: AsFd>(port: Fd, timeout: Option<Duration>) -> io::Result<Event> {
106135
let mut timeout = timeout.map(|timeout| c::timespec {
107136
tv_sec: timeout.as_secs().try_into().unwrap(),
108137
tv_nsec: timeout.subsec_nanos() as _,
@@ -119,7 +148,7 @@ pub fn port_get<Fd: AsFd>(port: Fd, timeout: Option<Duration>) -> io::Result<Eve
119148
/// this does nothing and returns immediately.
120149
///
121150
/// To query the number of events without retrieving any, use
122-
/// [`port_getn_query`].
151+
/// [`getn_query`].
123152
///
124153
/// # References
125154
/// - [OpenSolaris]
@@ -128,7 +157,8 @@ pub fn port_get<Fd: AsFd>(port: Fd, timeout: Option<Duration>) -> io::Result<Eve
128157
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/
129158
/// [illumos]: https://illumos.org/man/3C/port_getn
130159
#[cfg(feature = "alloc")]
131-
pub fn port_getn<Fd: AsFd>(
160+
#[doc(alias = "port_getn")]
161+
pub fn getn<Fd: AsFd>(
132162
port: Fd,
133163
events: &mut Vec<Event>,
134164
min_events: usize,
@@ -152,15 +182,16 @@ pub fn port_getn<Fd: AsFd>(
152182
/// `port_getn(port, NULL, 0, NULL)`—Queries the number of events
153183
/// available from a port.
154184
///
155-
/// To retrieve the events, use [`port_getn`].
185+
/// To retrieve the events, use [`getn`].
156186
///
157187
/// # References
158188
/// - [OpenSolaris]
159189
/// - [illumos]
160190
///
161191
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/
162192
/// [illumos]: https://illumos.org/man/3C/port_getn
163-
pub fn port_getn_query<Fd: AsFd>(port: Fd) -> io::Result<u32> {
193+
#[doc(alias = "port_getn")]
194+
pub fn getn_query<Fd: AsFd>(port: Fd) -> io::Result<u32> {
164195
syscalls::port_getn_query(port.as_fd())
165196
}
166197

@@ -172,6 +203,7 @@ pub fn port_getn_query<Fd: AsFd>(port: Fd) -> io::Result<u32> {
172203
///
173204
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_send/
174205
/// [illumos]: https://illumos.org/man/3C/port_send
175-
pub fn port_send<Fd: AsFd>(port: Fd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> {
206+
#[doc(alias = "port_send")]
207+
pub fn send<Fd: AsFd>(port: Fd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> {
176208
syscalls::port_send(port.as_fd(), events, userdata.cast())
177209
}

src/fs/inotify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ impl<'buf, Fd: AsFd> Reader<'buf, Fd> {
123123

124124
/// An inotify event.
125125
#[derive(Debug)]
126-
pub struct InotifyEvent<'a> {
126+
pub struct Event<'a> {
127127
wd: i32,
128128
events: ReadFlags,
129129
cookie: u32,
130130
file_name: Option<&'a CStr>,
131131
}
132132

133-
impl<'a> InotifyEvent<'a> {
133+
impl<'a> Event<'a> {
134134
/// Returns the watch for which this event occurs.
135135
#[inline]
136136
pub fn wd(&self) -> i32 {
@@ -172,7 +172,7 @@ impl<'buf, Fd: AsFd> Reader<'buf, Fd> {
172172
/// error occurs.
173173
#[allow(unsafe_code)]
174174
#[allow(clippy::should_implement_trait)]
175-
pub fn next(&mut self) -> io::Result<InotifyEvent<'_>> {
175+
pub fn next(&mut self) -> io::Result<Event<'_>> {
176176
if self.is_buffer_empty() {
177177
match read_uninit(self.fd.as_fd(), self.buf).map(|(init, _)| init.len()) {
178178
Ok(0) => return Err(Errno::INVAL),
@@ -195,7 +195,7 @@ impl<'buf, Fd: AsFd> Reader<'buf, Fd> {
195195

196196
self.offset += size_of::<inotify_event>() + usize::try_from(event.len).unwrap();
197197

198-
Ok(InotifyEvent {
198+
Ok(Event {
199199
wd: event.wd,
200200
events: ReadFlags::from_bits_retain(event.mask),
201201
cookie: event.cookie,

src/io_uring/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,10 @@ pub const IORING_OFF_CQ_RING: u64 = sys::IORING_OFF_CQ_RING as _;
912912
pub const IORING_OFF_SQES: u64 = sys::IORING_OFF_SQES as _;
913913

914914
/// `IORING_REGISTER_FILES_SKIP`
915-
#[doc(alias = "IORING_REGISTER_FILES_SKIP")]
916915
// SAFETY: `IORING_REGISTER_FILES_SKIP` is a reserved value that is never
917916
// dynamically allocated, so it'll remain valid for the duration of
918917
// `'static`.
919-
pub const IO_URING_REGISTER_FILES_SKIP: BorrowedFd<'static> =
918+
pub const IORING_REGISTER_FILES_SKIP: BorrowedFd<'static> =
920919
unsafe { BorrowedFd::<'static>::borrow_raw(sys::IORING_REGISTER_FILES_SKIP as RawFd) };
921920

922921
/// `IORING_NOTIF_USAGE_ZC_COPIED` (since Linux 6.2)

src/shm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! POSIX shared memory
22
//!
3-
//! # Example
3+
//! # Examples
44
//!
55
//! ```
66
//! use rustix::fs::{ftruncate, Mode};

tests/fs/inotify.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn test_inotify_iter() {
4141
}
4242

4343
let expected = format!(
44-
r#"InotifyEvent {{
44+
r#"Event {{
4545
wd: 1,
4646
events: ReadFlags(
4747
CREATE,
@@ -51,7 +51,7 @@ fn test_inotify_iter() {
5151
"foo",
5252
),
5353
}}
54-
InotifyEvent {{
54+
Event {{
5555
wd: 1,
5656
events: ReadFlags(
5757
OPEN,
@@ -61,7 +61,7 @@ InotifyEvent {{
6161
"foo",
6262
),
6363
}}
64-
InotifyEvent {{
64+
Event {{
6565
wd: 1,
6666
events: ReadFlags(
6767
CLOSE_WRITE,
@@ -71,7 +71,7 @@ InotifyEvent {{
7171
"foo",
7272
),
7373
}}
74-
InotifyEvent {{
74+
Event {{
7575
wd: 1,
7676
events: ReadFlags(
7777
MOVED_FROM,
@@ -81,7 +81,7 @@ InotifyEvent {{
8181
"foo",
8282
),
8383
}}
84-
InotifyEvent {{
84+
Event {{
8585
wd: 1,
8686
events: ReadFlags(
8787
MOVED_TO,
@@ -91,7 +91,7 @@ InotifyEvent {{
9191
"bar",
9292
),
9393
}}
94-
InotifyEvent {{
94+
Event {{
9595
wd: 1,
9696
events: ReadFlags(
9797
DELETE,

0 commit comments

Comments
 (0)