Skip to content

Commit c553989

Browse files
weihanglopetrochenkov
authored andcommitted
fix: preadv2 only available on GNU libc
Technically it is also available on musl libc 1.2.5, yet the [email protected] (lastet) doesn't export the symbol, and that version of musl libc is too new (released in 2024-03)
1 parent 36a5e2e commit c553989

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/unix.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ impl Client {
287287

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

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

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

0 commit comments

Comments
 (0)