Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: build and tests on FreeBSD 13.2 #1555

Merged
merged 5 commits into from
May 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn send(
last_send_error: &Mutex<Instant>,
transmits: &[Transmit],
) -> io::Result<usize> {
#[allow(unused_mut)] // only mutable on FeeBSD
#[allow(unused_mut)] // only mutable on FreeBSD
let mut encode_src_ip = true;
#[cfg(target_os = "freebsd")]
{
Expand Down Expand Up @@ -322,9 +322,23 @@ unsafe fn sendmmsg_with_fallback(
vlen: libc::c_uint,
) -> libc::c_int {
let flags = 0;
let ret = libc::syscall(libc::SYS_sendmmsg, sockfd, msgvec, vlen, flags) as libc::c_int;
if ret != -1 {
return ret;

#[cfg(not(target_os = "freebsd"))]
{
let ret = libc::syscall(libc::SYS_sendmmsg, sockfd, msgvec, vlen, flags) as libc::c_int;
if ret != -1 {
return ret;
}
}

// libc on FreeBSD implements `sendmmsg` as a high-level abstraction over `sendmsg`,
// thus `SYS_sendmmsg` constant and direct system call do not exist
#[cfg(target_os = "freebsd")]
{
let ret = libc::sendmmsg(sockfd, msgvec, vlen as usize, flags) as libc::c_int;
if ret != -1 {
return ret;
}
}

let e = io::Error::last_os_error();
Expand Down Expand Up @@ -355,7 +369,9 @@ unsafe fn sendmmsg_fallback(
if n == -1 {
-1
} else {
(*msgvec).msg_len = n as libc::c_uint;
// type of `msg_len` field differs on Linux and FreeBSD,
// it is up to the compiler to infer and cast `n` to correct type
(*msgvec).msg_len = n as _;
Tirka marked this conversation as resolved.
Show resolved Hide resolved
1
}
}
Expand Down Expand Up @@ -434,10 +450,24 @@ unsafe fn recvmmsg_with_fallback(
) -> libc::c_int {
let flags = 0;
let timeout = ptr::null_mut::<libc::timespec>();
let ret =
libc::syscall(libc::SYS_recvmmsg, sockfd, msgvec, vlen, flags, timeout) as libc::c_int;
if ret != -1 {
return ret;

#[cfg(not(target_os = "freebsd"))]
{
let ret =
libc::syscall(libc::SYS_recvmmsg, sockfd, msgvec, vlen, flags, timeout) as libc::c_int;
if ret != -1 {
return ret;
}
}

// libc on FreeBSD implements `recvmmsg` as a high-level abstraction over `recvmsg`,
// thus `SYS_recvmmsg` constant and direct system call do not exist
#[cfg(target_os = "freebsd")]
{
let ret = libc::recvmmsg(sockfd, msgvec, vlen as usize, flags, timeout) as libc::c_int;
if ret != -1 {
return ret;
}
}

let e = io::Error::last_os_error();
Expand Down Expand Up @@ -468,7 +498,9 @@ unsafe fn recvmmsg_fallback(
if n == -1 {
-1
} else {
(*msgvec).msg_len = n as libc::c_uint;
// type of `msg_len` field differs on Linux and FreeBSD,
// it is up to the compiler to infer and cast `n` to correct type
(*msgvec).msg_len = n as _;
1
}
}
Expand Down