Skip to content

Commit 30bc276

Browse files
mxindendjc
authored andcommitted
Revert "Implement fallback for sendmmsg and recvmmsg"
This reverts commit e6f1844. e6f1844 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 #1503 (comment) the decision was made to no longer support these old Android systems (API level 16). This commit reverts e6f1844. Given that `sendmmsg` support was previously dropped in ee08826, only the `recvmmsg` calls are reverted.
1 parent 7c09b02 commit 30bc276

File tree

1 file changed

+3
-81
lines changed

1 file changed

+3
-81
lines changed

quinn-udp/src/unix.rs

+3-81
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
395395
}
396396
let msg_count = loop {
397397
let n = unsafe {
398-
recvmmsg_with_fallback(
398+
libc::recvmmsg(
399399
io.as_raw_fd(),
400400
hdrs.as_mut_ptr(),
401401
bufs.len().min(BATCH_SIZE) as _,
402+
0,
403+
ptr::null_mut::<libc::timespec>(),
402404
)
403405
};
404406
if n == -1 {
@@ -445,86 +447,6 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
445447
Ok(1)
446448
}
447449

448-
/// Implementation of `recvmmsg` with a fallback
449-
/// to `recvmsg` if syscall is not available.
450-
///
451-
/// It uses [`libc::syscall`] instead of [`libc::recvmmsg`]
452-
/// to avoid linking error on systems where libc does not contain `recvmmsg`.
453-
#[cfg(not(any(
454-
target_os = "macos",
455-
target_os = "ios",
456-
target_os = "openbsd",
457-
target_os = "solaris",
458-
)))]
459-
unsafe fn recvmmsg_with_fallback(
460-
sockfd: libc::c_int,
461-
msgvec: *mut libc::mmsghdr,
462-
vlen: libc::c_uint,
463-
) -> libc::c_int {
464-
let flags = 0;
465-
let timeout = ptr::null_mut::<libc::timespec>();
466-
467-
#[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))]
468-
{
469-
let ret =
470-
libc::syscall(libc::SYS_recvmmsg, sockfd, msgvec, vlen, flags, timeout) as libc::c_int;
471-
if ret != -1 {
472-
return ret;
473-
}
474-
}
475-
476-
// libc on FreeBSD and NetBSD implement `recvmmsg` as a high-level abstraction over
477-
// `recvmsg`, thus `SYS_recvmmsg` constant and direct system call do not exist
478-
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
479-
{
480-
#[cfg(target_os = "freebsd")]
481-
let vlen = vlen as usize;
482-
let ret = libc::recvmmsg(sockfd, msgvec, vlen, flags, timeout) as libc::c_int;
483-
if ret != -1 {
484-
return ret;
485-
}
486-
}
487-
488-
let e = io::Error::last_os_error();
489-
match e.raw_os_error() {
490-
Some(libc::ENOSYS) => {
491-
// Fallback to `recvmsg`.
492-
recvmmsg_fallback(sockfd, msgvec, vlen)
493-
}
494-
_ => -1,
495-
}
496-
}
497-
498-
/// Fallback implementation of `recvmmsg` using `recvmsg`
499-
/// for systems which do not support `recvmmsg`
500-
/// such as Linux <2.6.33.
501-
#[cfg(not(any(
502-
target_os = "macos",
503-
target_os = "ios",
504-
target_os = "openbsd",
505-
target_os = "solaris",
506-
)))]
507-
unsafe fn recvmmsg_fallback(
508-
sockfd: libc::c_int,
509-
msgvec: *mut libc::mmsghdr,
510-
vlen: libc::c_uint,
511-
) -> libc::c_int {
512-
let flags = 0;
513-
if vlen == 0 {
514-
return 0;
515-
}
516-
517-
let n = libc::recvmsg(sockfd, &mut (*msgvec).msg_hdr, flags);
518-
if n == -1 {
519-
-1
520-
} else {
521-
// type of `msg_len` field differs on Linux and FreeBSD,
522-
// it is up to the compiler to infer and cast `n` to correct type
523-
(*msgvec).msg_len = n as _;
524-
1
525-
}
526-
}
527-
528450
const CMSG_LEN: usize = 88;
529451

530452
fn prepare_msg(

0 commit comments

Comments
 (0)