Skip to content

Commit

Permalink
fix: preadv2 only available on GNU libc
Browse files Browse the repository at this point in the history
Technically it is also available on musl libc 1.2.5,
yet the libc@0.2.153 (lastet) doesn't export the symbol,
and that version of musl libc is too new (released in 2024-03)
  • Loading branch information
weihanglo authored and petrochenkov committed Apr 12, 2024
1 parent 36a5e2e commit c553989
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ impl Client {

// On Linux, we can use preadv2 to do non-blocking read,
// even if `O_NONBLOCK` is not set.
#[cfg(target_os = "linux")]
//
// TODO: musl libc supports preadv2 since 1.2.5, but `libc` crate
// hasn't yet added it.
#[cfg(all(target_os = "linux", target_env = "gnu"))]
{
let read = self.read().as_raw_fd();
loop {
Expand Down Expand Up @@ -577,7 +580,9 @@ extern "C" fn sigusr1_handler(
// nothing to do
}

#[cfg(target_os = "linux")]
// This should be available for all linux targets,
// though only [`non_blocking_read`] currently uses it so adding gnu cfg.
#[cfg(all(target_os = "linux", target_env = "gnu"))]
fn cvt_ssize(t: libc::ssize_t) -> io::Result<libc::ssize_t> {
if t == -1 {
Err(io::Error::last_os_error())
Expand All @@ -586,7 +591,7 @@ fn cvt_ssize(t: libc::ssize_t) -> io::Result<libc::ssize_t> {
}
}

#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
fn non_blocking_read(fd: c_int, buf: &mut [u8]) -> io::Result<usize> {
static IS_NONBLOCKING_READ_UNSUPPORTED: AtomicBool = AtomicBool::new(false);

Expand Down

0 comments on commit c553989

Please sign in to comment.