From bf9ec6f6751a3d6b4364a5f2104cd331ffbebf84 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 14 Aug 2024 14:18:02 +0200 Subject: [PATCH 1/2] Revert "Implement fallback for `sendmmsg` and `recvmmsg`" This reverts commit e6f184489e703bcf70850f99373c88746c250662. e6f18448 called `sendmmsg` and `recvmmsg` through `libc::syscall` instead of `libc::sendmmsg` and `libc::recvmmsg`, thus preventing linking issues on old Android systems where `libc::sendmmsg` and `libc::recvmmsg` isn't available. In https://github.com/quinn-rs/quinn/issues/1503#issuecomment-2285962727 the decision was made to no longer support these old Android systems (API level 16). This commit reverts e6f18448. Given that `sendmmsg` support was previously dropped in ee088265, only the `recvmmsg` calls are reverted. --- quinn-udp/src/unix.rs | 84 ++----------------------------------------- 1 file changed, 3 insertions(+), 81 deletions(-) diff --git a/quinn-udp/src/unix.rs b/quinn-udp/src/unix.rs index 7033b6191..0650a7bd8 100644 --- a/quinn-udp/src/unix.rs +++ b/quinn-udp/src/unix.rs @@ -395,10 +395,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> } let msg_count = loop { let n = unsafe { - recvmmsg_with_fallback( + libc::recvmmsg( io.as_raw_fd(), hdrs.as_mut_ptr(), bufs.len().min(BATCH_SIZE) as _, + 0, + ptr::null_mut::(), ) }; if n == -1 { @@ -445,86 +447,6 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> Ok(1) } -/// Implementation of `recvmmsg` with a fallback -/// to `recvmsg` if syscall is not available. -/// -/// It uses [`libc::syscall`] instead of [`libc::recvmmsg`] -/// to avoid linking error on systems where libc does not contain `recvmmsg`. -#[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "openbsd", - target_os = "solaris", -)))] -unsafe fn recvmmsg_with_fallback( - sockfd: libc::c_int, - msgvec: *mut libc::mmsghdr, - vlen: libc::c_uint, -) -> libc::c_int { - let flags = 0; - let timeout = ptr::null_mut::(); - - #[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))] - { - let ret = - libc::syscall(libc::SYS_recvmmsg, sockfd, msgvec, vlen, flags, timeout) as libc::c_int; - if ret != -1 { - return ret; - } - } - - // libc on FreeBSD and NetBSD implement `recvmmsg` as a high-level abstraction over - // `recvmsg`, thus `SYS_recvmmsg` constant and direct system call do not exist - #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] - { - #[cfg(target_os = "freebsd")] - let vlen = vlen as usize; - let ret = libc::recvmmsg(sockfd, msgvec, vlen, flags, timeout) as libc::c_int; - if ret != -1 { - return ret; - } - } - - let e = io::Error::last_os_error(); - match e.raw_os_error() { - Some(libc::ENOSYS) => { - // Fallback to `recvmsg`. - recvmmsg_fallback(sockfd, msgvec, vlen) - } - _ => -1, - } -} - -/// Fallback implementation of `recvmmsg` using `recvmsg` -/// for systems which do not support `recvmmsg` -/// such as Linux <2.6.33. -#[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "openbsd", - target_os = "solaris", -)))] -unsafe fn recvmmsg_fallback( - sockfd: libc::c_int, - msgvec: *mut libc::mmsghdr, - vlen: libc::c_uint, -) -> libc::c_int { - let flags = 0; - if vlen == 0 { - return 0; - } - - let n = libc::recvmsg(sockfd, &mut (*msgvec).msg_hdr, flags); - if n == -1 { - -1 - } else { - // 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 - } -} - const CMSG_LEN: usize = 88; fn prepare_msg( From fb44c773fd2a1bea6a7a8553bfa84d52281b36e0 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 14 Aug 2024 14:30:21 +0200 Subject: [PATCH 2/2] chore(quinn-udp): increase crate patch version to v0.5.5 --- quinn-udp/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quinn-udp/Cargo.toml b/quinn-udp/Cargo.toml index 4cbe86019..257ee0015 100644 --- a/quinn-udp/Cargo.toml +++ b/quinn-udp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quinn-udp" -version = "0.5.4" +version = "0.5.5" edition.workspace = true rust-version.workspace = true license.workspace = true