Skip to content

Commit

Permalink
update recv to use correct values on FreeBSD
Browse files Browse the repository at this point in the history
Use correct value for POLLRDHUP and make fd.len cast more portable.

Signed-off-by: 180watt <180watt@duck.com>
  • Loading branch information
180watt committed Jul 29, 2024
1 parent f47d019 commit 1a2a84f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,15 +1162,26 @@ impl UnixCmsg {
}
},
BlockingMode::Timeout(duration) => {
let events = libc::POLLIN | libc::POLLPRI | libc::POLLRDHUP;
#[cfg(target_os = "linux")]
const POLLRDHUP: lib::c_short = libc::POLLRDHUP;

// It's rather unfortunate that Rust's libc doesn't know that
// FreeBSD has POLLRDHUP, but in the mean time we can add
// the value ourselves.
// https://cgit.freebsd.org/src/tree/sys/sys/poll.h#n72
#[cfg(target_os = "freebsd")]
const POLLRDHUP: libc::c_short = 0x4000;

let events = libc::POLLIN | libc::POLLPRI | POLLRDHUP;

let mut fd = [libc::pollfd {
fd,
events,
revents: 0,
}];
let result = libc::poll(
fd.as_mut_ptr(),
fd.len() as libc::c_ulong,
fd.len() as _,
duration.as_millis().try_into().unwrap_or(-1),
);

Expand Down

0 comments on commit 1a2a84f

Please sign in to comment.