Skip to content

Commit 1a2a84f

Browse files
committed
update recv to use correct values on FreeBSD
Use correct value for POLLRDHUP and make fd.len cast more portable. Signed-off-by: 180watt <[email protected]>
1 parent f47d019 commit 1a2a84f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/platform/unix/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,15 +1162,26 @@ impl UnixCmsg {
11621162
}
11631163
},
11641164
BlockingMode::Timeout(duration) => {
1165-
let events = libc::POLLIN | libc::POLLPRI | libc::POLLRDHUP;
1165+
#[cfg(target_os = "linux")]
1166+
const POLLRDHUP: lib::c_short = libc::POLLRDHUP;
1167+
1168+
// It's rather unfortunate that Rust's libc doesn't know that
1169+
// FreeBSD has POLLRDHUP, but in the mean time we can add
1170+
// the value ourselves.
1171+
// https://cgit.freebsd.org/src/tree/sys/sys/poll.h#n72
1172+
#[cfg(target_os = "freebsd")]
1173+
const POLLRDHUP: libc::c_short = 0x4000;
1174+
1175+
let events = libc::POLLIN | libc::POLLPRI | POLLRDHUP;
1176+
11661177
let mut fd = [libc::pollfd {
11671178
fd,
11681179
events,
11691180
revents: 0,
11701181
}];
11711182
let result = libc::poll(
11721183
fd.as_mut_ptr(),
1173-
fd.len() as libc::c_ulong,
1184+
fd.len() as _,
11741185
duration.as_millis().try_into().unwrap_or(-1),
11751186
);
11761187

0 commit comments

Comments
 (0)