Rename fd_readable_set_t to FdReadableSet

This commit is contained in:
Peter Ammon 2024-06-29 18:06:02 -07:00
parent 2d35d3f3c7
commit 266852327f
No known key found for this signature in database
2 changed files with 13 additions and 16 deletions

View File

@ -1,17 +1,15 @@
use libc::c_int;
use std::os::unix::prelude::*;
pub use fd_readable_set_t as FdReadableSet;
/// Returns `true` if the fd is or becomes readable within the given timeout.
/// This returns `false` if the waiting is interrupted by a signal.
pub fn is_fd_readable(fd: i32, timeout_usec: u64) -> bool {
fd_readable_set_t::is_fd_readable(fd, timeout_usec)
FdReadableSet::is_fd_readable(fd, timeout_usec)
}
/// Returns whether an fd is readable.
pub fn poll_fd_readable(fd: i32) -> bool {
fd_readable_set_t::poll_fd_readable(fd)
FdReadableSet::poll_fd_readable(fd)
}
/// A modest wrapper around select() or poll().
@ -19,7 +17,7 @@ pub fn poll_fd_readable(fd: i32) -> bool {
/// This only handles readability.
/// Apple's `man poll`: "The poll() system call currently does not support devices."
#[cfg(target_os = "macos")]
pub struct fd_readable_set_t {
pub struct FdReadableSet {
// The underlying fdset and nfds value to pass to select().
fdset_: libc::fd_set,
nfds_: c_int,
@ -31,10 +29,10 @@ const kUsecPerMsec: u64 = 1000;
const kUsecPerSec: u64 = 1000 * kUsecPerMsec;
#[cfg(target_os = "macos")]
impl fd_readable_set_t {
impl FdReadableSet {
/// Construct an empty set.
pub fn new() -> fd_readable_set_t {
fd_readable_set_t {
pub fn new() -> FdReadableSet {
FdReadableSet {
fdset_: unsafe { std::mem::zeroed() },
nfds_: 0,
}
@ -114,15 +112,15 @@ impl fd_readable_set_t {
}
#[cfg(not(target_os = "macos"))]
pub struct fd_readable_set_t {
pub struct FdReadableSet {
pollfds_: Vec<libc::pollfd>,
}
#[cfg(not(target_os = "macos"))]
impl fd_readable_set_t {
impl FdReadableSet {
/// Construct an empty set.
pub fn new() -> fd_readable_set_t {
fd_readable_set_t {
pub fn new() -> FdReadableSet {
FdReadableSet {
pollfds_: Vec::new(),
}
}
@ -177,7 +175,7 @@ impl fd_readable_set_t {
if (timeout_usec % kUsecPerMsec) > kUsecPerMsec / 2 {
timeout_msec += 1;
}
if timeout_usec == fd_readable_set_t::kNoTimeout || timeout_msec > c_int::MAX as u64 {
if timeout_usec == FdReadableSet::kNoTimeout || timeout_msec > c_int::MAX as u64 {
// Negative values mean wait forever in poll-speak.
return -1;
}

View File

@ -20,7 +20,7 @@ also provides the ability to perform a blocking wait for any topic to change in
set. This is the real power of topics: you can wait for a sigchld signal OR a thread exit.
*/
use crate::fd_readable_set::fd_readable_set_t;
use crate::fd_readable_set::FdReadableSet;
use crate::fds::{self, make_fd_nonblocking, AutoClosePipes};
use crate::flog::{FloggableDebug, FLOG};
use crate::wchar::WString;
@ -240,8 +240,7 @@ impl binary_semaphore_t {
// call until data is available (that is, fish would use 100% cpu while waiting for
// processes). This call prevents that.
if cfg!(feature = "tsan") {
let _ =
fd_readable_set_t::is_fd_readable(fd, fd_readable_set_t::kNoTimeout);
let _ = FdReadableSet::is_fd_readable(fd, FdReadableSet::kNoTimeout);
}
let mut ignored: u8 = 0;
match unistd::read(fd, std::slice::from_mut(&mut ignored)) {